refactor(books): add shelf data layer (#2188)

This commit is contained in:
Alex
2026-09-21 13:01:51 +01:00
committed by GitHub
parent 78e132aeee
commit 9be47b7ec0
9 changed files with 213 additions and 1 deletions
@@ -1,6 +1,6 @@
import {describe, expect, it} from 'vitest';
import {overlayPendingBookState} from './book-command-pending-state';
import {overlayPendingBookState, overlayShelfIds} from './book-command-pending-state';
import {type BookSummary} from './book-response.models';
describe('overlayPendingBookState', () => {
@@ -9,6 +9,10 @@ describe('overlayPendingBookState', () => {
libraryId: 2,
libraryName: 'Library',
readStatus: 'UNREAD',
shelves: [
{id: 20, name: 'Remove', publicShelf: false, bookCount: 1},
{id: 30, name: 'Keep', publicShelf: false, bookCount: 1},
],
epubProgress: {
cfi: 'epubcfi(/6/2)',
href: 'chapter-1.xhtml',
@@ -56,4 +60,22 @@ describe('overlayPendingBookState', () => {
expect(result.koreaderProgress).toBeUndefined();
expect(result.epubProgress).toEqual(book.epubProgress);
});
it('leaves shelf membership off the overlaid book', () => {
expect(overlayPendingBookState(book, {
...emptyOverlay,
readStatuses: new Map([[1, 'READ']]),
}).shelves).toBe(book.shelves);
});
it('reports confirmed shelf IDs when nothing is in flight', () => {
expect(overlayShelfIds(book, undefined)).toEqual(new Set([20, 30]));
});
it('applies in-flight assignments and removals to the shelf IDs', () => {
expect(overlayShelfIds(book, {
assignShelfIds: new Set([40]),
unassignShelfIds: new Set([20]),
})).toEqual(new Set([30, 40]));
});
});