feat(library): picker option to mark notes no_resolve

This commit is contained in:
afiqzudinhadi 2026-08-05 15:47:13 +08:00
parent 2686c3fa64
commit 16b8b242b8
4 changed files with 45 additions and 9 deletions

View file

@ -11,13 +11,14 @@ function fakeApp(): any {
}
describe('CandidatePickerModal', () => {
test('getItems: candidate labels followed by a trailing Skip item (null index)', () => {
test('getItems: candidate labels followed by Skip then Never resolve', () => {
const modal = new CandidatePickerModal(fakeApp(), 'Some Note.md', CANDIDATES);
const items = modal.getItems();
expect(items).toEqual([
{ label: 'Foo (2020)', index: 0 },
{ label: 'Bar (2021)', index: 1 },
{ label: 'Skip', index: null },
{ label: 'Never resolve (mark no_resolve)', index: 'never' },
]);
});
@ -40,6 +41,13 @@ describe('CandidatePickerModal', () => {
expect(await result).toBeNull();
});
test('onChooseItem(Never resolve) -> pick() resolves to \'never\'', async () => {
const modal = new CandidatePickerModal(fakeApp(), 'Some Note.md', CANDIDATES);
const result = modal.pick();
modal.onChooseItem({ label: 'Never resolve (mark no_resolve)', index: 'never' }, {} as MouseEvent);
expect(await result).toBe('never');
});
test('onClose without a prior choice (Esc / dismiss) -> pick() resolves to null', async () => {
const modal = new CandidatePickerModal(fakeApp(), 'Some Note.md', CANDIDATES);
const result = modal.pick();

View file

@ -587,6 +587,24 @@ describe('resolveType: interactive candidate picker (needsChoice)', () => {
expect(notices[0]).toContain('1 picked, 1 skipped');
});
test('pickCandidate fake returns \'never\' -> no_resolve patched via patchFrontmatter, not resolved, counted marked', async () => {
const c = new LibraryController(fakePlugin());
const notices: string[] = [];
(c as any).notify = (msg: string) => notices.push(msg);
const writes: { path: string; content: string }[] = [];
(c as any).makeDeps = () => makeCandidateDeps(writes);
(c as any).pickCandidate = async () => 'never';
const report = await c.resolveType(candidateSpec);
expect(report.resolved).toEqual([]);
expect(writes.length).toBe(1);
expect(writes[0].path).toBe('Mangas/Foo.md');
expect(writes[0].content).toContain('no_resolve: true');
expect(notices[0]).toContain('0 picked, 0 skipped');
expect(notices[0]).toContain('1 marked no-resolve');
});
test('no needsChoice entries -> summary omits the picked/skipped clause entirely', async () => {
const c = new LibraryController(fakePlugin());
const notices: string[] = [];