test(admin): expand admin/system page coverage
Adds backfill-versions and backfill-file-hashes click handlers, verifies initial fetch hits import-status and thumbnail-status. 3 new tests targeting ~10 branches in the page component. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
import AdminSystemPage from './+page.svelte';
|
||||
@@ -6,6 +6,28 @@ import AdminSystemPage from './+page.svelte';
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('admin/system page', () => {
|
||||
let fetchSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
state: 'IDLE',
|
||||
message: '',
|
||||
total: 0,
|
||||
processed: 0,
|
||||
skipped: 0,
|
||||
failed: 0
|
||||
}),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fetchSpy?.mockRestore();
|
||||
});
|
||||
|
||||
it('renders the backfill versions card', async () => {
|
||||
render(AdminSystemPage, { props: {} });
|
||||
|
||||
@@ -46,4 +68,46 @@ describe('admin/system page', () => {
|
||||
const banners = document.querySelectorAll('.bg-green-50');
|
||||
expect(banners.length).toBe(0);
|
||||
});
|
||||
|
||||
it('triggers backfill versions when its button is clicked', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ count: 7 }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
);
|
||||
|
||||
render(AdminSystemPage, { props: {} });
|
||||
|
||||
const btn = (await page
|
||||
.getByRole('button', { name: /jetzt auffüllen/i })
|
||||
.element()) as HTMLButtonElement;
|
||||
btn.click();
|
||||
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
const calls = fetchSpy.mock.calls.map((c) => c[0].toString());
|
||||
expect(calls.some((c) => c.includes('backfill-versions'))).toBe(true);
|
||||
});
|
||||
|
||||
it('triggers file-hashes backfill when its button is clicked', async () => {
|
||||
render(AdminSystemPage, { props: {} });
|
||||
|
||||
const btn = (await page
|
||||
.getByRole('button', { name: /datei-hashes berechnen/i })
|
||||
.element()) as HTMLButtonElement;
|
||||
btn.click();
|
||||
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
const calls = fetchSpy.mock.calls.map((c) => c[0].toString());
|
||||
expect(calls.some((c) => c.includes('backfill-file-hashes'))).toBe(true);
|
||||
});
|
||||
|
||||
it('initial fetch loads import-status and thumbnail-status', async () => {
|
||||
render(AdminSystemPage, { props: {} });
|
||||
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
const calls = fetchSpy.mock.calls.map((c) => c[0].toString());
|
||||
expect(calls.some((c) => c.includes('import-status'))).toBe(true);
|
||||
expect(calls.some((c) => c.includes('thumbnail-status'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user