BS-012 Implement accepted Services composition and brief About

This commit is contained in:
rob
2026-11-10 17:35:15 +00:00
parent 33e3413657
commit be0dde6c07
23 changed files with 795 additions and 50 deletions
+60
View File
@@ -0,0 +1,60 @@
import AxeBuilder from '@axe-core/playwright'
import { expect, test } from '@playwright/test'
for (const width of [320, 390, 768, 1024, 1672]) {
test(`Services renders and navigates at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 941 })
const errors = []
const failedRequests = []
page.on('pageerror', error => errors.push(error.message))
page.on('requestfailed', request => failedRequests.push(request.url()))
await page.goto('/services')
await page.evaluate(() => globalThis.document.fonts.ready)
await expect(page.getByRole('region', { name: 'BortStack services' }).getByRole('article')).toHaveCount(4)
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
for (const heading of await page.getByRole('heading').all()) {
const box = await heading.boundingBox()
expect(box.x).toBeGreaterThanOrEqual(0)
expect(box.x + box.width).toBeLessThanOrEqual(width + 1)
}
await page.getByRole('link', { name: 'Get in Touch' }).click()
await expect(page).toHaveURL(/\/contact$/)
await expect(page.getByRole('heading', { level: 1, name: 'Contact', exact: true })).toBeVisible()
expect(errors).toEqual([])
expect(failedRequests).toEqual([])
})
}
for (const theme of ['dark', 'light']) {
test(`Services is accessible and theme-safe in ${theme} mode`, async ({ page, isMobile }) => {
await page.addInitScript(theme => { if (!localStorage.getItem('bortstack-theme')) localStorage.setItem('bortstack-theme', theme) }, theme)
await page.goto('/services')
await page.evaluate(() => globalThis.document.fonts.ready)
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', theme)
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
await page.keyboard.press('Tab')
await expect(page.getByRole('link', { name: 'Skip to main content' })).toBeFocused()
await page.keyboard.press('Enter')
await expect(page.getByRole('main')).toBeFocused()
if (isMobile) await page.getByRole('button', { name: 'Toggle navigation' }).click()
await expect(page.getByRole('navigation', { name: 'Main navigation' }).getByRole('link', { name: 'Services', exact: true })).toHaveAttribute('aria-current', 'page')
await page.getByRole('button', { name: `Switch to ${theme === 'dark' ? 'light' : 'dark'} mode` }).click()
await page.reload()
await expect(page.locator('html')).toHaveAttribute('data-bs-theme', theme === 'dark' ? 'light' : 'dark')
})
}
test('Services reference composition at 1672×941', async ({ page }, testInfo) => {
await page.setViewportSize({ width: 1672, height: 941 })
await page.goto('/services')
await page.evaluate(() => globalThis.document.fonts.ready)
const grid = await page.getByRole('region', { name: 'BortStack services' }).boundingBox()
expect(Math.abs(grid.x - 123)).toBeLessThanOrEqual(3)
expect(Math.abs(grid.y - 363)).toBeLessThanOrEqual(8)
const closing = await page.getByRole('region', { name: 'Have a project in mind?' }).boundingBox()
for (const [value, reference] of [[closing.x, 70], [closing.y, 688], [closing.width, 1536], [closing.height, 222]]) {
expect(Math.abs(value - reference)).toBeLessThanOrEqual(8)
}
await page.screenshot({ path: testInfo.outputPath('services-reference-viewport.png') })
await page.screenshot({ path: testInfo.outputPath('services-reference-full.png'), fullPage: true })
})