test(admin): rewrite EntityNav flyout tests with behavioral assertions

Replaces the vacuous expect(true).toBe(true) sleep test with a real
flyout-open assertion (role=dialog appears after trigger click) and
turns the Escape-keydown smoke test into a full open→Escape→closed
behavioral test. Routes the Escape event through document (matches
the svelte:document binding) instead of window.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-11 17:25:08 +02:00
committed by marcel
parent a483c1020f
commit e70511a8f8

View File

@@ -97,30 +97,37 @@ describe('EntityNav', () => {
expect(mintIcons.length).toBeGreaterThan(0);
});
it('opens the flyout on tablet trigger button click', async () => {
it('opens the flyout dialog when a tablet section trigger is clicked', async () => {
mockPage.url = new URL('http://localhost/admin/users');
const EntityNav = await loadComponent();
render(EntityNav, { props: baseProps() });
// The tablet flyout triggers are the section buttons (not links)
// The first <button> in the DOM is the tablet trigger of the first section.
const triggerButton = document.querySelector('button') as HTMLButtonElement;
if (triggerButton) {
triggerButton.click();
await new Promise((r) => setTimeout(r, 50));
}
expect(triggerButton).not.toBeNull();
triggerButton.click();
// Render did not throw — branch reached
expect(true).toBe(true);
await vi.waitFor(() => {
expect(document.querySelector('[role="dialog"]')).not.toBeNull();
});
});
it('handles Escape keypress on window without throwing', async () => {
it('Escape closes the open flyout', async () => {
mockPage.url = new URL('http://localhost/admin/users');
const EntityNav = await loadComponent();
render(EntityNav, { props: baseProps() });
expect(() =>
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
).not.toThrow();
// Open the flyout first.
(document.querySelector('button') as HTMLButtonElement).click();
await vi.waitFor(() => {
expect(document.querySelector('[role="dialog"]')).not.toBeNull();
});
// Then Escape should close it (handler is bound via svelte:document).
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await vi.waitFor(() => {
expect(document.querySelector('[role="dialog"]')).toBeNull();
});
});
it('renders the user count badge on the users link', async () => {