import { EditorSelection } from '@codemirror/state'; import createTestEditor from '../testing/createTestEditor'; import { getFormattedCurrentTime, tryExpandQuickTimestamp } from './quickTimestampExtension'; describe('quickTimestampExtension', () => { describe('getFormattedCurrentTime', () => { it('formats time to HH:mm with 2-digit padding', () => { const testDate = new Date(2026, 10, 1, 9, 5); // 09:05 expect(getFormattedCurrentTime(testDate)).toBe('09:05'); const testDateAfternoon = new Date(2026, 10, 1, 16, 30); // 16:30 expect(getFormattedCurrentTime(testDateAfternoon)).toBe('16:30'); }); }); describe('tryExpandQuickTimestamp', () => { it('expands /now with trailing space into [HH:mm] ', async () => { const initialText = 'Meeting started /now'; const editor = await createTestEditor(initialText, EditorSelection.cursor(initialText.length), []); const handled = tryExpandQuickTimestamp(editor, initialText.length, initialText.length, ' '); expect(handled).toBe(true); const expectedTime = getFormattedCurrentTime(); expect(editor.state.doc.toString()).toBe(`Meeting started [${expectedTime}] `); }); it('expands /time with trailing newline into [HH:mm]\n', async () => { const initialText = '- /time'; const editor = await createTestEditor(initialText, EditorSelection.cursor(initialText.length), []); const handled = tryExpandQuickTimestamp(editor, initialText.length, initialText.length, '\n'); expect(handled).toBe(true); const expectedTime = getFormattedCurrentTime(); expect(editor.state.doc.toString()).toBe(`- [${expectedTime}]\n`); }); it('does not expand unrelated keywords or partial matches', async () => { const initialText = 'It is snow'; const editor = await createTestEditor(initialText, EditorSelection.cursor(initialText.length), []); const handled = tryExpandQuickTimestamp(editor, initialText.length, initialText.length, ' '); expect(handled).toBe(false); expect(editor.state.doc.toString()).toBe('It is snow'); }); }); });