Add end-to-end tests for task modification and assignment features
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m33s

- Implemented tests for editing penalty points and reward costs in `penalty-edit-points.spec.ts` and `reward-edit-cost.spec.ts`.
- Created detailed plans for task activation and assignment scenarios in `task-activated.plan.md` and `task-assignment.plan.md`.
- Added comprehensive test cases for modifying tasks, including editing points for chores, kindness acts, penalties, and rewards in `task-modified.plan.md`.
- Ensured all tests are isolated and run in serial mode to maintain state integrity.
This commit is contained in:
2026-03-17 22:46:27 -04:00
parent b2115ceb57
commit a9131242a7
28 changed files with 3724 additions and 106 deletions

View File

@@ -0,0 +1,219 @@
// spec: e2e/plans/task-modified.plan copy.md
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
const CHILD_NAME = 'ModifyRewardChild'
const REWARD_NAME = 'ModifyTestReward'
const REWARD_COST = 100
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 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: 'E2E test reward', cost } })
const list = await request.get('/api/reward/list')
const { rewards } = (await list.json()) as { rewards: { name: string; id: string }[] }
return rewards?.find((r) => r.name === name)?.id ?? ''
}
function rewardSection(page: Page): Locator {
return page.locator('.child-list-container').filter({
has: page.locator('h3', { hasText: 'Rewards' }),
})
}
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('Reward edit cost', () => {
test.describe.configure({ mode: 'serial' })
let childId = ''
let rewardId = ''
test.beforeAll(async ({ request }) => {
childId = await createChild(request, CHILD_NAME)
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('Edit button appears on first click of a reward card', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_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 opens modal with reward name and "Assign new cost" subtitle', async ({
page,
}) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_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(REWARD_NAME)
await expect(page.locator('.modal-subtitle')).toContainText('new cost')
await page.getByRole('button', { name: 'Cancel' }).click()
})
test('Input is pre-populated with the current cost', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await expect(page.locator('#custom-value')).toHaveValue(String(REWARD_COST))
await page.getByRole('button', { name: 'Cancel' }).click()
})
test('Cancel does not change the points needed display', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('999')
await page.getByRole('button', { name: 'Cancel' }).click()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
// Child has 0 points; reward cost 100 → "100 more points"
await expect(card.getByText(`${REWARD_COST} more points`)).toBeVisible()
await expect(card.locator('.override-badge')).not.toBeVisible()
})
test('Saving a new cost updates the points needed and shows ⭐ badge', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('50')
await page.getByRole('button', { name: 'Save' }).click()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
// Child still has 0 points; override cost 50 → "50 more points"
await expect(card.getByText('50 more points')).toBeVisible()
await expect(card.locator('.override-badge')).toBeVisible()
})
test('Setting cost to 0 makes the reward immediately redeemable', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('0')
await page.getByRole('button', { name: 'Save' }).click()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
await expect(card.getByText('REWARD READY')).toBeVisible()
})
test('Negative value disables the Save button', async ({ page }) => {
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await openEditModal(page, card)
await page.locator('#custom-value').fill('-1')
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 = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_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()
})
test('Editing a pending reward shows a warning dialog — Cancel aborts the edit', async ({
page,
request,
}) => {
// Give child enough points to satisfy the original reward cost, then create a pending request
await request.put(`/api/child/${childId}/edit`, { data: { points: REWARD_COST } })
await request.post(`/api/child/${childId}/request-reward`, { data: { reward_id: rewardId } })
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await expect(card.getByText('PENDING')).toBeVisible()
// First click → edit button visible
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.getByTitle('Edit custom value').click()
// PendingRewardDialog should appear warning about the pending state
await expect(page.locator('.modal-message')).toContainText('pending')
// Clicking "No" closes the dialog without opening the override modal
await page.getByRole('button', { name: 'No', exact: true }).click()
await expect(page.locator('.modal-message')).not.toBeVisible()
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
})
test('Editing a pending reward — confirming the warning opens the override modal', async ({
page,
}) => {
// Pending state was established in the previous test; navigate fresh
await page.goto(`/parent/${childId}`)
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
await card.waitFor({ state: 'visible' })
await expect(card.getByText('PENDING')).toBeVisible()
await card.click()
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
await card.getByTitle('Edit custom value').click()
// PendingRewardDialog visible
await expect(page.locator('.modal-message')).toContainText('pending')
// Confirming cancels the pending request and opens the override modal
await page.getByRole('button', { name: 'Yes' }).click()
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible({ timeout: 5000 })
await page.getByRole('button', { name: 'Cancel' }).click()
})
})