test(admin): cover all admin/system status branches
Adds backfill success banner, RUNNING import-status rendering, DONE import-status with processed count, FAILED thumbnail-status with error message, DONE thumbnail-status with retry button. 5 new tests covering state-machine branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -110,4 +110,132 @@ describe('admin/system page', () => {
|
|||||||
expect(calls.some((c) => c.includes('import-status'))).toBe(true);
|
expect(calls.some((c) => c.includes('import-status'))).toBe(true);
|
||||||
expect(calls.some((c) => c.includes('thumbnail-status'))).toBe(true);
|
expect(calls.some((c) => c.includes('thumbnail-status'))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows the success banner after backfill versions completes', async () => {
|
||||||
|
fetchSpy.mockImplementation(async (url: RequestInfo | URL) => {
|
||||||
|
const u = url.toString();
|
||||||
|
if (u.includes('backfill-versions')) {
|
||||||
|
return new Response(JSON.stringify({ count: 12 }), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ state: 'IDLE' }), {
|
||||||
|
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, 100));
|
||||||
|
const banner = document.querySelector('.bg-green-50');
|
||||||
|
expect(banner).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the running state for import-status', async () => {
|
||||||
|
fetchSpy.mockImplementation(async (url: RequestInfo | URL) => {
|
||||||
|
const u = url.toString();
|
||||||
|
if (u.includes('import-status')) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ state: 'RUNNING', message: '', processed: 0, startedAt: null }),
|
||||||
|
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ state: 'IDLE' }), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
render(AdminSystemPage, { props: {} });
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
expect(document.body.textContent).toMatch(/läuft|wird ausgeführt/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the DONE state with processed count for import-status', async () => {
|
||||||
|
fetchSpy.mockImplementation(async (url: RequestInfo | URL) => {
|
||||||
|
const u = url.toString();
|
||||||
|
if (u.includes('import-status')) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ state: 'DONE', message: '', processed: 99, startedAt: null }),
|
||||||
|
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ state: 'IDLE' }), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
render(AdminSystemPage, { props: {} });
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
expect(document.body.textContent).toContain('99');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the FAILED state with the error message for thumbnail-status', async () => {
|
||||||
|
fetchSpy.mockImplementation(async (url: RequestInfo | URL) => {
|
||||||
|
const u = url.toString();
|
||||||
|
if (u.includes('thumbnail-status')) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
state: 'FAILED',
|
||||||
|
message: 'connection refused',
|
||||||
|
total: 0,
|
||||||
|
processed: 0,
|
||||||
|
skipped: 0,
|
||||||
|
failed: 0,
|
||||||
|
startedAt: null
|
||||||
|
}),
|
||||||
|
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ state: 'IDLE' }), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
render(AdminSystemPage, { props: {} });
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
expect(document.body.textContent).toContain('connection refused');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the DONE state for thumbnail-status with retry button', async () => {
|
||||||
|
fetchSpy.mockImplementation(async (url: RequestInfo | URL) => {
|
||||||
|
const u = url.toString();
|
||||||
|
if (u.includes('thumbnail-status')) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
state: 'DONE',
|
||||||
|
message: '',
|
||||||
|
total: 100,
|
||||||
|
processed: 95,
|
||||||
|
skipped: 3,
|
||||||
|
failed: 2,
|
||||||
|
startedAt: null
|
||||||
|
}),
|
||||||
|
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ state: 'IDLE' }), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
render(AdminSystemPage, { props: {} });
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
const banner = document.querySelector('[data-testid="thumbnails-status-done"]');
|
||||||
|
expect(banner).not.toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user