refactor(books): shared search normalisation and debounce helpers + migrate command palette to server-side queries (#2232)

This commit is contained in:
Alex
2026-09-21 13:01:56 +01:00
committed by GitHub
parent 7ed1c35ca0
commit 04467d7d68
9 changed files with 339 additions and 83 deletions
@@ -0,0 +1,56 @@
import {effect, signal} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {debouncedSignal} from './debounced-signal';
describe('debouncedSignal', () => {
beforeEach(() => {
vi.useFakeTimers();
TestBed.configureTestingModule({});
});
afterEach(() => {
TestBed.resetTestingModule();
vi.useRealTimers();
});
it('exposes the initial source value immediately', () => {
const source = signal('initial');
const debounced = TestBed.runInInjectionContext(() => debouncedSignal(source, 200));
expect(debounced()).toBe('initial');
});
it('updates only after the debounce window', () => {
const source = signal('initial');
const debounced = TestBed.runInInjectionContext(() => debouncedSignal(source, 200));
source.set('changed');
TestBed.flushEffects();
vi.advanceTimersByTime(200 - 1);
expect(debounced()).toBe('initial');
vi.advanceTimersByTime(1);
expect(debounced()).toBe('changed');
});
it('does not emit when a change reverts to the settled value', () => {
const source = signal('settled');
const debounced = TestBed.runInInjectionContext(() => debouncedSignal(source, 200));
const values: string[] = [];
TestBed.runInInjectionContext(() => {
effect(() => values.push(debounced()));
});
TestBed.flushEffects();
source.set('temporary');
TestBed.flushEffects();
vi.advanceTimersByTime(200 / 2);
source.set('settled');
TestBed.flushEffects();
vi.advanceTimersByTime(200);
expect(values).toEqual(['settled']);
});
});