BS-007 Implement accepted Contact page and independent enquiry service

This commit is contained in:
rob
2026-11-10 19:45:11 +00:00
parent 21d048a1ff
commit 5bfb128e94
46 changed files with 837 additions and 145 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ for (const width of [320, 390, 768, 1024, 1440]) {
}
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()
await expect(page.getByRole('heading', { level: 1, name: 'Have a project in mind?', exact: true })).toBeVisible()
expect(errors).toEqual([])
expect(failedRequests).toEqual([])
})
+150
View File
@@ -0,0 +1,150 @@
import AxeBuilder from '@axe-core/playwright'
import { expect, test } from '@playwright/test'
async function config(page, available = true) {
await page.route('**/api/contact/config', route => route.fulfill({ json: { email: 'business@example.com', available } }))
}
async function draft(page) {
await page.getByLabel('Name', { exact: true }).fill('Example Person')
await page.getByLabel('Email', { exact: true }).fill('person@example.com')
await page.getByLabel('Project description', { exact: true }).fill('A useful software project enquiry.')
}
for (const width of [320, 390, 768, 1024, 1536]) {
test(`Contact reference and form at ${width}`, async ({ page }) => {
await config(page)
await page.setViewportSize({ width, height: 1024 })
const errors = []
page.on('pageerror', e => errors.push(e.message))
await page.goto('/contact')
await page.evaluate(() => globalThis.document.fonts.ready)
await expect(page.getByRole('heading', { level: 1, name: 'Have a project in mind?' })).toBeVisible()
await expect(page.getByRole('textbox')).toHaveCount(3)
await expect(page.getByRole('combobox')).toHaveCount(1)
await expect(page.getByLabel('Company', { exact: true })).toHaveCount(0)
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
if (width === 1536) {
const box = await page.getByRole('form').boundingBox()
for (const [actual, ref] of [[box.x, 60], [box.y, 397], [box.width, 914], [box.height, 521]]) expect(Math.abs(actual - ref)).toBeLessThan(6)
}
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByLabel('Name', { exact: true })).toBeFocused()
await expect(page.getByText('Enter your name.', { exact: true })).toBeVisible()
expect(errors).toEqual([])
})
}
for (const theme of ['dark', 'light']) {
test(`Contact keyboard, errors and contrast in ${theme}`, async ({ page, isMobile }) => {
await config(page)
await page.addInitScript(theme => { if (!localStorage.getItem('bortstack-theme')) localStorage.setItem('bortstack-theme', theme) }, theme)
await page.goto('/contact')
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()
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
await page.getByRole('button', { name: 'Send Message' }).click()
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
if (isMobile) await page.getByRole('button', { name: 'Toggle navigation' }).click()
await expect(page.getByRole('navigation', { name: 'Main navigation' }).getByRole('link', { name: 'Contact', 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('Contact retains failed draft and key, then succeeds without duplicate submission', async ({ page }) => {
await config(page)
const keys = [], bodies = []
let finish
await page.route('**/api/contact', async route => {
keys.push(route.request().headers()['idempotency-key'])
bodies.push(route.request().postDataJSON())
if (keys.length === 1) await route.fulfill({ status: 503, json: { message: 'Sending could not be confirmed. Please retry.' } })
else { await new Promise(resolve => { finish = resolve }); await route.fulfill({ json: { success: true } }) }
})
await page.goto('/contact')
await draft(page)
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('alert')).toContainText('could not be confirmed')
await expect(page.getByRole('alert')).toBeFocused()
await expect(page.getByLabel('Name', { exact: true })).toHaveValue('Example Person')
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('button', { name: 'Sending…' })).toBeDisabled()
await expect(page.getByLabel('Name', { exact: true })).toBeDisabled()
await expect.poll(() => keys.length).toBe(2)
finish()
await expect(page.getByRole('status')).toContainText('accepted for delivery')
expect(keys[0]).toBe(keys[1])
expect(bodies[0]).toEqual(bodies[1])
expect(Object.keys(bodies[0]).sort()).toEqual(['description', 'email', 'name', 'service', 'website'])
await expect(page.getByLabel('Name', { exact: true })).toHaveValue('')
})
test('Contact shows server errors and unavailable delivery honestly', async ({ page }) => {
await config(page, false)
await page.route('**/api/contact', r => r.fulfill({ status: 400, json: { message: 'Please check the highlighted fields.', errors: { email: 'Enter a valid email address.' } } }))
await page.goto('/contact')
await expect(page.getByText(/Enquiries are temporarily unavailable/)).toBeVisible()
await draft(page)
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('alert')).toContainText('check the highlighted fields')
await expect(page.getByLabel('Email', { exact: true })).toHaveAttribute('aria-invalid', 'true')
await page.unroute('**/api/contact')
await page.route('**/api/contact', r => r.abort())
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('alert')).toContainText('draft is kept')
await expect(page.getByText('Your enquiry has been accepted for delivery. Thank you.')).toHaveCount(0)
await page.unroute('**/api/contact')
await page.route('**/api/contact', r => r.fulfill({ status: 502, contentType: 'text/html', body: '<h1>Bad gateway</h1>' }))
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('alert')).toContainText('Unable to send right now. Your draft is kept; please retry.')
})
for (const theme of ['dark', 'light']) {
for (const width of [320, 1536]) {
test(`Service popup is styled and keyboard accessible in ${theme} at ${width}`, async ({ page }, testInfo) => {
await config(page)
await page.setViewportSize({ width, height: 1024 })
await page.addInitScript(theme => localStorage.setItem('bortstack-theme', theme), theme)
await page.goto('/contact')
const select = page.getByRole('combobox', { name: /Service/ })
await select.click()
const list = page.getByRole('listbox', { name: /Service/ })
await expect(list).toBeVisible()
await expect(list.getByRole('option')).toHaveCount(5)
expect((await new AxeBuilder({ page }).analyze()).violations).toEqual([])
const colors = await list.evaluate(el => ({ bg: globalThis.getComputedStyle(el).backgroundColor, text: globalThis.getComputedStyle(el).color }))
expect(colors.bg).toBe(theme === 'dark' ? 'rgb(10, 27, 42)' : 'rgb(231, 239, 245)')
expect(colors.text).toBe(theme === 'dark' ? 'rgb(245, 247, 250)' : 'rgb(16, 38, 56)')
expect(await page.locator('html').evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true)
await page.screenshot({ path: testInfo.outputPath(`service-open-${theme}-${width}.png`), fullPage: true })
await list.getByRole('option', { name: 'API Development & Integration' }).click()
await expect(select).toContainText('API Development & Integration')
await expect(select).toBeFocused()
await expect(list).toHaveCount(0)
await select.press('ArrowDown')
await select.press('Enter')
await expect(select).toContainText('Managed Hosting & Maintenance')
await select.press('Home')
await select.press('Escape')
await expect(select).toContainText('Managed Hosting & Maintenance')
await select.press('Home')
await select.press('Enter')
await expect(select).toContainText('Select a service')
await select.click()
await select.press('Tab')
await expect(list).toHaveCount(0)
await expect(page.getByLabel('Project description')).toBeFocused()
await select.click()
await page.getByLabel('Email', { exact: true }).click()
await expect(list).toHaveCount(0)
await draft(page)
await select.click()
await page.getByRole('option', { name: 'Website Development', exact: true }).click()
let submitted
await page.route('**/api/contact', route => { submitted = route.request().postDataJSON(); return route.fulfill({ json: { success: true } }) })
await page.getByRole('button', { name: 'Send Message' }).click()
await expect(page.getByRole('status')).toContainText('accepted for delivery')
expect(submitted.service).toBe('Website Development')
await expect(select).toContainText('Select a service')
})
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ for (const width of [320, 768, 1440]) {
}
await hero.getByRole('link', { name: 'Discuss a Project' }).click()
await expect(page).toHaveURL(/\/contact$/)
await expect(page.getByRole('heading', { name: 'Contact', exact: true })).toBeVisible()
await expect(page.getByRole('heading', { name: 'Have a project in mind?', exact: true })).toBeVisible()
expect(errors).toEqual([])
expect(failedRequests).toEqual([])
})
+2 -2
View File
@@ -4,14 +4,14 @@ import { expect, test } from '@playwright/test'
for (const [path, heading] of [
['/', /Software solutions\s*for real-world use\./], ['/services', 'Services'],
['/projects', 'Projects'], ['/projects/example', 'Project details'],
['/about', 'About BortStack'], ['/contact', 'Contact'], ['/privacy', 'Privacy policy'],
['/about', 'About BortStack'], ['/contact', 'Have a project in mind?'], ['/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()) })
page.on('request', request => { if (/\/api\//.test(request.url()) && !request.url().endsWith('/api/contact/config')) 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)
+1 -1
View File
@@ -19,7 +19,7 @@ for (const width of [320, 390, 768, 1024, 1672]) {
}
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()
await expect(page.getByRole('heading', { level: 1, name: 'Have a project in mind?', exact: true })).toBeVisible()
expect(errors).toEqual([])
expect(failedRequests).toEqual([])
})
+1 -1
View File
@@ -20,7 +20,7 @@ test('stored light initializes before React is allowed to load', async ({ page }
await page.addInitScript(() => localStorage.setItem('bortstack-theme', 'light'))
let release
const gate = new Promise(resolve => { release = resolve })
await page.route('**/src/main.jsx', async route => { await gate; await route.continue() })
await page.route('**/src/main.jsx*', async route => { await gate; await route.continue() })
const navigation = page.goto('/')
await page.waitForFunction(() => globalThis.document.documentElement.dataset.bsTheme === 'light')
expect(await page.locator('#root').innerHTML()).toBe('')