Files
gabrielvidalandClaude Opus 5.5 9743452689 feat: the modal's Time is a dropdown from now to 21:00
"Now (14:35)" — now rounded up to 5 min, resolved at Post — then every
quarter hour up to BABYFOOT_LAST_TIME (default 21:00), instead of Slack's
free timepicker. After that time /babyfoot answers privately "Babyfoot
closes at 21:00 — see you tomorrow!" and opens no modal.

npm test: the options list and the dropdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 15:32:50 +01:00

48 lines
1.8 KiB
JavaScript

// The modal's Time dropdown — `npm test`.
process.env.SLACK_BOT_TOKEN = 'xoxb-test';
process.env.SLACK_APP_TOKEN = 'xapp-test';
delete process.env.BABYFOOT_LAST_TIME; // the default, 21:00
require('@slack/web-api').WebClient.prototype.apiCall = async () => ({ ok: true, user_id: 'UBOT', bot_id: 'BBOT' });
const test = require('node:test');
const assert = require('node:assert/strict');
const { timeChoices, timeSelect } = require('../app.js');
const at = (hhmm) => {
const [h, m] = hhmm.split(':').map(Number);
return h * 60 + m;
};
test('now, then every quarter hour up to 21:00', () => {
const times = timeChoices(at('14:35'));
assert.deepEqual(times.slice(0, 4), ['14:35', '14:45', '15:00', '15:15']);
assert.equal(times.at(-1), '21:00');
assert.equal(times.length, 1 + 26); // now + 14:45 … 21:00
});
test('on a quarter hour, now is not repeated', () => {
assert.deepEqual(timeChoices(at('20:30')), ['20:30', '20:45', '21:00']);
});
test('at 21:00 only "now" is left; past it, nothing', () => {
assert.deepEqual(timeChoices(at('21:00')), ['21:00']);
assert.deepEqual(timeChoices(at('21:05')), []);
assert.deepEqual(timeChoices(24 * 60), []); // 23:58 rounded up
});
test('a whole day stays under Slack\'s 100 options', () => {
const times = timeChoices(0);
assert.ok(times.length <= 100);
assert.equal(times.at(-1), '21:00');
});
test('the dropdown: "Now (…)" first and preselected, valued "now"', () => {
const el = timeSelect(at('12:05'));
assert.equal(el.type, 'static_select');
assert.equal(el.action_id, 'value');
assert.deepEqual(el.options[0], { text: { type: 'plain_text', text: 'Now (12:05)' }, value: 'now' });
assert.deepEqual(el.initial_option, el.options[0]);
assert.deepEqual(el.options[1], { text: { type: 'plain_text', text: '12:15' }, value: '12:15' });
assert.equal(timeSelect(at('21:30')), null);
});