一些检查失败了
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
84 行
2.9 KiB
TypeScript
84 行
2.9 KiB
TypeScript
import { cleanSnippet, formatNoteListDate, reorderNotesWithPinned, NoteListItemEntity } from './noteListSnippetUtils';
|
|
|
|
describe('noteListSnippetUtils', () => {
|
|
describe('cleanSnippet', () => {
|
|
it('returns empty string for empty or whitespace-only bodies', () => {
|
|
expect(cleanSnippet('')).toBe('');
|
|
expect(cleanSnippet(' \n \n ')).toBe('');
|
|
});
|
|
|
|
it('strips markdown syntax and returns plain text', () => {
|
|
const body = '# Title\n\nThis is **bold** and *italic* with a [link](https://example.com).';
|
|
expect(cleanSnippet(body, 'Title')).toBe('This is bold and italic with a link.');
|
|
});
|
|
|
|
it('skips redundant heading when matching title', () => {
|
|
const body = '# Meeting Notes\n\nDiscussing project roadmap.';
|
|
expect(cleanSnippet(body, 'Meeting Notes')).toBe('Discussing project roadmap.');
|
|
});
|
|
|
|
it('strips checklist markers and bullet points', () => {
|
|
const body = '- [ ] First task\n- [x] Second completed task\n* Bullet item';
|
|
expect(cleanSnippet(body)).toBe('First task Second completed task Bullet item');
|
|
});
|
|
|
|
it('truncates long text and appends ellipsis', () => {
|
|
const longText = 'A'.repeat(120);
|
|
const snippet = cleanSnippet(longText);
|
|
expect(snippet.length).toBeLessThanOrEqual(72);
|
|
expect(snippet.endsWith('…')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('formatNoteListDate', () => {
|
|
it('returns empty string when timestamp is 0 or missing', () => {
|
|
expect(formatNoteListDate(0)).toBe('');
|
|
});
|
|
|
|
it('formats today timestamp as HH:mm', () => {
|
|
const today = new Date();
|
|
today.setHours(14, 25, 0, 0);
|
|
expect(formatNoteListDate(today.getTime())).toBe('14:25');
|
|
});
|
|
|
|
it('formats past year date as YYYY/M/D', () => {
|
|
const past = new Date(2023, 4, 20, 10, 0, 0);
|
|
expect(formatNoteListDate(past.getTime())).toBe('2023/5/20');
|
|
});
|
|
});
|
|
|
|
describe('reorderNotesWithPinned', () => {
|
|
it('returns original notes when pinnedNoteIds is empty', () => {
|
|
const notes = [{ id: '1' }, { id: '2' }] as NoteListItemEntity[];
|
|
expect(reorderNotesWithPinned(notes, [])).toEqual(notes);
|
|
});
|
|
|
|
it('moves pinned notes to the front with is_pinned flag', () => {
|
|
const notes = [
|
|
{ id: '1', title: 'Note 1' },
|
|
{ id: '2', title: 'Note 2' },
|
|
{ id: '3', title: 'Note 3' },
|
|
] as NoteListItemEntity[];
|
|
|
|
const reordered = reorderNotesWithPinned(notes, ['2']);
|
|
expect(reordered.map(n => n.id)).toEqual(['2', '1', '3']);
|
|
expect(reordered[0].is_pinned).toBe(1);
|
|
expect(reordered[1].is_pinned).toBeUndefined();
|
|
});
|
|
|
|
it('preserves order of multiple pinned notes', () => {
|
|
const notes = [
|
|
{ id: '1', title: 'Note 1' },
|
|
{ id: '2', title: 'Note 2' },
|
|
{ id: '3', title: 'Note 3' },
|
|
] as NoteListItemEntity[];
|
|
|
|
const reordered = reorderNotesWithPinned(notes, ['3', '1']);
|
|
expect(reordered.map(n => n.id)).toEqual(['1', '3', '2']);
|
|
expect(reordered[0].is_pinned).toBe(1);
|
|
expect(reordered[1].is_pinned).toBe(1);
|
|
expect(reordered[2].is_pinned).toBeUndefined();
|
|
});
|
|
});
|
|
});
|