29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
|
|
import { describe, test, expect } from 'vitest';
|
||
|
|
import { Navbar } from './Navbar';
|
||
|
|
|
||
|
|
const toHtml = (Navbar as any).toHtml;
|
||
|
|
|
||
|
|
describe('Navbar.toHtml hamburger accessibility (F2.3)', () => {
|
||
|
|
test('mobile toggle button has an accessible name, aria-expanded, and aria-controls', () => {
|
||
|
|
const { html } = toHtml({ showMobileMenu: true }, '');
|
||
|
|
expect(html).toMatch(/class="navbar-hamburger"[^>]*aria-label="Toggle navigation menu"/);
|
||
|
|
expect(html).toMatch(/aria-expanded="false"/);
|
||
|
|
expect(html).toMatch(/aria-controls="navbar-links"/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('aria-controls target id exists on the links container', () => {
|
||
|
|
const { html } = toHtml({ showMobileMenu: true }, '');
|
||
|
|
expect(html).toContain('id="navbar-links"');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('toggle script flips aria-expanded on click', () => {
|
||
|
|
const { html } = toHtml({ showMobileMenu: true }, '');
|
||
|
|
expect(html).toMatch(/setAttribute\(['"]aria-expanded['"]/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('no mobile menu: no hamburger button emitted', () => {
|
||
|
|
const { html } = toHtml({ showMobileMenu: false }, '');
|
||
|
|
expect(html).not.toContain('navbar-hamburger');
|
||
|
|
});
|
||
|
|
});
|