一些检查失败了
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
67 行
2.6 KiB
TypeScript
67 行
2.6 KiB
TypeScript
import { runtime, getTodayDatePrefix, getTodayNoteTitle, normalizeDateWeekdayToChinese } from './openTodayNote';
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
|
|
import Note from '@joplin/lib/models/Note';
|
|
import Folder from '@joplin/lib/models/Folder';
|
|
import Setting from '@joplin/lib/models/Setting';
|
|
|
|
describe('openTodayNote', () => {
|
|
beforeEach(async () => {
|
|
await setupDatabaseAndSynchronizer(1);
|
|
await switchClient(1);
|
|
});
|
|
|
|
it('formats date prefix and note title correctly in Chinese weekday', () => {
|
|
const fixedDate = new Date(2026, 10, 1, 12, 0, 0); // 2026-11-01 (星期日)
|
|
const prefix = getTodayDatePrefix(fixedDate.getTime());
|
|
expect(prefix).toBe('2026-11-01');
|
|
|
|
const titleSunday = getTodayNoteTitle(fixedDate.getTime());
|
|
expect(titleSunday).toBe('2026-11-01 星期日');
|
|
|
|
const mondayDate = new Date(2026, 10, 2, 12, 0, 0); // 2026-11-02 (星期一)
|
|
const titleMonday = getTodayNoteTitle(mondayDate.getTime());
|
|
expect(titleMonday).toBe('2026-11-02 星期一');
|
|
});
|
|
|
|
it('normalizes English weekdays to Chinese weekdays', () => {
|
|
expect(normalizeDateWeekdayToChinese('2026-11-02 Monday')).toBe('2026-11-02 星期一');
|
|
expect(normalizeDateWeekdayToChinese('# 2026-11-02 Monday\n\n• [ ]')).toBe('# 2026-11-02 星期一\n\n• [ ]');
|
|
expect(normalizeDateWeekdayToChinese('2026-11-03 Tuesday')).toBe('2026-11-03 星期二');
|
|
});
|
|
|
|
it('creates a new today note if none exists', async () => {
|
|
const activeFolder = await Folder.save({ title: 'Work' });
|
|
Setting.setValue('activeFolderId', activeFolder.id);
|
|
|
|
await runtime().execute(null);
|
|
|
|
const prefix = getTodayDatePrefix();
|
|
const notes = await Note.search({ query: prefix });
|
|
expect(notes.length).toBe(1);
|
|
expect(notes[0].title.startsWith(prefix)).toBe(true);
|
|
expect(notes[0].title).toMatch(/星期[一二三四五六日]/);
|
|
expect(notes[0].body).toContain(`- [ ] `);
|
|
});
|
|
|
|
it('reuses existing today note and migrates English weekday to Chinese weekday', async () => {
|
|
const activeFolder = await Folder.save({ title: 'Work' });
|
|
Setting.setValue('activeFolderId', activeFolder.id);
|
|
|
|
const todayPrefix = getTodayDatePrefix();
|
|
const existing = await Note.save({
|
|
title: `${todayPrefix} Monday`,
|
|
body: `# ${todayPrefix} Monday\n\n• [ ] 备忘录`,
|
|
parent_id: activeFolder.id,
|
|
});
|
|
|
|
await runtime().execute(null);
|
|
|
|
const loaded = await Note.load(existing.id);
|
|
expect(loaded.id).toBe(existing.id);
|
|
expect(loaded.title).toMatch(/星期[一二三四五六日]/);
|
|
expect(loaded.title).not.toContain('Monday');
|
|
expect(loaded.body).toMatch(/星期[一二三四五六日]/);
|
|
expect(loaded.body).not.toContain('Monday');
|
|
});
|
|
});
|