Redesign the interface around Scan and Library, classify uncatalogued books from similar ones

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 11:01:50 -07:00
1 parent 308c0e1ed3
commit 6cec404e21
71 files changed
+8634 -1502

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import type { Book } from '../shared/types.ts';
import { emptyPending, isPending, pendingIds, queueVisible, removeLater, restore, visible } from './pending.ts';
const book = (id: number, printedAt: string | null = null) => ({ id, title: 'T' + id, printedAt } as Book);
const ids = (bs: Book[]) => bs.map(b => b.id);
test('a removed book is hidden at once but remembered', () => {
const s = removeLater(emptyPending, book(1));
assert.ok(isPending(s, 1));
assert.deepEqual(ids(visible([book(1), book(2)], s)), [2]);
assert.deepEqual(ids(queueVisible([book(1), book(2)], s)), [2]);
assert.deepEqual(pendingIds(s), [1]);
});
test('a book that was printed before is only taken off the print list, never hidden from the library', () => {
const s = removeLater(emptyPending, book(1, '2026-01-01'));
assert.equal(s.items[1]!.kind, 'dequeue');
assert.deepEqual(ids(visible([book(1)], s)), [1]);
assert.deepEqual(ids(queueVisible([book(1)], s)), []);
});
test('undo brings the book back and forgets it', () => {
const s = removeLater(removeLater(emptyPending, book(1)), book(2));
const r = restore(s, 1);
assert.equal(r.removal?.book.id, 1);
assert.deepEqual(pendingIds(r.state), [2]);
assert.deepEqual(ids(visible([book(1), book(2)], r.state)), [1]);
});
test('restoring something that is not pending changes nothing', () => {
const r = restore(emptyPending, 5);
assert.equal(r.removal, null);
assert.equal(r.state, emptyPending);
});
test('removing does not touch the earlier state', () => {
const a = removeLater(emptyPending, book(1));
removeLater(a, book(2));
assert.deepEqual(pendingIds(a), [1]);
assert.deepEqual(pendingIds(emptyPending), []);
});