The tests cover every page without JavaScript, the menu by keyboard and pointer, the fade-in at load and on scroll, and image requests per width. They found that the closed menu's shoot links could take focus, which is fixed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
264 lines
11 KiB
TypeScript
264 lines
11 KiB
TypeScript
import { mkdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
import { eventually, openPage, waitForHydration } from './support/browser.ts';
|
|
import { startServer } from './support/server.ts';
|
|
|
|
// BR-TST-05 (interactie), BR-ENT-06, BR-MAIL-10: wat een bezoeker na de
|
|
// hydratatie kan doen, en wat daarvoor en daarna anders is.
|
|
let server: Awaited<ReturnType<typeof startServer>>;
|
|
beforeAll(async () => {
|
|
server = await startServer();
|
|
});
|
|
afterAll(() => server.close());
|
|
|
|
describe('mobiel menu', () => {
|
|
it('opent en sluit met de knop en met Escape', async () => {
|
|
const { page, ...opened } = await openPage(server.origin + '/', {
|
|
width: 390,
|
|
});
|
|
await waitForHydration(page);
|
|
const toggle = page.getByTestId('nav-menu-toggle');
|
|
const menu = page.locator('#mobile-nav');
|
|
expect(await menu.isVisible()).toBe(false);
|
|
|
|
await toggle.click();
|
|
await eventually(() => toggle.getAttribute('aria-expanded')).toBe(
|
|
'true',
|
|
);
|
|
await eventually(() => menu.isVisible()).toBe(true);
|
|
|
|
await toggle.click();
|
|
await eventually(() => toggle.getAttribute('aria-expanded')).toBe(
|
|
'false',
|
|
);
|
|
await eventually(() => menu.isVisible()).toBe(false);
|
|
|
|
await toggle.click();
|
|
await eventually(() => menu.isVisible()).toBe(true);
|
|
await page.keyboard.press('Escape');
|
|
await eventually(() => menu.isVisible()).toBe(false);
|
|
expect(opened.messages).toEqual([]);
|
|
expect(opened.violations).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('navigatie in de browser', () => {
|
|
it('gaat naar een andere pagina zonder de pagina te herladen', async () => {
|
|
const { page, ...opened } = await openPage(server.origin + '/');
|
|
await waitForHydration(page);
|
|
// Blijft alleen bestaan als de pagina niet opnieuw geladen wordt
|
|
await page.evaluate(() => {
|
|
(window as unknown as { staysAlive: boolean }).staysAlive = true;
|
|
});
|
|
await page
|
|
.getByRole('navigation', { name: 'Hoofdmenu' })
|
|
.getByRole('link', { name: 'Over mij' })
|
|
.click();
|
|
await page.waitForURL('**/over-mij');
|
|
await eventually(() =>
|
|
page.locator('h1').first().textContent(),
|
|
).toMatch(/\S/);
|
|
expect(
|
|
await page.evaluate(
|
|
() =>
|
|
(window as unknown as { staysAlive?: boolean }).staysAlive,
|
|
),
|
|
).toBe(true);
|
|
expect(await page.title()).toContain('Over mij');
|
|
expect(opened.messages).toEqual([]);
|
|
expect(opened.violations).toEqual([]);
|
|
});
|
|
|
|
it('zet de focus op main na een navigatie, niet bij het eerste laden (V14)', async () => {
|
|
const { page } = await openPage(server.origin + '/');
|
|
await waitForHydration(page);
|
|
// Even wachten: de focus zou na het hydrateren kunnen schuiven
|
|
await page.waitForTimeout(500);
|
|
const focused = () =>
|
|
page.evaluate(() => document.activeElement?.id ?? '');
|
|
expect(await focused()).not.toBe('main');
|
|
|
|
await page
|
|
.getByRole('navigation', { name: 'Hoofdmenu' })
|
|
.getByRole('link', { name: 'Over mij' })
|
|
.click();
|
|
await page.waitForURL('**/over-mij');
|
|
await eventually(focused).toBe('main');
|
|
});
|
|
|
|
it('verandert de focus niet als alleen de zoekwaarde of hash wisselt (V14)', async () => {
|
|
const { page } = await openPage(
|
|
server.origin + '/contact?pakket=gezin',
|
|
);
|
|
await waitForHydration(page);
|
|
// De tidy-navigatie haalt ?pakket= weg; dat telt niet als paginawissel
|
|
await page.waitForFunction(() => location.search === '');
|
|
await page.waitForTimeout(500);
|
|
expect(
|
|
await page.evaluate(() => document.activeElement?.id ?? ''),
|
|
).not.toBe('main');
|
|
});
|
|
});
|
|
|
|
describe('het e-mailadres', () => {
|
|
it('staat niet in de HTML en komt er na de hydratatie als link', async () => {
|
|
const plain = await openPage(server.origin + '/', {
|
|
javaScript: false,
|
|
});
|
|
expect(await plain.page.getByTestId('footer-email-link').count()).toBe(
|
|
0,
|
|
);
|
|
expect(await plain.page.locator('a[href^="mailto:"]').count()).toBe(0);
|
|
|
|
const { page, ...opened } = await openPage(server.origin + '/');
|
|
await waitForHydration(page);
|
|
const link = page.getByTestId('footer-email-link');
|
|
await eventually(() => link.count()).toBe(1);
|
|
expect(await link.getAttribute('href')).toMatch(/^mailto:.+@.+/);
|
|
expect(opened.messages).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('tidy navigatie op de contactpagina (V14)', () => {
|
|
it('eindigt op /contact zonder extra geschiedenisregel en bovenaan', async () => {
|
|
const { page } = await openPage(
|
|
server.origin + '/contact?pakket=gezin',
|
|
);
|
|
const before = await page.evaluate(() => history.length);
|
|
await waitForHydration(page);
|
|
await page.waitForFunction(() => location.search === '');
|
|
expect(new URL(page.url()).pathname).toBe('/contact');
|
|
expect(await page.evaluate(() => history.length)).toBe(before);
|
|
expect(await page.evaluate(() => window.scrollY)).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('/?pakket=...#contact', () => {
|
|
it('scrolt naar het contactgedeelte', async () => {
|
|
const { page, ...opened } = await openPage(
|
|
server.origin + '/?pakket=gezin#contact',
|
|
{ height: 800 },
|
|
);
|
|
await waitForHydration(page);
|
|
const top = () =>
|
|
page
|
|
.getByTestId('contact-section')
|
|
.evaluate((section) => section.getBoundingClientRect().top);
|
|
// De scroll is vloeiend en begint na de hydratatie
|
|
await eventually(async () => (await top()) < 400).toBe(true);
|
|
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0);
|
|
expect(opened.messages).toEqual([]);
|
|
expect(opened.violations).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('structured data en CSP (BR-SCR-22)', () => {
|
|
it('JSON-LD blijft inline staan zonder dat de CSP het blokkeert', async () => {
|
|
const { page, ...opened } = await openPage(server.origin + '/over-mij');
|
|
await waitForHydration(page);
|
|
expect(
|
|
await page.locator('script[type="application/ld+json"]').count(),
|
|
).toBeGreaterThan(0);
|
|
expect(opened.violations).toEqual([]);
|
|
expect(opened.messages).toEqual([]);
|
|
});
|
|
});
|
|
|
|
// V15: de stijlen staan in de HTML, de pagina springt niet bij de hydratatie.
|
|
// Een screenshotvergelijking met en zonder JavaScript gaat naar
|
|
// E2E_SCREENSHOT_DIR (alleen als die gezet is); er wordt naar gekeken, niet
|
|
// op pixels vergeleken. Ook zonder JavaScript toont de pagina nu zijn inhoud
|
|
// (Reveal is zichtbaar, de foto's staan in de noscript-tweeling); alleen de
|
|
// uitgestelde foto's en de bedieningen die script nodig hebben verschillen.
|
|
describe('stijlen zonder en met JavaScript (V15)', () => {
|
|
it('heeft de stijlen in de HTML', async () => {
|
|
const html = await (await fetch(server.origin + '/over-mij')).text();
|
|
expect(html).toMatch(/<style data-emotion=/);
|
|
expect(html).toMatch(/<link rel="stylesheet" href="\/assets\/index-/);
|
|
});
|
|
|
|
it.each([390, 1280])(
|
|
'houdt de kop en de pagina op hun plek bij %i px',
|
|
async (width) => {
|
|
const url = server.origin + '/over-mij';
|
|
const dir = process.env.E2E_SCREENSHOT_DIR;
|
|
if (dir) mkdirSync(dir, { recursive: true });
|
|
const box = (page: import('playwright-core').Page) =>
|
|
page.evaluate(() => {
|
|
const rect = (selector: string) => {
|
|
const { x, y, width, height } = document
|
|
.querySelector(selector)!
|
|
.getBoundingClientRect();
|
|
return { x, y, width, height };
|
|
};
|
|
return {
|
|
h1: rect('h1'),
|
|
main: rect('main'),
|
|
footerTop: rect('footer').y + window.scrollY,
|
|
};
|
|
});
|
|
|
|
const plain = await openPage(url, { javaScript: false, width });
|
|
await plain.page.waitForLoadState('networkidle');
|
|
const withoutScript = await box(plain.page);
|
|
if (dir) {
|
|
await plain.page.screenshot({
|
|
path: join(dir, `over-mij-${width}-zonder-js.png`),
|
|
});
|
|
}
|
|
|
|
const { page, ...opened } = await openPage(url, { width });
|
|
await waitForHydration(page);
|
|
await page.waitForLoadState('networkidle');
|
|
await page.waitForTimeout(1500);
|
|
const withScript = await box(page);
|
|
if (dir) {
|
|
await page.screenshot({
|
|
path: join(dir, `over-mij-${width}-met-js.png`),
|
|
});
|
|
}
|
|
|
|
// De kop staat op dezelfde plek; tot ruim een regel verschil in de
|
|
// hoogte van de pagina is toegestaan (afbeeldingen, e-mailregel)
|
|
expect(withScript.h1.x).toBeCloseTo(withoutScript.h1.x, 0);
|
|
expect(withScript.h1.y).toBeCloseTo(withoutScript.h1.y, 0);
|
|
expect(withScript.h1.width).toBeCloseTo(withoutScript.h1.width, 0);
|
|
expect(withScript.main.y).toBeCloseTo(withoutScript.main.y, 0);
|
|
expect(opened.messages).toEqual([]);
|
|
},
|
|
);
|
|
});
|
|
|
|
// V9: de reviews staan in de HTML; de kopieën naast de langste zijn alleen
|
|
// voor zoekmachines en schermlezers verborgen en verstoren de lay-out niet
|
|
describe('reviews voor het laden van de carrousel (V9)', () => {
|
|
it('toont één review, de rest is 1 px, aria-hidden en inert', async () => {
|
|
const { page } = await openPage(server.origin + '/', {
|
|
javaScript: false,
|
|
width: 390,
|
|
});
|
|
const slides = await page
|
|
.getByTestId('testimonials')
|
|
.locator('[data-testid^="testimonial-"]')
|
|
.evaluateAll((elements) =>
|
|
elements.map((element) => {
|
|
const { width, height } = element.getBoundingClientRect();
|
|
return {
|
|
size: [Math.round(width), Math.round(height)],
|
|
hidden: !!element.closest(
|
|
'[aria-hidden="true"][inert]',
|
|
),
|
|
};
|
|
}),
|
|
);
|
|
expect(slides.length).toBeGreaterThan(1);
|
|
const [shown, ...copies] = slides;
|
|
expect(shown.hidden).toBe(false);
|
|
expect(shown.size[1]).toBeGreaterThan(50);
|
|
for (const copy of copies) {
|
|
expect(copy).toEqual({ size: [1, 1], hidden: true });
|
|
}
|
|
});
|
|
});
|