All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 2m59s
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import { test as setup } from '@playwright/test'
|
|
import { STORAGE_STATE, E2E_EMAIL, E2E_PASSWORD, E2E_PIN } from './e2e-constants'
|
|
|
|
setup('authenticate', async ({ page }) => {
|
|
// Seed backend test data
|
|
const backendUrl = 'http://localhost:5000'
|
|
const seedRes = await page.request.post(`${backendUrl}/auth/e2e-seed`)
|
|
if (!seedRes.ok()) {
|
|
throw new Error(`e2e-seed failed: ${seedRes.status()} ${await seedRes.text()}`)
|
|
}
|
|
|
|
await page.goto('/auth/login')
|
|
await page.getByLabel('Email address').fill(E2E_EMAIL)
|
|
await page.getByLabel('Password').fill(E2E_PASSWORD)
|
|
await page.getByRole('button', { name: 'Sign in' }).click()
|
|
|
|
// After login the router redirects to /child (not parent-authenticated yet)
|
|
await page.waitForURL(/\/(parent|child)/)
|
|
|
|
// Click the LoginButton in the header to open the PIN modal
|
|
await page.getByRole('button', { name: 'Parent login' }).click()
|
|
|
|
// Fill in the PIN and submit
|
|
const pinInput = page.getByLabel('PIN').or(page.getByPlaceholder('Enter PIN'))
|
|
await pinInput.waitFor({ timeout: 5000 })
|
|
await page.screenshot({ path: 'auth-setup-before-pin.png' })
|
|
await pinInput.fill(E2E_PIN)
|
|
await page.screenshot({ path: 'auth-setup-after-pin.png' })
|
|
await page.getByRole('button', { name: 'Verify' }).click()
|
|
|
|
// LoginButton does router.push('/parent') after PIN - wait for it
|
|
await page.waitForURL(/\/parent(\/|$)/)
|
|
|
|
// Confirm parent mode is active by waiting for the Add Child FAB at /parent
|
|
try {
|
|
await page.getByRole('button', { name: 'Add Child' }).waitFor({ timeout: 5000 })
|
|
} catch (e) {
|
|
await page.screenshot({ path: 'auth-setup-parent-fail.png' })
|
|
throw new Error('Parent mode not reached after PIN entry. See auth-setup-parent-fail.png for details.')
|
|
}
|
|
|
|
await page.context().storageState({ path: STORAGE_STATE })
|
|
})
|