Files
chore/frontend/e2e/mode_parent/task-modification/kindness-edit-points.spec.ts
Ryan Kegel 127378797c
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 2m46s
Refactored frontend directory
2026-04-25 00:40:15 -04:00

177 lines
7.3 KiB
TypeScript

// spec: e2e/plans/task-modified.plan copy.md
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
const CHILD_NAME = 'ModifyKindnessChild'
const KIND_NAME = 'ModifyTestKindness'
const KIND_HELPER_NAME = 'ModifyKindnessHelper'
const KIND_POINTS = 15
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')
const { children } = (await list.json()) as { children: { name: string; id: string }[] }
return children?.find((c) => c.name === name)?.id ?? ''
}
async function createTask(
request: APIRequestContext,
name: string,
type: 'chore' | 'kindness' | 'penalty',
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 } })
const list = await request.get('/api/task/list')
const { tasks } = (await list.json()) as { tasks: { name: string; id: string }[] }
return tasks?.find((t) => t.name === name)?.id ?? ''
}
function kindnessSection(page: Page): Locator {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Kindness Acts' }),
})
}
async function openEditModal(page: Page, card: Locator): Promise<void> {
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.getByTitle('Edit custom value').click()
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible()
}
test.describe('Kindness act edit points', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let kindId = ''
let kindHelperId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
kindId = await createTask(request, KIND_NAME, 'kindness', KIND_POINTS)
kindHelperId = await createTask(request, KIND_HELPER_NAME, 'kindness', 5)
await request.put(`/api/child/${childId}/set-tasks`, {
data: { task_ids: [kindId, kindHelperId], type: 'kindness' },
})
})
test.afterAll(async ({ request }) => {
if (childId) await request.delete(`/api/child/${childId}`)
if (kindId) await request.delete(`/api/task/${kindId}`)
if (kindHelperId) await request.delete(`/api/task/${kindHelperId}`)
})
test('Edit button appears on first click of a kindness card', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await expect(card.getByTitle('Edit custom value')).not.toBeVisible()
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await expect(card.getByTitle('Edit custom value')).toBeVisible()
})
test('Edit button disappears when clicking a different kindness card', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const section = kindnessSection(page)
const card = section.locator('.item-card').filter({ hasText: KIND_NAME })
const helperCard = section.locator('.item-card').filter({ hasText: KIND_HELPER_NAME })
await card.waitFor({ state: 'visible' })
await helperCard.waitFor({ state: 'visible' })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await expect(card.getByTitle('Edit custom value')).toBeVisible()
await helperCard.click()
await expect(card.getByTitle('Edit custom value')).not.toBeVisible()
})
test('Edit button opens modal with kindness name and "Assign new points" subtitle', async ({
page,
}) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.getByTitle('Edit custom value').click()
await expect(page.locator('.modal-title')).toHaveText(KIND_NAME)
await expect(page.locator('.modal-subtitle')).toContainText('new points')
await page.getByRole('button', { name: 'Cancel' }).click()
})
test('Input is pre-populated with the current point value', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await expect(page.locator('#custom-value')).toHaveValue(String(KIND_POINTS))
await page.getByRole('button', { name: 'Cancel' }).click()
})
test('Cancel does not save — points remain unchanged, no ⭐ badge', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('77')
await page.getByRole('button', { name: 'Cancel' }).click()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
await expect(card.locator('.item-points')).toContainText(`${KIND_POINTS} Points`)
await expect(card.locator('.override-badge')).not.toBeVisible()
})
test('Saving a new value updates displayed points and shows ⭐ badge', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('20')
await page.getByRole('button', { name: 'Save' }).click()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
await expect(card.locator('.item-points')).toContainText('20 Points')
await expect(card.locator('.override-badge')).toBeVisible()
})
test('Negative value disables the Save button', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('-5')
await expect(page.getByRole('button', { name: 'Save' })).toBeDisabled()
await page.getByRole('button', { name: 'Cancel' }).click()
})
test('Value above 10000 disables Save; exactly 10000 enables it', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('10001')
await expect(page.getByRole('button', { name: 'Save' })).toBeDisabled()
await page.locator('#custom-value').fill('10000')
await expect(page.getByRole('button', { name: 'Save' })).toBeEnabled()
await page.getByRole('button', { name: 'Cancel' }).click()
})
})