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:
@@ -97,30 +97,37 @@ describe('EntityNav', () => {
|
|||||||
expect(mintIcons.length).toBeGreaterThan(0);
|
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');
|
mockPage.url = new URL('http://localhost/admin/users');
|
||||||
const EntityNav = await loadComponent();
|
const EntityNav = await loadComponent();
|
||||||
render(EntityNav, { props: baseProps() });
|
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;
|
const triggerButton = document.querySelector('button') as HTMLButtonElement;
|
||||||
if (triggerButton) {
|
expect(triggerButton).not.toBeNull();
|
||||||
triggerButton.click();
|
triggerButton.click();
|
||||||
await new Promise((r) => setTimeout(r, 50));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render did not throw — branch reached
|
await vi.waitFor(() => {
|
||||||
expect(true).toBe(true);
|
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');
|
mockPage.url = new URL('http://localhost/admin/users');
|
||||||
const EntityNav = await loadComponent();
|
const EntityNav = await loadComponent();
|
||||||
render(EntityNav, { props: baseProps() });
|
render(EntityNav, { props: baseProps() });
|
||||||
|
|
||||||
expect(() =>
|
// Open the flyout first.
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
(document.querySelector('button') as HTMLButtonElement).click();
|
||||||
).not.toThrow();
|
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 () => {
|
it('renders the user count badge on the users link', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user