一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
49 行
2.0 KiB
TypeScript
49 行
2.0 KiB
TypeScript
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');
|
|
});
|
|
});
|
|
});
|