60 lines
3.6 KiB
JavaScript
60 lines
3.6 KiB
JavaScript
import AxeBuilder from '@axe-core/playwright'
|
||
import { expect, test } from '@playwright/test'
|
||
|
||
for (const width of [320, 390, 768, 1024, 1440]) {
|
||
test(`About renders and navigates at ${width}px`, async ({ page }) => {
|
||
await page.setViewportSize({ width, height: 900 })
|
||
const errors = []
|
||
const failedRequests = []
|
||
page.on('pageerror', error => errors.push(error.message))
|
||
page.on('requestfailed', request => failedRequests.push(request.url()))
|
||
await page.goto('/about')
|
||
await page.evaluate(() => globalThis.document.fonts.ready)
|
||
await expect(page.getByRole('region', { name: 'Why BortStack' }).getByRole('article')).toHaveCount(3)
|
||
await expect(page.getByRole('img', { name: /approved about laptop artwork is missing/i })).toBeVisible()
|
||
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(`About accessibility and persistent ${theme} theme`, async ({ page, isMobile }) => {
|
||
await page.addInitScript(theme => { if (!localStorage.getItem('bortstack-theme')) localStorage.setItem('bortstack-theme', theme) }, theme)
|
||
await page.goto('/about')
|
||
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: 'About', 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('About aligns with reference at 1024×1536', async ({ page }, testInfo) => {
|
||
await page.setViewportSize({ width: 1024, height: 1536 })
|
||
await page.goto('/about')
|
||
await page.evaluate(() => globalThis.document.fonts.ready)
|
||
const hero = await page.getByRole('region', { name: 'About BortStack' }).boundingBox()
|
||
for (const [actual, reference] of [[hero.x, 52], [hero.y, 74], [hero.height, 492]]) expect(Math.abs(actual - reference)).toBeLessThanOrEqual(5)
|
||
const firstRow = await page.getByRole('article', { name: 'Practical engineering' }).boundingBox()
|
||
expect(Math.abs(firstRow.y - 687)).toBeLessThanOrEqual(8)
|
||
const closing = await page.getByRole('region', { name: /From initial idea to a fully\s*deployed solution\./ }).boundingBox()
|
||
for (const [actual, reference] of [[closing.x, 30], [closing.y, 1176], [closing.width, 964], [closing.height, 275]]) expect(Math.abs(actual - reference)).toBeLessThanOrEqual(8)
|
||
await page.screenshot({ path: testInfo.outputPath('about-reference-full.png'), fullPage: true })
|
||
})
|