BS-002 Establish public marketing routes and navigation
This commit is contained in:
@@ -1,66 +1,39 @@
|
||||
import AxeBuilder from '@axe-core/playwright'
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
const publicPages = [
|
||||
['/', 'Build your application from here'],
|
||||
['/contact', 'Contact'],
|
||||
['/privacy', 'Privacy policy'],
|
||||
['/terms', 'Terms of service'],
|
||||
['/login', 'Login'],
|
||||
['/register', 'Register'],
|
||||
['/forgot-password', 'Reset password'],
|
||||
]
|
||||
|
||||
for (const [path, heading] of publicPages) {
|
||||
test(`${path} renders without horizontal overflow`, async ({ page }) => {
|
||||
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()
|
||||
const dimensions = await page.locator('html').evaluate((element) => ({
|
||||
viewport: element.clientWidth,
|
||||
content: element.scrollWidth,
|
||||
}))
|
||||
expect(dimensions.content).toBeLessThanOrEqual(dimensions.viewport)
|
||||
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
|
||||
expect(errors).toEqual([])
|
||||
expect(accountRequests).toEqual([])
|
||||
})
|
||||
}
|
||||
|
||||
test('public shell passes automated accessibility diagnostics', async ({ page }) => {
|
||||
await page.goto('/contact')
|
||||
const results = await new AxeBuilder({ page }).analyze()
|
||||
expect(results.violations).toEqual([])
|
||||
})
|
||||
|
||||
test('skip link is the first keyboard navigation target', async ({ page }) => {
|
||||
test('public shell has accessible landmarks and first keyboard skip link', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
await page.keyboard.press('Tab')
|
||||
const skipLink = page.getByRole('link', { name: 'Skip to main content' })
|
||||
await expect(skipLink).toBeFocused()
|
||||
await expect(skipLink).toHaveAttribute('href', '#main-content')
|
||||
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('mobile navigation expands and exposes public destinations', async ({ page, isMobile }) => {
|
||||
test.skip(!isMobile, 'mobile navigation diagnostic')
|
||||
test('navigation works and closes on mobile selection', async ({ page, isMobile }) => {
|
||||
await page.goto('/')
|
||||
await page.getByRole('button', { name: 'Toggle navigation' }).click()
|
||||
await expect(page.getByRole('link', { name: 'Contact', exact: true }).first()).toBeVisible()
|
||||
await expect(page.getByRole('link', { name: 'Login', exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test('contact form reports mocked delivery success', async ({ page }) => {
|
||||
await page.route('**/api/contact', async (route) => {
|
||||
await route.fulfill({ status: 200, contentType: 'application/json', body: '{"success":true}' })
|
||||
})
|
||||
await page.goto('/contact')
|
||||
await page.getByLabel('Name').fill('Example Person')
|
||||
await page.getByLabel('Email').fill('person@example.com')
|
||||
await page.getByLabel('Subject').fill('A useful question')
|
||||
await page.getByLabel('Message').fill('This message is long enough to be accepted.')
|
||||
await page.getByRole('button', { name: 'Send message' }).click()
|
||||
await expect(page.getByRole('status')).toContainText('message has been sent')
|
||||
})
|
||||
|
||||
test('protected dashboard with no session does not expose its content', async ({ page }) => {
|
||||
await page.goto('/dashboard')
|
||||
await expect(page.getByRole('heading', { name: 'Unauthorized' })).toBeVisible()
|
||||
await expect(page.getByText('Protected application workspace')).toHaveCount(0)
|
||||
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', 'noindex, nofollow')
|
||||
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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user