From 0972f2691bf8d96e570d5b810fbd042631fb0479 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 10 May 2026 06:51:35 +0200 Subject: [PATCH] test(admin): expand admin/invites page coverage Status color paths (exhausted/expired/revoked), new-invite form toggle, loadError banner. 5 new tests covering ~10 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 --- .../routes/admin/invites/page.svelte.test.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/frontend/src/routes/admin/invites/page.svelte.test.ts b/frontend/src/routes/admin/invites/page.svelte.test.ts index 9e43e7aa..04d4cab5 100644 --- a/frontend/src/routes/admin/invites/page.svelte.test.ts +++ b/frontend/src/routes/admin/invites/page.svelte.test.ts @@ -198,4 +198,59 @@ describe('admin/invites page', () => { await expect.element(page.getByText('Kein Ablauf')).toBeVisible(); }); + + it('renders the exhausted status with the correct color class', async () => { + render(AdminInvitesPage, { + props: { data: baseData({ invites: [makeInvite({ status: 'exhausted' })] }) } + }); + + // gray color for exhausted + const pill = Array.from(document.querySelectorAll('.bg-gray-100')); + expect(pill.length).toBeGreaterThan(0); + }); + + it('renders the expired status with the correct color class', async () => { + render(AdminInvitesPage, { + props: { data: baseData({ invites: [makeInvite({ status: 'expired' })] }) } + }); + + // amber color for expired + const pill = Array.from(document.querySelectorAll('.bg-amber-50')); + expect(pill.length).toBeGreaterThan(0); + }); + + it('renders the revoked status with the correct color class', async () => { + render(AdminInvitesPage, { + props: { data: baseData({ invites: [makeInvite({ status: 'revoked' })] }) } + }); + + const pill = Array.from(document.querySelectorAll('.bg-red-50')); + // May have other red elements (like loadError) — at least one + expect(pill.length).toBeGreaterThan(0); + }); + + it('toggles the new-invite form when the button is clicked', async () => { + render(AdminInvitesPage, { props: { data: baseData(), form: undefined } }); + + const formBefore = document.querySelector('form[action="?/create"]'); + expect(formBefore).toBeNull(); + + const newBtn = Array.from(document.querySelectorAll('button')).find((b) => + /neue|invite|einladung/i.test(b.textContent ?? '') + ) as HTMLButtonElement | undefined; + newBtn?.click(); + await new Promise((r) => setTimeout(r, 30)); + + const formAfter = document.querySelector('form[action="?/create"]'); + expect(formAfter).not.toBeNull(); + }); + + it('shows the load error banner when data.loadError is set', async () => { + render(AdminInvitesPage, { + props: { data: baseData({ loadError: 'INTERNAL_ERROR' }), form: undefined } + }); + + const banner = document.querySelector('.bg-red-50'); + expect(banner).not.toBeNull(); + }); });