mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
195328f7a6
* Persist saved annotate file edits in drafts * Handle stale saved file edit context * Test source edit conflict actions * Return source metadata for single-file docs * Fix saved file edit conflict races * Handle deleted source files in annotate edits * Tighten annotate missing-file recovery * Reset edit state for missing file reopen * Tighten source edit restore path handling * Harden source edit recovery paths * Harden source edit disk reconciliation * Fix live file tree startup delay * Document file tree watcher startup ordering * Preserve source save through missing files and symlinks * Harden missing source file recovery * Tighten annotate source edit boundaries
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import type { DraftEditedDocument } from '@plannotator/ui/hooks/useAnnotationDraft';
|
|
import { pickRestoredSingleFileDraftToDisplay } from './draftRestoreSelection';
|
|
|
|
function draft(key: string, scope: 'single-file' | 'folder-file' = 'single-file'): DraftEditedDocument {
|
|
return {
|
|
key,
|
|
sourceSave: {
|
|
enabled: true,
|
|
kind: 'local-text-file',
|
|
scope,
|
|
path: `/repo/${key}.md`,
|
|
basename: `${key}.md`,
|
|
language: 'markdown',
|
|
hash: `sha256:${key}`,
|
|
mtimeMs: 1,
|
|
size: 2,
|
|
eol: 'lf',
|
|
},
|
|
sessionOpenText: 'a\n',
|
|
diskBaseline: 'a\n',
|
|
currentText: 'b\n',
|
|
};
|
|
}
|
|
|
|
describe('pickRestoredSingleFileDraftToDisplay', () => {
|
|
test('keeps the active restored single-file draft visible', () => {
|
|
expect(
|
|
pickRestoredSingleFileDraftToDisplay([draft('a'), draft('b')], ['a', 'b'], 'b')?.key,
|
|
).toBe('b');
|
|
});
|
|
|
|
test('shows the only restored single-file draft when nothing is active', () => {
|
|
expect(
|
|
pickRestoredSingleFileDraftToDisplay([draft('a')], ['a'], null)?.key,
|
|
).toBe('a');
|
|
});
|
|
|
|
test('does not guess across multiple drafts or folder files', () => {
|
|
expect(pickRestoredSingleFileDraftToDisplay([draft('a'), draft('b')], ['a', 'b'], null)).toBeUndefined();
|
|
expect(pickRestoredSingleFileDraftToDisplay([draft('a', 'folder-file')], ['a'], null)).toBeUndefined();
|
|
});
|
|
});
|