Refactored frontend directory
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 2m46s

This commit is contained in:
2026-04-25 00:40:15 -04:00
parent db846f4e31
commit 127378797c
263 changed files with 88 additions and 79 deletions

View File

@@ -0,0 +1,164 @@
// spec: e2e/plans/parent-notifications.plan.md §2
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
const CHILD_NAME = 'ChoreNotifApproveChild'
const CHORE_NAME = 'ChoreNotifApproveChore'
const CHORE_POINTS = 5
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
async function getPoints(page: Page): Promise<number> {
const text = await page.locator('.points .value').textContent()
return parseInt(text?.trim() ?? '0', 10)
}
function choreSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Chores' }),
})
}
test.describe('Chore Notification — Appearance and In-App Approval', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let choreId = ''
let pointsBeforeApproval = 0
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
// Set a daily interval schedule so the chore persists post-approval
await request.put(`/api/child/${childId}/task/${choreId}/schedule`, {
data: {
mode: 'interval',
interval_days: 1,
anchor_date: new Date().toLocaleDateString('en-CA'),
interval_has_deadline: false,
},
})
// Confirm the chore to create a pending notification
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
// 2.1 Confirmed chore appears in the notification view
test('Confirmed chore appears in notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await expect(item).toContainText('completed')
})
// 2.2 Notification item displays the child's name
test('Notification item displays the child name', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await expect(item).toContainText(CHILD_NAME)
})
// 2.3 Clicking notification navigates to ParentView with correct query params
test('Clicking notification navigates to ParentView with correct query params', async ({
page,
}) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await item.click()
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=chore`), {
timeout: 5000,
})
expect(page.url()).toContain(`scrollTo=${choreId}`)
expect(page.url()).toContain('entityType=chore')
await expect(page.locator('h3', { hasText: 'Chores' })).toBeVisible()
})
// 2.4 Pending chore card shows PENDING stamp in ParentView
test('Pending chore card shows PENDING stamp in ParentView', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await expect(card).toContainText('PENDING')
})
// 2.5 Clicking a pending chore card opens ChoreApproveDialog
test('Clicking a pending chore card opens ChoreApproveDialog', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
await expect(page.getByRole('button', { name: 'Approve' })).toBeVisible({ timeout: 5000 })
await expect(page.getByRole('button', { name: 'Reject' })).toBeVisible()
})
// 2.6 Approving via ChoreApproveDialog removes the PENDING stamp
test('Approving via ChoreApproveDialog removes PENDING stamp', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
// Capture points before approval for test 2.8 verification
pointsBeforeApproval = await getPoints(page)
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
const approveBtn = page.getByRole('button', { name: 'Approve' })
await expect(approveBtn).toBeVisible({ timeout: 5000 })
await approveBtn.click()
await expect(approveBtn).not.toBeVisible({ timeout: 5000 })
await expect(card).not.toContainText('PENDING', { timeout: 5000 })
})
// 2.7 Approving a chore clears it from the notification view
test('Approving a chore clears it from notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).not.toBeVisible({ timeout: 5000 })
})
// 2.8 Approving a chore awards points to the child
test('Approving a chore awards points to the child', async ({ page }) => {
// The chore was approved in test 2.6. Verify the points were updated correctly.
// (Cannot re-confirm as the chore was already approved today.)
await page.goto(`/parent/${childId}`)
const currentPoints = await getPoints(page)
expect(currentPoints).toBe(pointsBeforeApproval + CHORE_POINTS)
})
})

View File

@@ -0,0 +1,141 @@
// spec: e2e/plans/parent-notifications.plan.md §3
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
const CHILD_NAME = 'ChoreNotifDenyChild'
const CHORE_NAME = 'ChoreNotifDenyChore'
const CHORE_POINTS = 5
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
async function getPoints(page: Page): Promise<number> {
const text = await page.locator('.points .value').textContent()
return parseInt(text?.trim() ?? '0', 10)
}
function choreSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Chores' }),
})
}
test.describe('Chore Notification — In-App Rejection', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let choreId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
// Set a daily interval schedule so the chore persists post-rejection
await request.put(`/api/child/${childId}/task/${choreId}/schedule`, {
data: {
mode: 'interval',
interval_days: 1,
anchor_date: new Date().toLocaleDateString('en-CA'),
interval_has_deadline: false,
},
})
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
// 3.1 Confirmed chore appears in the notification view
test('Confirmed chore appears in notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
})
// 3.2 ChoreApproveDialog shows both Approve and Reject buttons
test('ChoreApproveDialog shows both Approve and Reject buttons', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
await expect(page.getByRole('button', { name: 'Approve' })).toBeVisible({ timeout: 5000 })
await expect(page.getByRole('button', { name: 'Reject' })).toBeVisible()
})
// 3.3 Rejecting via ChoreApproveDialog removes the PENDING stamp
test('Rejecting via ChoreApproveDialog removes PENDING stamp', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
const rejectBtn = page.getByRole('button', { name: 'Reject' })
await expect(rejectBtn).toBeVisible({ timeout: 5000 })
await rejectBtn.click()
await expect(rejectBtn).not.toBeVisible({ timeout: 5000 })
await expect(card).not.toContainText('PENDING', { timeout: 5000 })
})
// 3.4 Rejecting a chore clears it from the notification view
test('Rejecting a chore clears it from notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: CHORE_NAME })
await expect(item).not.toBeVisible({ timeout: 5000 })
})
// 3.5 Rejecting a chore does not award points
test('Rejecting a chore does not award points', async ({ page, request }) => {
// Re-confirm the chore for this test
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
await page.goto(`/parent/${childId}`)
const before = await getPoints(page)
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
const rejectBtn = page.getByRole('button', { name: 'Reject' })
await expect(rejectBtn).toBeVisible({ timeout: 5000 })
await rejectBtn.click()
await expect(rejectBtn).not.toBeVisible({ timeout: 5000 })
await expect(page.locator('.points .value')).toHaveText(String(before), { timeout: 5000 })
})
})

View File

@@ -0,0 +1,204 @@
// spec: e2e/plans/parent-notifications.plan.md §6
import { test, expect, type APIRequestContext, type Page, type Locator } from '@playwright/test'
const CHILD_NAME = 'DeepLinkChild'
const CHORE_PREFIX = 'DeepLinkChore'
const CHORE_COUNT = 10
const REWARD_NAME = 'DeepLinkReward'
const REWARD_COST = 20
const INITIAL_POINTS = 100
const NARROW_VIEWPORT = { width: 480, height: 800 }
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'deep link test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
async function isInViewport(locator: Locator): Promise<boolean> {
return locator.evaluate((el) => {
const rect = el.getBoundingClientRect()
return (
rect.bottom > 0 &&
rect.right > 0 &&
rect.top < (window.innerHeight || document.documentElement.clientHeight) &&
rect.left < (window.innerWidth || document.documentElement.clientWidth)
)
})
}
function choreSection(page: Page): Locator {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Chores' }),
})
}
function rewardSection(page: Page): Locator {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Rewards' }),
})
}
test.describe('ParentView Deep-Link Navigation', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
const choreIds: string[] = []
let targetChoreId = ''
let rewardId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_POINTS)
for (let i = 1; i <= CHORE_COUNT; i++) {
choreIds.push(await createTask(request, `${CHORE_PREFIX}${i}`, 5))
}
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: choreIds, type: 'chore' },
})
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
// Target the last chore (most likely off-screen)
targetChoreId = choreIds[CHORE_COUNT - 1]
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: targetChoreId },
})
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
for (const id of choreIds) await request.delete(`/api/task/${id}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
// 6.1 Deep link to chore — correct card is scrolled into viewport
test('Deep link to chore scrolls correct card into viewport', async ({ page }) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto(`/parent/${childId}?scrollTo=${targetChoreId}&entityType=chore`)
const card = choreSection(page)
.locator('.item-card')
.filter({ hasText: `${CHORE_PREFIX}${CHORE_COUNT}` })
await expect(card).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(800)
expect(await isInViewport(card)).toBe(true)
})
// 6.2 Deep link to reward — correct card is scrolled into viewport
test('Deep link to reward scrolls correct card into viewport', async ({ page }) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto(`/parent/${childId}?scrollTo=${rewardId}&entityType=reward`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(800)
expect(await isInViewport(card)).toBe(true)
})
// 6.3 Deep link with unknown entityType — page loads without JS error
test('Deep link with unknown entityType loads without JS error', async ({ page }) => {
const errors: string[] = []
page.on('pageerror', (err) => errors.push(err.message))
await page.goto(`/parent/${childId}?scrollTo=${targetChoreId}&entityType=unknown`)
await page.waitForTimeout(500)
expect(errors).toHaveLength(0)
await expect(page.locator('h3', { hasText: 'Chores' })).toBeVisible()
})
// 6.4 Deep link with missing scrollTo — page loads normally
test('Deep link with missing scrollTo loads normally', async ({ page }) => {
await page.goto(`/parent/${childId}?entityType=chore`)
await expect(page.locator('h3', { hasText: 'Chores' })).toBeVisible({ timeout: 5000 })
})
// 6.5 Deep link with no query params — page loads normally
test('Deep link with no query params loads normally', async ({ page }) => {
await page.goto(`/parent/${childId}`)
await expect(page.locator('h3', { hasText: 'Chores' })).toBeVisible({ timeout: 5000 })
await expect(page.locator('h3', { hasText: 'Rewards' })).toBeVisible()
})
// 6.6 Clicking a chore notification produces the correct deep link
test('Clicking a chore notification produces correct deep link', async ({ page }) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: `${CHORE_PREFIX}${CHORE_COUNT}` })
await expect(item).toBeVisible({ timeout: 5000 })
await item.click()
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=chore`), {
timeout: 5000,
})
expect(page.url()).toContain(`scrollTo=${targetChoreId}`)
expect(page.url()).toContain('entityType=chore')
const card = choreSection(page)
.locator('.item-card')
.filter({ hasText: `${CHORE_PREFIX}${CHORE_COUNT}` })
await expect(card).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(800)
expect(await isInViewport(card)).toBe(true)
})
// 6.7 Clicking a reward notification produces the correct deep link
test('Clicking a reward notification produces correct deep link', async ({ page }) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await item.click()
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=reward`), {
timeout: 5000,
})
expect(page.url()).toContain(`scrollTo=${rewardId}`)
expect(page.url()).toContain('entityType=reward')
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(800)
expect(await isInViewport(card)).toBe(true)
})
})

View File

@@ -0,0 +1,119 @@
// spec: e2e/plans/parent-notifications.plan.md §7 — approve chore
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'DigestApproveChoreChild'
const CHORE_NAME = 'DigestApproveChoreChore'
const CHORE_POINTS = 8
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
test.describe('Digest Action Token — Approve Chore', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let choreId = ''
let approveToken = ''
test.beforeAll(async ({ request, playwright }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
// Set interval schedule so chore persists post-approval
await request.put(`/api/child/${childId}/task/${choreId}/schedule`, {
data: {
mode: 'interval',
interval_days: 1,
anchor_date: new Date().toLocaleDateString('en-CA'),
interval_has_deadline: false,
},
})
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
// Obtain a valid approve-chore token via the E2E test helper
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'approve',
},
})
expect(tokenRes.status()).toBe(200)
approveToken = (await tokenRes.json()).token
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
// 7.1 Approve-chore token returns 302 redirect to correct ParentView URL
test('Approve-chore token returns 302 redirect to correct ParentView URL', async ({
playwright,
}) => {
const unauthCtx = await playwright.request.newContext({
ignoreHTTPSErrors: true,
baseURL: 'https://localhost:5173',
})
const res = await unauthCtx.get(`/api/digest-action/${approveToken}`, {
maxRedirects: 0,
})
expect(res.status()).toBe(302)
const location = res.headers()['location'] ?? ''
expect(location).toContain(`/parent/${childId}`)
expect(location).toContain(`scrollTo=${choreId}`)
expect(location).toContain('entityType=chore')
await unauthCtx.dispose()
})
// 7.2 Approve-chore action is performed: pending confirmation removed, points awarded
test('Approve-chore action is performed: points awarded and confirmation removed', async ({
request,
}) => {
// Execute the action via authenticated POST (GET only redirects, POST consumes the token)
const execRes = await request.post(`/api/digest-action/${approveToken}`)
expect(execRes.status()).toBe(200)
const childRes = await request.get(`/api/child/list`)
const children = (await childRes.json()).children ?? []
const child = children.find((c: any) => c.id === childId)
expect(child).toBeTruthy()
expect(child.points).toBeGreaterThanOrEqual(CHORE_POINTS)
const pendingRes = await request.get('/api/pending-confirmations')
const confirmations = (await pendingRes.json()).confirmations ?? []
const pending = confirmations.filter(
(c: any) => c.child_id === childId && c.entity_id === choreId,
)
// Should be no pending (status == 'pending') confirmation
expect(pending.filter((c: any) => c.status === 'pending')).toHaveLength(0)
})
})

View File

@@ -0,0 +1,113 @@
// spec: e2e/plans/parent-notifications.plan.md §7 — approve reward
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'DigestApproveRewardChild'
const REWARD_NAME = 'DigestApproveRewardReward'
const REWARD_COST = 15
const INITIAL_POINTS = 50
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'digest approve test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
test.describe('Digest Action Token — Approve Reward', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let rewardId = ''
let approveToken = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_POINTS)
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: rewardId,
entity_type: 'reward',
action: 'approve',
},
})
expect(tokenRes.status()).toBe(200)
approveToken = (await tokenRes.json()).token
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
// 7.5 Approve-reward token returns 302 redirect to correct ParentView URL
test('Approve-reward token returns 302 redirect to correct ParentView URL', async ({
playwright,
}) => {
const unauthCtx = await playwright.request.newContext({
ignoreHTTPSErrors: true,
baseURL: 'https://localhost:5173',
})
const res = await unauthCtx.get(`/api/digest-action/${approveToken}`, {
maxRedirects: 0,
})
expect(res.status()).toBe(302)
const location = res.headers()['location'] ?? ''
expect(location).toContain(`/parent/${childId}`)
expect(location).toContain(`scrollTo=${rewardId}`)
expect(location).toContain('entityType=reward')
await unauthCtx.dispose()
})
// 7.6 Approve-reward action: reward triggered, child points deducted
test('Approve-reward action: reward triggered and child points deducted', async ({ request }) => {
// Execute the action via authenticated POST (GET only redirects, POST consumes the token)
const execRes = await request.post(`/api/digest-action/${approveToken}`)
expect(execRes.status()).toBe(200)
const childRes = await request.get('/api/child/list')
const children = (await childRes.json()).children ?? []
const child = children.find((c: any) => c.id === childId)
expect(child).toBeTruthy()
expect(child.points).toBe(INITIAL_POINTS - REWARD_COST)
const pendingRes = await request.get('/api/pending-confirmations')
const confirmations = (await pendingRes.json()).confirmations ?? []
const pending = confirmations.filter(
(c: any) => c.child_id === childId && c.entity_id === rewardId && c.status === 'pending',
)
expect(pending).toHaveLength(0)
})
})

View File

@@ -0,0 +1,108 @@
// spec: e2e/plans/parent-notifications.plan.md §7 — deny chore
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'DigestDenyChoreChild'
const CHORE_NAME = 'DigestDenyChoreChore'
const CHORE_POINTS = 8
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
test.describe('Digest Action Token — Deny Chore', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let choreId = ''
let denyToken = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'deny',
},
})
expect(tokenRes.status()).toBe(200)
denyToken = (await tokenRes.json()).token
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
// 7.3 Deny-chore token returns 302 redirect to correct ParentView URL
test('Deny-chore token returns 302 redirect to correct ParentView URL', async ({
playwright,
}) => {
const unauthCtx = await playwright.request.newContext({
ignoreHTTPSErrors: true,
baseURL: 'https://localhost:5173',
})
const res = await unauthCtx.get(`/api/digest-action/${denyToken}`, {
maxRedirects: 0,
})
expect(res.status()).toBe(302)
const location = res.headers()['location'] ?? ''
expect(location).toContain(`/parent/${childId}`)
expect(location).toContain('entityType=chore')
await unauthCtx.dispose()
})
// 7.4 Deny-chore action is performed: pending confirmation removed, no points awarded
test('Deny-chore action is performed: confirmation removed, points unchanged', async ({
request,
}) => {
// Execute the action via authenticated POST (GET only redirects, POST consumes the token)
const execRes = await request.post(`/api/digest-action/${denyToken}`)
expect(execRes.status()).toBe(200)
const childRes = await request.get(`/api/child/list`)
const children = (await childRes.json()).children ?? []
const child = children.find((c: any) => c.id === childId)
expect(child).toBeTruthy()
// No points awarded for rejection
expect(child.points).toBe(0)
const pendingRes = await request.get('/api/pending-confirmations')
const confirmations = (await pendingRes.json()).confirmations ?? []
const pending = confirmations.filter(
(c: any) => c.child_id === childId && c.entity_id === choreId && c.status === 'pending',
)
expect(pending).toHaveLength(0)
})
})

View File

@@ -0,0 +1,113 @@
// spec: e2e/plans/parent-notifications.plan.md §7 — deny reward
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'DigestDenyRewardChild'
const REWARD_NAME = 'DigestDenyRewardReward'
const REWARD_COST = 15
const INITIAL_POINTS = 50
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'digest deny test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
test.describe('Digest Action Token — Deny Reward', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let rewardId = ''
let denyToken = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_POINTS)
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: rewardId,
entity_type: 'reward',
action: 'deny',
},
})
expect(tokenRes.status()).toBe(200)
denyToken = (await tokenRes.json()).token
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
// 7.7 Deny-reward token returns 302 redirect to correct ParentView URL
test('Deny-reward token returns 302 redirect to correct ParentView URL', async ({
playwright,
}) => {
const unauthCtx = await playwright.request.newContext({
ignoreHTTPSErrors: true,
baseURL: 'https://localhost:5173',
})
const res = await unauthCtx.get(`/api/digest-action/${denyToken}`, {
maxRedirects: 0,
})
expect(res.status()).toBe(302)
const location = res.headers()['location'] ?? ''
expect(location).toContain(`/parent/${childId}`)
expect(location).toContain('entityType=reward')
await unauthCtx.dispose()
})
// 7.8 Deny-reward action: pending request removed, points unchanged
test('Deny-reward action: pending request removed and points unchanged', async ({ request }) => {
// Execute the action via authenticated POST (GET only redirects, POST consumes the token)
const execRes = await request.post(`/api/digest-action/${denyToken}`)
expect(execRes.status()).toBe(200)
const childRes = await request.get('/api/child/list')
const children = (await childRes.json()).children ?? []
const child = children.find((c: any) => c.id === childId)
expect(child).toBeTruthy()
// Points should be unchanged (deny doesn't deduct anything)
expect(child.points).toBe(INITIAL_POINTS)
const pendingRes = await request.get('/api/pending-confirmations')
const confirmations = (await pendingRes.json()).confirmations ?? []
const pending = confirmations.filter(
(c: any) => c.child_id === childId && c.entity_id === rewardId && c.status === 'pending',
)
expect(pending).toHaveLength(0)
})
})

View File

@@ -0,0 +1,167 @@
// spec: e2e/plans/parent-notifications.plan.md §8
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'DigestErrorChild'
const CHORE_NAME = 'DigestErrorChore'
const CHORE_POINTS = 5
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
async function getUnauthContext(playwright: any) {
return playwright.request.newContext({
ignoreHTTPSErrors: true,
baseURL: 'https://localhost:5173',
})
}
test.describe('Digest Action Token — Error Paths', () => {
let childId = ''
let choreId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
// 8.1 Expired token returns 400
test('Expired token returns 400', async ({ request, playwright }) => {
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'approve',
expires_in_hours: -1,
},
})
expect(tokenRes.status()).toBe(200)
const expiredToken = (await tokenRes.json()).token
const unauthCtx = await getUnauthContext(playwright)
const res = await unauthCtx.get(`/api/digest-action/${expiredToken}`, { maxRedirects: 0 })
expect(res.status()).toBe(400)
expect(res.headers()['location']).toBeUndefined()
await unauthCtx.dispose()
})
// 8.2 Already-used token returns 400 on second use
test('Already-used token returns 400 on second use', async ({ request, playwright }) => {
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'deny',
},
})
expect(tokenRes.status()).toBe(200)
const token = (await tokenRes.json()).token
const unauthCtx = await getUnauthContext(playwright)
// First use — authenticated POST executes and consumes the token
const first = await request.post(`/api/digest-action/${token}`)
expect(first.status()).toBe(200)
// Second use — token is consumed, unauthenticated GET should return 400
const second = await unauthCtx.get(`/api/digest-action/${token}`, { maxRedirects: 0 })
expect(second.status()).toBe(400)
await unauthCtx.dispose()
// Re-create a pending chore confirmation for subsequent tests
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
})
// 8.3 Tampered token returns 400
test('Tampered token returns 400', async ({ request, playwright }) => {
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'approve',
},
})
expect(tokenRes.status()).toBe(200)
const validToken: string = (await tokenRes.json()).token
// Tamper: replace the last character
const lastChar = validToken[validToken.length - 1]
const replacement = lastChar === 'a' ? 'b' : 'a'
const tamperedToken = validToken.slice(0, -1) + replacement
const unauthCtx = await getUnauthContext(playwright)
const res = await unauthCtx.get(`/api/digest-action/${tamperedToken}`, { maxRedirects: 0 })
expect(res.status()).toBe(400)
await unauthCtx.dispose()
})
// 8.4 Completely fake token returns 400
test('Completely fake token returns 400', async ({ playwright }) => {
const unauthCtx = await getUnauthContext(playwright)
const res = await unauthCtx.get('/api/digest-action/this-token-does-not-exist', {
maxRedirects: 0,
})
expect(res.status()).toBe(400)
await unauthCtx.dispose()
})
// 8.5 Error response is a plain HTML page with no redirect
test('Error response is plain HTML with no Location header', async ({ request, playwright }) => {
const tokenRes = await request.post('/api/admin/test/digest-token', {
data: {
child_id: childId,
entity_id: choreId,
entity_type: 'chore',
action: 'approve',
expires_in_hours: -1,
},
})
const expiredToken = (await tokenRes.json()).token
const unauthCtx = await getUnauthContext(playwright)
const res = await unauthCtx.get(`/api/digest-action/${expiredToken}`, { maxRedirects: 0 })
expect(res.status()).toBe(400)
const contentType = res.headers()['content-type'] ?? ''
expect(contentType).toContain('text/html')
expect(res.headers()['location']).toBeUndefined()
await unauthCtx.dispose()
})
})

View File

@@ -0,0 +1,88 @@
// spec: e2e/plans/bugs-1.0.6-set01.plan.md §4
import { test, expect, type APIRequestContext } from '@playwright/test'
const CHILD_NAME = 'NotifOverflowChild'
const LONG_CHORE_NAME = 'This Is A Very Long Chore Name That Should Not Overflow The Card Boundary'
const CHORE_POINTS = 5
async function createChild(request: APIRequestContext, name: string): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
return (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
test.describe('Notification card overflow', () => {
let childId = ''
let choreId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
choreId = await createTask(request, LONG_CHORE_NAME, CHORE_POINTS)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [choreId], type: 'chore' },
})
// Confirm chore to create a pending notification
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: choreId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (choreId) await request.delete(`/api/task/${choreId}`)
})
test('Notification text does not overflow card boundaries', async ({ page }) => {
await page.goto('/parent/notifications')
const notifItem = page.locator('.list-item').filter({ hasText: LONG_CHORE_NAME })
await expect(notifItem).toBeVisible({ timeout: 5000 })
// Get bounding boxes
const cardBox = await notifItem.boundingBox()
expect(cardBox).not.toBeNull()
// Verify the card doesn't overflow horizontally beyond its parent
const parentBox = await notifItem.locator('..').boundingBox()
expect(parentBox).not.toBeNull()
if (cardBox && parentBox) {
// Card's right edge should not extend beyond parent's right edge
expect(cardBox.x + cardBox.width).toBeLessThanOrEqual(parentBox.x + parentBox.width + 1)
}
})
test('Long notification entity name wraps or clips within card', async ({ page }) => {
await page.goto('/parent/notifications')
const notifItem = page.locator('.list-item').filter({ hasText: LONG_CHORE_NAME })
await expect(notifItem).toBeVisible()
// The text content inside the notification should not cause horizontal scroll
const hasHorizontalScroll = await notifItem.evaluate((el) => {
return el.scrollWidth > el.clientWidth
})
expect(hasHorizontalScroll).toBe(false)
})
})

View File

@@ -0,0 +1,167 @@
// spec: e2e/plans/bugs-1.0.6-set01.plan.md §9
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
const CHILD_NAME = 'NotifScrollChild'
const CHORE_COUNT = 10
const CHORE_PREFIX = 'NotifScrollChore'
const TARGET_CHORE_IDX = CHORE_COUNT // last chore, likely off-screen
const REWARD_NAME = 'NotifScrollReward'
const REWARD_COST = 10
const INITIAL_CHILD_POINTS = 50
const NARROW_VIEWPORT = { width: 480, height: 800 }
async function isInViewport(locator: Locator): Promise<boolean> {
return locator.evaluate((el) => {
const rect = el.getBoundingClientRect()
return (
rect.bottom > 0 &&
rect.right > 0 &&
rect.top < (window.innerHeight || document.documentElement.clientHeight) &&
rect.left < (window.innerWidth || document.documentElement.clientWidth)
)
})
}
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createTask(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/task/list')
for (const t of (await pre.json()).tasks ?? []) {
if (t.name === name) await request.delete(`/api/task/${t.id}`)
}
await request.put('/api/task/add', { data: { name, points, type: 'chore' } })
const list = await request.get('/api/task/list')
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'notif test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
function choreSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Chores' }),
})
}
function rewardSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Rewards' }),
})
}
test.describe('Notification click navigates and scrolls to task', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
const choreIds: string[] = []
let targetChoreId = ''
let rewardId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_CHILD_POINTS)
for (let i = 1; i <= CHORE_COUNT; i++) {
choreIds.push(await createTask(request, `${CHORE_PREFIX}${i}`, 5))
}
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: choreIds, type: 'chore' },
})
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
// The target chore is the last one — most likely off-screen
targetChoreId = choreIds[TARGET_CHORE_IDX - 1]
// Confirm the target chore → creates pending notification
await request.post(`/api/child/${childId}/confirm-chore`, {
data: { task_id: targetChoreId },
})
// Request the reward → creates pending notification
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
for (const id of choreIds) await request.delete(`/api/task/${id}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
test('Clicking a chore notification navigates and scrolls to the chore card', async ({
page,
}) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto('/parent/notifications')
const targetChoreName = `${CHORE_PREFIX}${TARGET_CHORE_IDX}`
const notifItem = page.locator('.list-item').filter({ hasText: targetChoreName })
await expect(notifItem).toBeVisible({ timeout: 5000 })
await notifItem.click()
// Verify navigation to parent child view with scrollTo query param
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=chore`), {
timeout: 5000,
})
// Verify the target chore card is scrolled into viewport
const targetCard = choreSection(page).locator('.item-card').filter({ hasText: targetChoreName })
await expect(targetCard).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(1000)
expect(await isInViewport(targetCard)).toBe(true)
})
test('Clicking a reward notification scrolls reward card into viewport', async ({ page }) => {
await page.setViewportSize(NARROW_VIEWPORT)
await page.goto('/parent/notifications')
const notifItem = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(notifItem).toBeVisible({ timeout: 5000 })
await notifItem.click()
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=reward`), {
timeout: 5000,
})
const targetCard = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(targetCard).toBeVisible({ timeout: 5000 })
await page.waitForTimeout(1000)
expect(await isInViewport(targetCard)).toBe(true)
})
})

View File

@@ -0,0 +1,86 @@
// spec: e2e/plans/parent-notifications.plan.md §1
import { test, expect, type Page } from '@playwright/test'
function pushToggle(page: Page) {
return page
.locator('.toggle-field-row')
.filter({ has: page.locator('.toggle-field-label', { hasText: 'Push Notifications' }) })
.locator('button.toggle-btn')
}
test.describe('Push subscription registration', () => {
// -------------------------------------------------------------------------
// 1.3 No subscription POST when notification permission not granted
// -------------------------------------------------------------------------
test('No subscription POST is sent when notification permission is not granted', async ({
page,
}) => {
// Do NOT grant notifications permission
let postCaptured = false
await page.route('**/api/push-subscription', async (route) => {
if (route.request().method() === 'POST') {
postCaptured = true
}
await route.continue()
})
await page.goto('/parent/profile')
const toggle = pushToggle(page)
await expect(toggle).toBeVisible({ timeout: 5000 })
const isDisabled = await toggle.isDisabled().catch(() => false)
if (!isDisabled) {
// Try to click the toggle — it may prompt for permission but deny it
await toggle.click().catch(() => {})
await page
.getByRole('button', { name: 'Save' })
.click()
.catch(() => {})
await page.waitForTimeout(1000)
}
expect(postCaptured).toBe(false)
})
// -------------------------------------------------------------------------
// 1.4 Backend rejects unauthenticated subscription POST (401)
// -------------------------------------------------------------------------
test('Backend rejects unauthenticated subscription POST with 401', async ({ page }) => {
// Navigate first, then use credentials:'omit' to strip cookies and verify
// the backend enforces auth.
await page.goto('/parent/profile')
const status = await page.evaluate(async () => {
const res = await fetch('/api/push-subscription', {
method: 'POST',
credentials: 'omit',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
endpoint: 'https://fcm.googleapis.com/fcm/send/fake-endpoint',
keys: { p256dh: 'fake-key', auth: 'fake-auth' },
}),
})
return res.status
})
expect(status).toBe(401)
})
// -------------------------------------------------------------------------
// 1.5 Backend rejects unauthenticated subscription DELETE (401)
// -------------------------------------------------------------------------
test('Backend rejects unauthenticated subscription DELETE with 401', async ({ page }) => {
await page.goto('/parent/profile')
const status = await page.evaluate(async () => {
const res = await fetch('/api/push-subscription', {
method: 'DELETE',
credentials: 'omit',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
endpoint: 'https://fcm.googleapis.com/fcm/send/fake-endpoint',
}),
})
return res.status
})
expect(status).toBe(401)
})
})

View File

@@ -0,0 +1,153 @@
// spec: e2e/plans/parent-notifications.plan.md §4
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
const CHILD_NAME = 'RewardNotifApproveChild'
const REWARD_NAME = 'RewardNotifApproveReward'
const REWARD_COST = 10
const INITIAL_POINTS = 30
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'notif e2e test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
async function getPoints(page: Page): Promise<number> {
const text = await page.locator('.points .value').textContent()
return parseInt(text?.trim() ?? '0', 10)
}
function rewardSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Rewards' }),
})
}
test.describe('Reward Notification — Appearance and In-App Grant', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let rewardId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_POINTS)
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
// 4.1 Requested reward appears in the notification view
test('Requested reward appears in notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await expect(item).toContainText('requested')
})
// 4.2 Notification item displays the child's name
test('Notification item displays the child name', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await expect(item).toContainText(CHILD_NAME)
})
// 4.3 Clicking reward notification navigates to ParentView with correct query params
test('Clicking reward notification navigates to ParentView with correct query params', async ({
page,
}) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
await item.click()
await page.waitForURL(new RegExp(`/parent/${childId}\\?scrollTo=.*&entityType=reward`), {
timeout: 5000,
})
expect(page.url()).toContain(`scrollTo=${rewardId}`)
expect(page.url()).toContain('entityType=reward')
})
// 4.4 Pending reward card shows PENDING badge in ParentView
test('Pending reward card shows PENDING badge in ParentView', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await expect(card).toContainText('PENDING')
})
// 4.5 Clicking a pending reward card opens the grant confirmation dialog
test('Clicking a pending reward card opens grant confirmation dialog', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
// A confirm dialog should appear — look for a confirmation button
const confirmBtn = page.getByRole('button', { name: /yes|confirm|grant/i })
await expect(confirmBtn).toBeVisible({ timeout: 5000 })
})
// 4.6 Confirming the grant removes PENDING badge and updates child points
test('Confirming grant removes PENDING badge and updates child points', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const before = await getPoints(page)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
const confirmBtn = page.getByRole('button', { name: /yes|confirm|grant/i })
await expect(confirmBtn).toBeVisible({ timeout: 5000 })
await confirmBtn.click()
await expect(confirmBtn).not.toBeVisible({ timeout: 5000 })
await expect(card).not.toContainText('PENDING', { timeout: 5000 })
await expect(page.locator('.points .value')).toHaveText(String(before - REWARD_COST), {
timeout: 5000,
})
})
// 4.7 Granting a reward clears it from the notification view
test('Granting a reward clears it from notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).not.toBeVisible({ timeout: 5000 })
})
})

View File

@@ -0,0 +1,164 @@
// spec: e2e/plans/parent-notifications.plan.md §5
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
const CHILD_NAME = 'RewardNotifDenyChild'
const REWARD_NAME = 'RewardNotifDenyReward'
const REWARD_COST = 10
const INITIAL_POINTS = 30
async function createChild(
request: APIRequestContext,
name: string,
points: number,
): Promise<string> {
const pre = await request.get('/api/child/list')
for (const c of (await pre.json()).children ?? []) {
if (c.name === name) await request.delete(`/api/child/${c.id}`)
}
await request.put('/api/child/add', { data: { name, age: 8 } })
const list = await request.get('/api/child/list')
const id = (await list.json()).children?.find((c: any) => c.name === name)?.id ?? ''
if (points > 0) await request.put(`/api/child/${id}/edit`, { data: { points } })
return id
}
async function createReward(
request: APIRequestContext,
name: string,
cost: number,
): Promise<string> {
const pre = await request.get('/api/reward/list')
for (const r of (await pre.json()).rewards ?? []) {
if (r.name === name) await request.delete(`/api/reward/${r.id}`)
}
await request.put('/api/reward/add', { data: { name, description: 'notif e2e deny test', cost } })
const list = await request.get('/api/reward/list')
return (await list.json()).rewards?.find((r: any) => r.name === name)?.id ?? ''
}
async function getPoints(page: Page): Promise<number> {
const text = await page.locator('.points .value').textContent()
return parseInt(text?.trim() ?? '0', 10)
}
function rewardSection(page: Page) {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Rewards' }),
})
}
test.describe('Reward Notification — In-App Denial', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let rewardId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME, INITIAL_POINTS)
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
await request.put(`/api/child/${childId}/set-rewards`, {
data: { reward_ids: [rewardId] },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
})
test.beforeEach(async ({ request }) => {
// Create a fresh pending request before each test
await request.post(`/api/child/${childId}/request-reward`, {
data: { reward_id: rewardId },
})
})
test.afterEach(async ({ request }) => {
// Clean up any unconsumed pending requests
await request.post(`/api/child/${childId}/cancel-request-reward`, {
data: { reward_id: rewardId },
})
})
// 5.1 Requested reward appears in the notification view
test('Requested reward appears in notification view', async ({ page }) => {
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).toBeVisible({ timeout: 5000 })
})
// 5.2 Pending reward card shows PENDING badge in ParentView
test('Pending reward card shows PENDING badge in ParentView', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await expect(card).toContainText('PENDING')
})
// 5.3 Denying a reward request removes the PENDING badge
test('Denying a reward request removes PENDING badge', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const before = await getPoints(page)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
// Look for a Deny button in the dialog
const denyBtn = page.getByRole('button', { name: /deny/i })
await expect(denyBtn).toBeVisible({ timeout: 5000 })
await denyBtn.click()
await expect(denyBtn).not.toBeVisible({ timeout: 5000 })
await expect(card).not.toContainText('PENDING', { timeout: 5000 })
// Points should be unchanged
await expect(page.locator('.points .value')).toHaveText(String(before), { timeout: 5000 })
})
// 5.4 Denying a reward request clears it from the notification view
test('Denying a reward request clears it from notification view', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await expect(card).toBeVisible({ timeout: 5000 })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.click()
const denyBtn = page.getByRole('button', { name: /deny/i })
await expect(denyBtn).toBeVisible({ timeout: 5000 })
await denyBtn.click()
await expect(denyBtn).not.toBeVisible({ timeout: 5000 })
await page.goto('/parent/notifications')
const item = page.locator('.list-item').filter({ hasText: REWARD_NAME })
await expect(item).not.toBeVisible({ timeout: 5000 })
})
// 5.5 POST deny-reward-request returns 200 when pending request exists (API layer)
test('POST deny-reward-request returns 200 when pending request exists', async ({ request }) => {
const res = await request.post(`/api/child/${childId}/deny-reward-request`, {
data: { reward_id: rewardId },
})
expect(res.status()).toBe(200)
})
// 5.6 POST deny-reward-request returns 200 with graceful message when no pending request
test('POST deny-reward-request returns 200 gracefully when no pending request', async ({
request,
}) => {
// Cancel existing request first (afterEach will also try but that's fine)
await request.post(`/api/child/${childId}/cancel-request-reward`, {
data: { reward_id: rewardId },
})
const res = await request.post(`/api/child/${childId}/deny-reward-request`, {
data: { reward_id: rewardId },
})
// Backend returns 200 with a graceful "already resolved" message per the spec
expect(res.status()).toBe(200)
const body = await res.json()
expect(body.message).toContain('already been resolved')
})
})

View File

@@ -0,0 +1,149 @@
// spec: e2e/plans/parent-notifications.plan.md §10
import { test, expect, type Page } from '@playwright/test'
function digestToggle(page: Page) {
return page
.locator('.toggle-field-row')
.filter({ has: page.locator('.toggle-field-label', { hasText: 'Daily Digest' }) })
.locator('button.toggle-btn')
}
function pushToggle(page: Page) {
return page
.locator('.toggle-field-row')
.filter({ has: page.locator('.toggle-field-label', { hasText: 'Push Notifications' }) })
.locator('button.toggle-btn')
}
test.describe('User Profile Notification Settings', () => {
test.describe.configure({ mode: 'serial' })
// ---------------------------------------------------------------------------
// 10.1 Email Digest toggle is visible on User Profile page
// ---------------------------------------------------------------------------
test('Email Digest toggle is visible on User Profile page', async ({ page }) => {
await page.goto('/parent/profile')
await expect(digestToggle(page)).toBeVisible({ timeout: 5000 })
})
// ---------------------------------------------------------------------------
// 10.2 Email Digest toggle initialises from the server value
// ---------------------------------------------------------------------------
test('Email Digest toggle initialises from the server value', async ({ page, request }) => {
// Set known state: enabled
await request.put('/api/user/profile', { data: { email_digest_enabled: true } })
await page.goto('/parent/profile')
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'true', { timeout: 5000 })
// Set known state: disabled
await request.put('/api/user/profile', { data: { email_digest_enabled: false } })
await page.reload()
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'false', { timeout: 5000 })
// Restore default
await request.put('/api/user/profile', { data: { email_digest_enabled: true } })
})
// ---------------------------------------------------------------------------
// 10.3 Toggling Email Digest off sends email_digest_enabled: false to API
// ---------------------------------------------------------------------------
test('Toggling Email Digest off sends correct API payload', async ({ page, request }) => {
await request.put('/api/user/profile', { data: { email_digest_enabled: true } })
await page.goto('/parent/profile')
// Wait for profile to load and toggle to reflect server state
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'true', { timeout: 5000 })
let capturedBody: Record<string, unknown> | null = null
await page.route('**/api/user/profile', async (route) => {
if (route.request().method() === 'PUT') {
capturedBody = JSON.parse(route.request().postData() ?? '{}')
}
await route.continue()
})
await digestToggle(page).click()
// Submit the form (Save button)
await page.getByRole('button', { name: 'Save' }).click()
await page.waitForTimeout(500)
expect(capturedBody).not.toBeNull()
expect((capturedBody as Record<string, unknown>)['email_digest_enabled']).toBe(false)
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'false', { timeout: 3000 })
// Restore
await request.put('/api/user/profile', { data: { email_digest_enabled: true } })
})
// ---------------------------------------------------------------------------
// 10.4 Toggling Email Digest on sends email_digest_enabled: true to API
// ---------------------------------------------------------------------------
test('Toggling Email Digest on sends correct API payload', async ({ page, request }) => {
await request.put('/api/user/profile', { data: { email_digest_enabled: false } })
await page.goto('/parent/profile')
// Wait for profile to load and toggle to reflect server state
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'false', { timeout: 5000 })
let capturedBody: Record<string, unknown> | null = null
await page.route('**/api/user/profile', async (route) => {
if (route.request().method() === 'PUT') {
capturedBody = JSON.parse(route.request().postData() ?? '{}')
}
await route.continue()
})
await digestToggle(page).click()
await page.getByRole('button', { name: 'Save' }).click()
await page.waitForTimeout(500)
expect(capturedBody).not.toBeNull()
expect((capturedBody as Record<string, unknown>)['email_digest_enabled']).toBe(true)
await expect(digestToggle(page)).toHaveAttribute('aria-pressed', 'true', { timeout: 3000 })
// Restore
await request.put('/api/user/profile', { data: { email_digest_enabled: true } })
})
// ---------------------------------------------------------------------------
// 10.5 Push Notifications toggle is visible on User Profile page
// ---------------------------------------------------------------------------
test('Push Notifications toggle is visible on User Profile page', async ({ page }) => {
await page.goto('/parent/profile')
await expect(pushToggle(page)).toBeVisible({ timeout: 5000 })
})
// ---------------------------------------------------------------------------
// 10.6 Push Notifications toggle initialises to off when no subscription exists
// ---------------------------------------------------------------------------
test('Push Notifications toggle initialises to off when no subscription exists', async ({
page,
}) => {
// Do NOT grant notifications permission — toggle should start unchecked
await page.goto('/parent/profile')
const toggle = pushToggle(page)
await expect(toggle).toBeVisible({ timeout: 5000 })
// Either aria-pressed="false" or disabled (when browser denies permissions)
const ariaPressed = await toggle.getAttribute('aria-pressed')
expect(ariaPressed).toBe('false')
})
// ---------------------------------------------------------------------------
// 10.8 Push Notifications toggle is disabled when browser permission is denied
// ---------------------------------------------------------------------------
test('Push Notifications toggle is disabled when browser permission is denied', async ({
page,
context,
}) => {
// Do not grant permission (leave as denied/prompt)
await context.clearPermissions()
await page.goto('/parent/profile')
const toggle = pushToggle(page)
await expect(toggle).toBeVisible({ timeout: 5000 })
// When permission is denied, the toggle should be disabled or aria-pressed="false"
const isDisabled = await toggle.isDisabled().catch(() => false)
const ariaPressed = await toggle.getAttribute('aria-pressed')
// Either disabled or not pressed — permission denied prevents enabling it
expect(isDisabled || ariaPressed === 'false').toBe(true)
})
})