release / govulncheck (push) Successful in 23s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m41s
release / integration (push) Successful in 4m49s
release / android (push) Successful in 5m32s
release / Build signed APK (releases and dev) (push) Successful in 5m39s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 28s
release / Verify release artifacts (tag releases only) (push) Skipped
CI run 8789 warned on both: - kit 3 deprecates `config.alias`. The $test-utils alias becomes a `#test-utils/*` subpath import, matching #lib, and its 43 import sites move with it. - Vite's coming native config loader needs the extension on vitest.config.ts's import of vite.config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.4 KiB
TypeScript
94 lines
3.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
import { render, screen, fireEvent } from '@testing-library/svelte';
|
|
import { pageUrlModule } from '#test-utils/mocks/appState.js';
|
|
|
|
const state = vi.hoisted(() => ({
|
|
pageUrl: new URL('http://localhost/')
|
|
}));
|
|
|
|
vi.mock('$app/state', () => pageUrlModule(state));
|
|
|
|
vi.mock('$app/navigation', () => ({
|
|
goto: vi.fn()
|
|
}));
|
|
|
|
import SearchInput from './SearchInput.svelte';
|
|
import { goto } from '$app/navigation';
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
state.pageUrl = new URL('http://localhost/');
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
describe('SearchInput', () => {
|
|
test('mount pre-fills value from page.url.searchParams', () => {
|
|
state.pageUrl = new URL('http://localhost/search?q=hello');
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
expect(input.value).toBe('hello');
|
|
});
|
|
|
|
test('typing fires goto once after 250ms debounce', async () => {
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: 'h' } });
|
|
expect(goto).not.toHaveBeenCalled();
|
|
vi.advanceTimersByTime(250);
|
|
expect(goto).toHaveBeenCalledTimes(1);
|
|
expect(goto).toHaveBeenCalledWith('/search?q=h', { replace: false, reset: false });
|
|
});
|
|
|
|
test('rapid keystrokes debounce to a single goto', async () => {
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: 'h' } });
|
|
vi.advanceTimersByTime(100);
|
|
await fireEvent.input(input, { target: { value: 'he' } });
|
|
vi.advanceTimersByTime(100);
|
|
await fireEvent.input(input, { target: { value: 'hel' } });
|
|
vi.advanceTimersByTime(250);
|
|
expect(goto).toHaveBeenCalledTimes(1);
|
|
expect(goto).toHaveBeenCalledWith('/search?q=hel', { replace: false, reset: false });
|
|
});
|
|
|
|
test('typing while on /search uses replace=true', async () => {
|
|
state.pageUrl = new URL('http://localhost/search?q=h');
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: 'he' } });
|
|
vi.advanceTimersByTime(250);
|
|
expect(goto).toHaveBeenCalledWith('/search?q=he', { replace: true, reset: false });
|
|
});
|
|
|
|
test('clearing input on /search calls goto("/search") (drops ?q=)', async () => {
|
|
state.pageUrl = new URL('http://localhost/search?q=h');
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: '' } });
|
|
vi.advanceTimersByTime(250);
|
|
expect(goto).toHaveBeenCalledWith('/search', { replace: true, reset: false });
|
|
});
|
|
|
|
test('Escape clears the input value', async () => {
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: 'hello' } });
|
|
expect(input.value).toBe('hello');
|
|
await fireEvent.keyDown(input, { key: 'Escape' });
|
|
expect(input.value).toBe('');
|
|
});
|
|
|
|
test('encodeURIComponent applied to special chars', async () => {
|
|
render(SearchInput);
|
|
const input = screen.getByRole('searchbox') as HTMLInputElement;
|
|
await fireEvent.input(input, { target: { value: 'a b&c' } });
|
|
vi.advanceTimersByTime(250);
|
|
expect(goto).toHaveBeenCalledWith('/search?q=a%20b%26c', { replace: false, reset: false });
|
|
});
|
|
});
|