refactor(books): refresh paginated cache after legacy actions (#2222)

This commit is contained in:
Alex
2026-09-21 13:01:54 +01:00
committed by GitHub
parent 79ebf13be3
commit 49cc7add81
16 changed files with 216 additions and 16 deletions
@@ -9,6 +9,7 @@ import type {GroupRule} from '../component/magic-shelf-component';
import {BookService} from '../../book/service/book.service';
import {BookRuleEvaluatorService} from './book-rule-evaluator.service';
import {MagicShelfService, type MagicShelf} from './magic-shelf.service';
import {bookQueryKeys} from '../../book/data/book-query-keys';
function buildMagicShelf(overrides: Partial<MagicShelf> = {}): MagicShelf {
return {
@@ -170,6 +171,26 @@ describe('MagicShelfService', () => {
request.flush(buildMagicShelf({id: 11, name: 'Magic', filterJson: JSON.stringify(group), isPublic: true}));
expect(invalidateQueriesSpy).toHaveBeenCalledWith({queryKey: ['magicShelves'], exact: true});
expect(invalidateQueriesSpy).not.toHaveBeenCalledWith({queryKey: bookQueryKeys.collections()});
});
it('invalidates browser collections after changing an existing shelf rule', () => {
const invalidateQueriesSpy = vi.spyOn(queryClientHarness.queryClient, 'invalidateQueries').mockResolvedValue(undefined);
httpTestingController.expectOne(req => req.url.endsWith('/api/magic-shelves')).flush([]);
service.saveShelf({
id: 11,
name: 'Changed',
icon: 'zap',
group: buildGroupRule({name: 'Changed'}),
}).subscribe();
httpTestingController.expectOne(req => req.url.endsWith('/api/magic-shelves')).flush(
buildMagicShelf({id: 11, name: 'Changed'}),
);
expect(invalidateQueriesSpy).toHaveBeenCalledWith({queryKey: bookQueryKeys.collections()});
});
it('invalidates shelf queries after delete', () => {
@@ -184,6 +205,7 @@ describe('MagicShelfService', () => {
request.flush(null);
expect(invalidateQueriesSpy).toHaveBeenCalledWith({queryKey: ['magicShelves'], exact: true});
expect(invalidateQueriesSpy).toHaveBeenCalledWith({queryKey: bookQueryKeys.collections()});
});
it('finds shelves by id from the hydrated query state', async () => {