122 lines
5.7 KiB
TypeScript
122 lines
5.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { PublicFormHelper } from '../../helpers/helpers';
|
|
|
|
test.describe.configure({ mode: 'serial' });
|
|
|
|
test.describe('Public Observation Form (Landing Page)', () => {
|
|
test('observation form loads from landing page', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
await expect(page.locator('#observationForm')).toBeVisible();
|
|
await expect(page.locator('textarea[name="description"]')).toBeVisible();
|
|
await expect(page.locator('.severity-option').first()).toBeVisible();
|
|
await expect(page.locator('#obsSubmitBtn')).toContainText('Submit Observation');
|
|
});
|
|
|
|
test('observation form has 4 severity levels', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
|
|
await expect(page.locator('.severity-option')).toHaveCount(4);
|
|
await expect(page.locator('.severity-option[data-value="low"]')).toBeVisible();
|
|
await expect(page.locator('.severity-option[data-value="medium"]')).toBeVisible();
|
|
await expect(page.locator('.severity-option[data-value="high"]')).toBeVisible();
|
|
await expect(page.locator('.severity-option[data-value="critical"]')).toBeVisible();
|
|
});
|
|
|
|
test('default severity is medium', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
|
|
await expect(page.locator('#severityInput')).toHaveValue('medium');
|
|
});
|
|
|
|
test('changing severity updates hidden input', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
|
|
await page.click('.severity-option[data-value="high"]');
|
|
await expect(page.locator('#severityInput')).toHaveValue('high');
|
|
|
|
await page.click('.severity-option[data-value="critical"]');
|
|
await expect(page.locator('#severityInput')).toHaveValue('critical');
|
|
});
|
|
|
|
test('observation form fills correctly', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
|
|
await page.fill('input[name="title"]', 'Test Observation Title');
|
|
await page.click('.severity-option[data-value="high"]');
|
|
await page.fill('textarea[name="description"]', 'This is a detailed test observation for E2E testing. The waiting area was overcrowded.');
|
|
await page.fill('input[name="location_text"]', 'Emergency Department - Waiting Area');
|
|
await page.fill('input[name="reporter_name"]', 'Test Reporter');
|
|
await page.fill('input[name="reporter_phone"]', '+966501112233');
|
|
await page.fill('input[name="reporter_email"]', 'reporter@example.com');
|
|
|
|
await expect(page.locator('input[name="title"]')).toHaveValue('Test Observation Title');
|
|
await expect(page.locator('textarea[name="description"]')).toHaveValue(
|
|
'This is a detailed test observation for E2E testing. The waiting area was overcrowded.'
|
|
);
|
|
await expect(page.locator('input[name="location_text"]')).toHaveValue('Emergency Department - Waiting Area');
|
|
await expect(page.locator('input[name="reporter_name"]')).toHaveValue('Test Reporter');
|
|
await expect(page.locator('input[name="reporter_phone"]')).toHaveValue('+966501112233');
|
|
await expect(page.locator('input[name="reporter_email"]')).toHaveValue('reporter@example.com');
|
|
await expect(page.locator('#severityInput')).toHaveValue('high');
|
|
});
|
|
|
|
test('back button returns to selection from observation form', async ({ page }) => {
|
|
const helper = new PublicFormHelper(page);
|
|
await helper.goToPublicLanding();
|
|
await helper.selectFormType('observation');
|
|
await page.waitForSelector('#observationForm', { timeout: 15000 });
|
|
|
|
await page.click('button:has-text("Back to Selection")');
|
|
|
|
await page.waitForSelector('.selection-card', { timeout: 10000 });
|
|
await expect(page.locator('.selection-card')).toHaveCount(3);
|
|
});
|
|
});
|
|
|
|
test.describe('Public Observation Tracking', () => {
|
|
test('tracking page loads correctly', async ({ page }) => {
|
|
await page.goto('/observations/track/');
|
|
await page.waitForSelector('input[name="tracking_code"]');
|
|
|
|
await expect(page.locator('input[name="tracking_code"]')).toBeVisible();
|
|
await expect(page.locator('button[type="submit"]')).toContainText('Track');
|
|
});
|
|
|
|
test('tracking with invalid code shows not found', async ({ page }) => {
|
|
await page.goto('/observations/track/');
|
|
await page.fill('input[name="tracking_code"]', 'INVALID-CODE-999');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const hasInfo = await page.locator('.bg-green-50, .bg-amber-50').count().then(c => c > 0);
|
|
expect(hasInfo).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test.describe('Direct Observation Submit Page', () => {
|
|
test('direct URL loads the form', async ({ page }) => {
|
|
await page.goto('/observations/new/');
|
|
await page.waitForSelector('textarea[name="description"]');
|
|
|
|
await expect(page.locator('textarea[name="description"]')).toBeVisible();
|
|
await expect(page.locator('.severity-option')).toHaveCount(4);
|
|
await expect(page.locator('button[type="submit"]')).toContainText('Submit Observation');
|
|
});
|
|
});
|