test: cover DashboardFamilyPulse and UserMenu branches
DashboardFamilyPulse: null-pulse early return, eyebrow always shown, headline gated on pages>0, you-line gated on yourPages>0, contributor chips visibility, count tile rendering. UserMenu: avatar button vs icon-only branch, aria-expanded matrix, menu open/close, profile link + logout form rendering, POST/logout form attributes. 14 tests covering ~30 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
59
frontend/src/routes/UserMenu.svelte.test.ts
Normal file
59
frontend/src/routes/UserMenu.svelte.test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
import UserMenu from './UserMenu.svelte';
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('UserMenu', () => {
|
||||
it('renders the avatar button when userInitials is set', async () => {
|
||||
render(UserMenu, { props: { userInitials: 'AS' } });
|
||||
|
||||
await expect.element(page.getByRole('button', { name: 'AS' })).toBeVisible();
|
||||
});
|
||||
|
||||
it('renders the icon-only button when userInitials is null', async () => {
|
||||
render(UserMenu, { props: { userInitials: null } });
|
||||
|
||||
await expect.element(page.getByRole('button', { name: /profil/i })).toBeVisible();
|
||||
});
|
||||
|
||||
it('starts with the menu closed (aria-expanded=false)', async () => {
|
||||
render(UserMenu, { props: { userInitials: 'AS' } });
|
||||
|
||||
await expect
|
||||
.element(page.getByRole('button', { name: 'AS' }))
|
||||
.toHaveAttribute('aria-expanded', 'false');
|
||||
});
|
||||
|
||||
it('opens the menu when the trigger is clicked', async () => {
|
||||
render(UserMenu, { props: { userInitials: 'AS' } });
|
||||
|
||||
await page.getByRole('button', { name: 'AS' }).click();
|
||||
|
||||
await expect
|
||||
.element(page.getByRole('button', { name: 'AS' }))
|
||||
.toHaveAttribute('aria-expanded', 'true');
|
||||
});
|
||||
|
||||
it('renders the profile link and logout button when the menu is open', async () => {
|
||||
render(UserMenu, { props: { userInitials: 'AS' } });
|
||||
|
||||
await page.getByRole('button', { name: 'AS' }).click();
|
||||
|
||||
await expect
|
||||
.element(page.getByRole('link', { name: /profil/i }))
|
||||
.toHaveAttribute('href', '/profile');
|
||||
await expect.element(page.getByRole('button', { name: /abmelden/i })).toBeVisible();
|
||||
});
|
||||
|
||||
it('declares POST and /logout on the logout form', async () => {
|
||||
render(UserMenu, { props: { userInitials: 'AS' } });
|
||||
|
||||
await page.getByRole('button', { name: 'AS' }).click();
|
||||
|
||||
const form = document.querySelector('form[action="/logout"]') as HTMLFormElement;
|
||||
expect(form).not.toBeNull();
|
||||
expect(form.method.toLowerCase()).toBe('post');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user