Files
BortStack/react/e2e/public-shell.spec.js
T

40 lines
2.0 KiB
JavaScript

import AxeBuilder from '@axe-core/playwright'
import { expect, test } from '@playwright/test'
for (const [path, heading] of [
['/', 'Software development for real-world needs'], ['/services', 'Services'],
['/projects', 'Projects'], ['/projects/example', 'Project details'],
['/about', 'About BortStack'], ['/contact', 'Contact'], ['/privacy', 'Privacy policy'],
['/login', 'Page not found'], ['/dashboard', 'Page not found'],
]) {
test(`${path} renders without overflow or auth requests`, async ({ page }) => {
const errors = []
const accountRequests = []
page.on('pageerror', error => errors.push(error.message))
page.on('request', request => { if (/\/api\//.test(request.url())) accountRequests.push(request.url()) })
await page.goto(path)
await expect(page.getByRole('heading', { name: heading, exact: true })).toBeVisible()
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
expect(errors).toEqual([])
expect(accountRequests).toEqual([])
})
}
test('public shell has accessible landmarks and first keyboard skip link', async ({ page }) => {
await page.goto('/')
await page.keyboard.press('Tab')
await expect(page.getByRole('link', { name: 'Skip to main content' })).toBeFocused()
await expect(page.getByRole('main')).toHaveCount(1)
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
})
test('navigation works and closes on mobile selection', async ({ page, isMobile }) => {
await page.goto('/')
const navigation = page.getByRole('navigation', { name: 'Main navigation' })
if (isMobile) await page.getByRole('button', { name: 'Toggle navigation' }).click()
await navigation.getByRole('link', { name: 'Services', exact: true }).click()
await expect(page.getByRole('heading', { name: 'Services', exact: true })).toBeVisible()
if (isMobile) await expect(page.getByRole('button', { name: 'Toggle navigation' })).toHaveAttribute('aria-expanded', 'false')
await expect(page.getByRole('link', { name: /login|register|dashboard/i })).toHaveCount(0)
})