Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/thatdeveloperguy-website / tests/browser/inquiry.spec.ts |
| Date | Not specified in source |
| Repository | Janady13/thatdeveloperguy-website |
| Revision | 2bea2ebdff0e34494bff597d4fa9c8422a0c3a94 |
| Branch | main |
| Path or archive member | tests/browser/inquiry.spec.ts |
| Original SHA-256 | 28c5e7c617e8df526531612c938031a1a4682c14a6c1a241c7ebaa22a6e0c2ba |
| Git blob SHA | 95ce8c715b932aabe9aa20d9fb7c5377353e4e89 |
| Reading-copy SHA-256 | 28c5e7c617e8df526531612c938031a1a4682c14a6c1a241c7ebaa22a6e0c2ba |
Recovered source transcript
Download complete source text ↓78 lines · 4.9 KB
import { test, expect } from '@playwright/test';
const fill = async (page: import('@playwright/test').Page) => {
await page.goto('/contact?project=security&from=capability.cybersecurity');
await page.getByLabel('Your name').fill('Pat Example');
await page.getByLabel('Email for the reply').fill('pat@example.org');
await page.getByLabel('Message').fill('We need a security review of two offices and a small data center.');
};
const api = (outcome: string, status: number, extra: Record<string, unknown> = {}) => (route: import('@playwright/test').Route) =>
route.fulfill({ status, contentType: 'application/json', body: JSON.stringify({ outcome, requestId: 'test-req', title: 't', message: 'm', fields: {}, duplicate: false, ...extra }) });
test.describe('inquiry form', () => {
test('the service selection follows the door the visitor came through', async ({ page }) => {
await fill(page);
await expect(page.getByLabel('What is this about')).toHaveValue('security');
await expect(page.locator('input[name="from"]')).toHaveValue('capability.cybersecurity');
await expect(page.locator('form.inquiry-form')).toHaveAttribute('action', '/api/inquiries');
await expect(page.locator('form.inquiry-form')).toHaveAttribute('method', 'post');
});
test('success is shown only for provider_accepted; the form clears', async ({ page }) => {
await page.route('**/api/inquiries', api('provider_accepted', 200, { title: 'Message received', message: 'The email service accepted your message for delivery.' }));
await fill(page);
await page.getByRole('button', { name: 'Send inquiry' }).click();
await expect(page.getByRole('status')).toContainText('Message received');
await expect(page.getByLabel('Your name')).toHaveValue('');
});
test('a provider rejection is shown as failure, never success', async ({ page }) => {
await page.route('**/api/inquiries', api('provider_rejected', 502, { title: 'Message not sent', message: 'The email service refused the message.' }));
await fill(page);
await page.getByRole('button', { name: 'Send inquiry' }).click();
await expect(page.getByRole('alert')).toContainText('Message not sent');
await expect(page.getByRole('status')).toHaveCount(0);
await expect(page.getByLabel('Your name')).toHaveValue('Pat Example');
});
test('delivery_unknown is shown as uncertain, not success', async ({ page }) => {
await page.route('**/api/inquiries', api('delivery_unknown', 504, { title: 'Delivery uncertain', message: 'The email service did not confirm within the time allowed.' }));
await fill(page);
await page.getByRole('button', { name: 'Send inquiry' }).click();
await expect(page.getByRole('alert')).toContainText('Delivery uncertain');
});
test('validation failures mark the fields', async ({ page }) => {
await page.route('**/api/inquiries', api('validation_failed', 422, { title: 'Check the form', message: 'Some fields need attention.', fields: { email: 'Enter one valid email address for the reply.' } }));
await fill(page);
await page.getByRole('button', { name: 'Send inquiry' }).click();
await expect(page.getByLabel('Email for the reply')).toHaveAttribute('aria-invalid', 'true');
await expect(page.locator('#err-email')).toContainText('valid email');
});
test('opening the receipt page directly does not claim anything was sent', async ({ page }) => {
await page.goto('/contact/received');
await expect(page.getByRole('heading', { level: 1 })).toContainText('Message received');
await expect(page.locator('body')).toContainText('not yet proof it has been read');
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', 'noindex');
});
test('the form submits natively without JavaScript (the live 303 is verified by the HTTP tests)', async ({ browser }) => {
const context = await browser.newContext({ javaScriptEnabled: false });
const page = await context.newPage();
let posted: { method: string; body: string; type: string } | null = null;
await page.route('**/api/inquiries', route => { const r = route.request(); posted = { method: r.method(), body: r.postData() ?? '', type: r.headers()['content-type'] ?? '' }; return route.fulfill({ status: 200, contentType: 'text/html', body: '<!doctype html><title>ok</title>received' }); });
await page.goto('/contact');
await page.getByLabel('Your name').fill('Pat Example');
await page.getByLabel('Email for the reply').fill('pat@example.org');
await page.getByLabel('Message').fill('We need a security review of two offices and a small data center.');
await page.getByRole('button', { name: 'Send inquiry' }).click();
await expect(page).toHaveURL(/\/api\/inquiries$/);
expect(posted!.method).toBe('POST');
expect(posted!.type).toContain('application/x-www-form-urlencoded');
expect(posted!.body).toContain('name=Pat+Example');
expect(posted!.body).toContain('website=');
await context.close();
});
});