Refactored frontend directory
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 2m46s
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 2m46s
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
// spec: e2e/plans/task-modified.plan copy.md
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'ModifyChoreChild'
|
||||
const CHORE_NAME = 'ModifyTestChore'
|
||||
const CHORE_POINTS = 10
|
||||
const HELPER_KIND_NAME = 'ModifyChoreHelperKindness'
|
||||
|
||||
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 choreSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Chores' }),
|
||||
})
|
||||
}
|
||||
|
||||
function kindnessSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Kindness Acts' }),
|
||||
})
|
||||
}
|
||||
|
||||
async function openChoreOverrideModal(page: Page, card: Locator): Promise<void> {
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
await card.getByRole('button', { name: 'Options' }).click()
|
||||
await page.getByRole('button', { name: 'Edit Points' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible()
|
||||
}
|
||||
|
||||
test.describe('Chore edit points', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let choreId = ''
|
||||
let helperKindId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
choreId = await createTask(request, CHORE_NAME, 'chore', CHORE_POINTS)
|
||||
helperKindId = await createTask(request, HELPER_KIND_NAME, 'kindness', 5)
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [choreId], type: 'chore' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [helperKindId], type: 'kindness' },
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
if (choreId) await request.delete(`/api/task/${choreId}`)
|
||||
if (helperKindId) await request.delete(`/api/task/${helperKindId}`)
|
||||
})
|
||||
|
||||
test('Kebab button is hidden initially, visible after first click, hidden after deselect', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Initially hidden (v-show=false while selectedChoreId != item.id)
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeHidden()
|
||||
|
||||
// First click: card enters ready state, kebab shown
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
|
||||
// Clicking a kindness card resets selectedChoreId to null → kebab hidden
|
||||
const kindCard = kindnessSection(page)
|
||||
.locator('.item-card')
|
||||
.filter({ hasText: HELPER_KIND_NAME })
|
||||
await kindCard.click()
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeHidden()
|
||||
})
|
||||
|
||||
test('Kebab menu contains "Edit Points" and "Schedule"', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
await card.getByRole('button', { name: 'Options' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Edit Points' })).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'Schedule' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('"Edit Points" opens override modal pre-populated with current points', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
await card.getByRole('button', { name: 'Options' }).click()
|
||||
await page.getByRole('button', { name: 'Edit Points' }).click()
|
||||
|
||||
await expect(page.locator('.modal-title')).toHaveText(CHORE_NAME)
|
||||
await expect(page.locator('#custom-value')).toHaveValue(String(CHORE_POINTS))
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
})
|
||||
|
||||
test('Clicking outside the modal does not close it', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await openChoreOverrideModal(page, card)
|
||||
|
||||
// Click the backdrop area far from the modal dialog
|
||||
await page.locator('.modal-backdrop').click({ position: { x: 5, y: 5 }, force: true })
|
||||
|
||||
// Modal must still be visible
|
||||
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
})
|
||||
|
||||
test('Cancel does not save — card still shows original points, no ⭐ badge', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreOverrideModal(page, card)
|
||||
await page.locator('#custom-value').fill('99')
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
await expect(card.locator('.item-points')).toContainText(`${CHORE_POINTS} Points`)
|
||||
await expect(card.locator('.override-badge')).not.toBeVisible()
|
||||
})
|
||||
|
||||
test('Saving a valid new value updates the displayed points on the card', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreOverrideModal(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()
|
||||
await expect(card.locator('.item-points')).toContainText('50 Points')
|
||||
})
|
||||
|
||||
test('⭐ override badge appears on the card after saving a custom value', async ({ page }) => {
|
||||
// Badge state persists server-side; verify on a fresh page load
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await expect(card.locator('.override-badge')).toBeVisible()
|
||||
})
|
||||
|
||||
test('⭐ badge persists after changing value back to the original default', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Change override back to original value — badge stays until item is unassigned/reassigned
|
||||
await openChoreOverrideModal(page, card)
|
||||
await page.locator('#custom-value').fill(String(CHORE_POINTS))
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
await expect(card.locator('.item-points')).toContainText(`${CHORE_POINTS} Points`)
|
||||
await expect(card.locator('.override-badge')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Negative value disables the Save button', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreOverrideModal(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 = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreOverrideModal(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('Zero is a valid value — card shows "0 Points" with ⭐ badge', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreOverrideModal(page, card)
|
||||
await page.locator('#custom-value').fill('0')
|
||||
await expect(page.getByRole('button', { name: 'Save' })).toBeEnabled()
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
await expect(card.locator('.item-points')).toContainText('0 Points')
|
||||
await expect(card.locator('.override-badge')).toBeVisible()
|
||||
})
|
||||
})
|
||||
170
frontend/e2e/mode_parent/task-modification/chore-reset.spec.ts
Normal file
170
frontend/e2e/mode_parent/task-modification/chore-reset.spec.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
// spec: e2e/plans/task-modified.plan copy.md
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'ModifyResetChild'
|
||||
const CHORE_NAME = 'ModifyResetChore'
|
||||
const CHORE_POINTS = 10
|
||||
const HELPER_KIND_NAME = 'ModifyResetKindnessHelper'
|
||||
|
||||
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 ?? ''
|
||||
}
|
||||
|
||||
async function activateItem(itemCard: Locator): Promise<void> {
|
||||
await itemCard.click()
|
||||
await expect(itemCard).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await itemCard.click()
|
||||
}
|
||||
|
||||
function choreSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Chores' }),
|
||||
})
|
||||
}
|
||||
|
||||
async function openChoreKebab(page: Page, card: Locator): Promise<void> {
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
await card.getByRole('button', { name: 'Options' }).click()
|
||||
}
|
||||
|
||||
test.describe('Chore reset', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let choreId = ''
|
||||
let helperKindId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
choreId = await createTask(request, CHORE_NAME, 'chore', CHORE_POINTS)
|
||||
helperKindId = await createTask(request, HELPER_KIND_NAME, 'kindness', 5)
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [choreId], type: 'chore' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [helperKindId], type: 'kindness' },
|
||||
})
|
||||
// Add a schedule so COMPLETED status persists after trigger
|
||||
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,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
if (choreId) await request.delete(`/api/task/${choreId}`)
|
||||
if (helperKindId) await request.delete(`/api/task/${helperKindId}`)
|
||||
})
|
||||
|
||||
test('"Reset" is absent from kebab menu when chore is not yet completed', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openChoreKebab(page, card)
|
||||
await expect(page.getByRole('button', { name: 'Reset' })).not.toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'Edit Points' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('Chore shows COMPLETED stamp after activation and confirmation', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await activateItem(card)
|
||||
await expect(page.getByRole('button', { name: 'Yes' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
})
|
||||
|
||||
test('"Reset" appears in kebab menu after chore is completed', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
|
||||
await openChoreKebab(page, card)
|
||||
await expect(page.getByRole('button', { name: 'Reset' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('Clicking "Reset" removes the COMPLETED stamp', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
|
||||
await openChoreKebab(page, card)
|
||||
await page.getByRole('button', { name: 'Reset' }).click()
|
||||
|
||||
await expect(card.getByText('COMPLETED')).not.toBeVisible()
|
||||
})
|
||||
|
||||
test('Chore is re-activatable after reset — returns to COMPLETED on confirm', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Chore is not completed after the previous test's reset
|
||||
await expect(card.getByText('COMPLETED')).not.toBeVisible()
|
||||
|
||||
await activateItem(card)
|
||||
await expect(page.getByRole('button', { name: 'Yes' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Reset → activate cycle is repeatable without error', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Reset the now-completed chore
|
||||
await openChoreKebab(page, card)
|
||||
await page.getByRole('button', { name: 'Reset' }).click()
|
||||
await expect(card.getByText('COMPLETED')).not.toBeVisible()
|
||||
|
||||
// Navigate fresh so item-ready state is cleared before activating
|
||||
await page.goto(`/parent/${childId}`)
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Activate again — COMPLETED returns
|
||||
await activateItem(card)
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,176 @@
|
||||
// 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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,241 @@
|
||||
// spec: e2e/plans/task-modified.plan copy.md
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'ModifyActivateChild'
|
||||
const CHORE_NAME = 'ModifyActChore'
|
||||
const KIND_NAME = 'ModifyActKindness'
|
||||
const PEN_NAME = 'ModifyActPenalty'
|
||||
const REWARD_NAME = 'ModifyActReward'
|
||||
|
||||
const CHORE_POINTS = 10
|
||||
const KIND_POINTS = 10
|
||||
const PEN_POINTS = 10
|
||||
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 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 ?? ''
|
||||
}
|
||||
|
||||
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 ?? ''
|
||||
}
|
||||
|
||||
async function getPoints(page: Page): Promise<number> {
|
||||
const text = await page.locator('.points .value').textContent()
|
||||
return parseInt(text?.trim() ?? '0', 10)
|
||||
}
|
||||
|
||||
async function activateItem(itemCard: Locator): Promise<void> {
|
||||
await itemCard.click()
|
||||
await expect(itemCard).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await itemCard.click()
|
||||
}
|
||||
|
||||
function choreSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Chores' }),
|
||||
})
|
||||
}
|
||||
|
||||
function kindnessSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Kindness Acts' }),
|
||||
})
|
||||
}
|
||||
|
||||
function penaltySection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Penalties' }),
|
||||
})
|
||||
}
|
||||
|
||||
function rewardSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Rewards' }),
|
||||
})
|
||||
}
|
||||
|
||||
async function openChoreOverrideModal(page: Page, card: Locator): Promise<void> {
|
||||
await card.click()
|
||||
await expect(card).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
await expect(card.getByRole('button', { name: 'Options' })).toBeVisible()
|
||||
await card.getByRole('button', { name: 'Options' }).click()
|
||||
await page.getByRole('button', { name: 'Edit Points' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible()
|
||||
}
|
||||
|
||||
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('Modified points take effect on activation', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let choreId = ''
|
||||
let kindId = ''
|
||||
let penId = ''
|
||||
let rewardId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
choreId = await createTask(request, CHORE_NAME, 'chore', CHORE_POINTS)
|
||||
kindId = await createTask(request, KIND_NAME, 'kindness', KIND_POINTS)
|
||||
penId = await createTask(request, PEN_NAME, 'penalty', PEN_POINTS)
|
||||
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
|
||||
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [choreId], type: 'chore' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [kindId], type: 'kindness' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [penId], type: 'penalty' },
|
||||
})
|
||||
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 (choreId) await request.delete(`/api/task/${choreId}`)
|
||||
if (kindId) await request.delete(`/api/task/${kindId}`)
|
||||
if (penId) await request.delete(`/api/task/${penId}`)
|
||||
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
|
||||
})
|
||||
|
||||
test('Modified chore points are awarded on activation (override 25, default 10)', async ({
|
||||
page,
|
||||
}) => {
|
||||
// Edit override to 25 via kebab → Edit Points
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await openChoreOverrideModal(page, card)
|
||||
await page.locator('#custom-value').fill('25')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
|
||||
// Fresh navigation — activate chore and verify points awarded at override rate
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const choreCard = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await choreCard.waitFor({ state: 'visible' })
|
||||
const before = await getPoints(page)
|
||||
|
||||
await activateItem(choreCard)
|
||||
await expect(page.getByRole('button', { name: 'Yes' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
|
||||
await expect(page.locator('.points .value')).toHaveText(String(before + 25))
|
||||
})
|
||||
|
||||
test('Modified kindness points are awarded on activation (override 8, default 10)', async ({
|
||||
page,
|
||||
}) => {
|
||||
// Edit override to 8 via edit button
|
||||
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('8')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
|
||||
// Fresh navigation — activate and verify points use override value
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const kindCard = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
|
||||
await kindCard.waitFor({ state: 'visible' })
|
||||
const before = await getPoints(page)
|
||||
|
||||
await activateItem(kindCard)
|
||||
await expect(page.getByRole('button', { name: 'Yes' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
|
||||
await expect(page.locator('.points .value')).toHaveText(String(before + 8))
|
||||
})
|
||||
|
||||
test('Modified penalty points are deducted at override rate (override 3, default 10)', async ({
|
||||
page,
|
||||
}) => {
|
||||
// Edit penalty override to 3 via edit button
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
await openEditModal(page, card)
|
||||
await page.locator('#custom-value').fill('3')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
|
||||
// Fresh navigation — activate penalty and verify deduction uses override value
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const penCard = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await penCard.waitFor({ state: 'visible' })
|
||||
const before = await getPoints(page)
|
||||
|
||||
await activateItem(penCard)
|
||||
await expect(page.getByRole('button', { name: 'Yes' })).toBeVisible()
|
||||
await page.getByRole('button', { name: 'Yes' }).click()
|
||||
|
||||
await expect(page.locator('.points .value')).toHaveText(String(before - 3))
|
||||
})
|
||||
|
||||
test('Modified reward cost is reflected in points needed display (override 30)', async ({
|
||||
page,
|
||||
}) => {
|
||||
// Edit reward override to 30 via edit button
|
||||
// Child currently has 25 + 8 - 3 = 30 points from previous tests
|
||||
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('30')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
|
||||
// Fresh navigation — verify reward shows "REWARD READY" (30pts held, 30 cost override)
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const rewardCard = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
|
||||
await rewardCard.waitFor({ state: 'visible' })
|
||||
await expect(rewardCard.getByText('REWARD READY')).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,151 @@
|
||||
// spec: e2e/plans/bugs-1.0.6-set01.plan.md §5
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'OverrideSSEChild'
|
||||
const CHORE_NAME = 'OverrideSSEChore'
|
||||
const KIND_NAME = 'OverrideSSEKindness'
|
||||
const PEN_NAME = 'OverrideSSEPenalty'
|
||||
|
||||
const CHORE_POINTS = 10
|
||||
const KIND_POINTS = 15
|
||||
const PEN_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,
|
||||
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')
|
||||
return (await list.json()).tasks?.find((t: any) => t.name === name)?.id ?? ''
|
||||
}
|
||||
|
||||
function choreSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Chores' }),
|
||||
})
|
||||
}
|
||||
|
||||
function kindnessSection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Kindness Acts' }),
|
||||
})
|
||||
}
|
||||
|
||||
function penaltySection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Penalties' }),
|
||||
})
|
||||
}
|
||||
|
||||
test.describe('Override SSE updates child view', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let choreId = ''
|
||||
let kindId = ''
|
||||
let penId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
choreId = await createTask(request, CHORE_NAME, 'chore', CHORE_POINTS)
|
||||
kindId = await createTask(request, KIND_NAME, 'kindness', KIND_POINTS)
|
||||
penId = await createTask(request, PEN_NAME, 'penalty', PEN_POINTS)
|
||||
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [choreId], type: 'chore' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [kindId], type: 'kindness' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [penId], type: 'penalty' },
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
if (choreId) await request.delete(`/api/task/${choreId}`)
|
||||
if (kindId) await request.delete(`/api/task/${kindId}`)
|
||||
if (penId) await request.delete(`/api/task/${penId}`)
|
||||
})
|
||||
|
||||
test('Changing chore override points updates child view in real time', async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Verify original points displayed
|
||||
await expect(card.getByText(`${CHORE_POINTS} Points`)).toBeVisible()
|
||||
|
||||
// Set override via API
|
||||
await request.put(`/api/child/${childId}/override`, {
|
||||
data: { entity_id: choreId, entity_type: 'task', custom_value: 25 },
|
||||
})
|
||||
|
||||
// Without page reload, verify the card updates
|
||||
await expect(card.getByText('25 Points')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Changing kindness override points updates child view', async ({ page, request }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = kindnessSection(page).locator('.item-card').filter({ hasText: KIND_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await expect(card.getByText(`${KIND_POINTS} Points`)).toBeVisible()
|
||||
|
||||
await request.put(`/api/child/${childId}/override`, {
|
||||
data: { entity_id: kindId, entity_type: 'task', custom_value: 30 },
|
||||
})
|
||||
|
||||
await expect(card.getByText('30 Points')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Changing penalty override points updates child view', async ({ page, request }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await expect(card.getByText(`${PEN_POINTS} Points`)).toBeVisible()
|
||||
|
||||
await request.put(`/api/child/${childId}/override`, {
|
||||
data: { entity_id: penId, entity_type: 'task', custom_value: 20 },
|
||||
})
|
||||
|
||||
await expect(card.getByText('20 Points')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Deleting an override reverts child view to original points', async ({ page, request }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Currently showing overridden value from earlier test
|
||||
await expect(card.getByText('25 Points')).toBeVisible()
|
||||
|
||||
// Delete the override
|
||||
await request.delete(`/api/child/${childId}/override/${choreId}`)
|
||||
|
||||
// Without page reload, verify the card reverts to original points
|
||||
await expect(card.getByText(`${CHORE_POINTS} Points`)).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,182 @@
|
||||
// spec: e2e/plans/task-modified.plan copy.md
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'ModifyPenaltyChild'
|
||||
const PEN_NAME = 'ModifyTestPenalty'
|
||||
const PEN_HELPER_NAME = 'ModifyPenaltyHelper'
|
||||
const PEN_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')
|
||||
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 penaltySection(page: Page): Locator {
|
||||
return page.locator('.child-list-container').filter({
|
||||
has: page.locator('h3', { hasText: 'Penalties' }),
|
||||
})
|
||||
}
|
||||
|
||||
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('Penalty edit points', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let penId = ''
|
||||
let penHelperId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
penId = await createTask(request, PEN_NAME, 'penalty', PEN_POINTS)
|
||||
penHelperId = await createTask(request, PEN_HELPER_NAME, 'penalty', PEN_POINTS)
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [penId, penHelperId], type: 'penalty' },
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
if (penId) await request.delete(`/api/task/${penId}`)
|
||||
if (penHelperId) await request.delete(`/api/task/${penHelperId}`)
|
||||
})
|
||||
|
||||
test('Edit button appears on first click of a penalty card', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_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 penalty card', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const section = penaltySection(page)
|
||||
const card = section.locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
const helperCard = section.locator('.item-card').filter({ hasText: PEN_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 penalty name and "Assign new points" subtitle', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_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(PEN_NAME)
|
||||
await expect(page.locator('.modal-subtitle')).toContainText('new points')
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
})
|
||||
|
||||
test('Input is pre-populated with the raw point value (positive, not negated)', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openEditModal(page, card)
|
||||
// The input holds the positive magnitude; the negative display is a UI convention
|
||||
await expect(page.locator('#custom-value')).toHaveValue(String(PEN_POINTS))
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
})
|
||||
|
||||
test('Cancel does not change the display', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openEditModal(page, card)
|
||||
await page.locator('#custom-value').fill('99')
|
||||
await page.getByRole('button', { name: 'Cancel' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
// Penalty displays points negated: -5 Points
|
||||
await expect(card.locator('.item-points')).toContainText(`-${PEN_POINTS} Points`)
|
||||
await expect(card.locator('.override-badge')).not.toBeVisible()
|
||||
})
|
||||
|
||||
test('Saving a new value updates card to show negated override and ⭐ badge', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
await openEditModal(page, card)
|
||||
await page.locator('#custom-value').fill('12')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Save' })).not.toBeVisible()
|
||||
await expect(card.locator('.item-points')).toContainText('-12 Points')
|
||||
await expect(card.locator('.override-badge')).toBeVisible()
|
||||
})
|
||||
|
||||
test('Negative value disables the Save button', async ({ page }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = penaltySection(page).locator('.item-card').filter({ hasText: PEN_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 = penaltySection(page).locator('.item-card').filter({ hasText: PEN_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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,221 @@
|
||||
// spec: e2e/plans/bugs-1.0.6-set01.plan.md §10
|
||||
|
||||
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'PendingResetChild'
|
||||
const CHORE_NAME = 'PendingResetChore'
|
||||
const REWARD_NAME = 'PendingResetReward'
|
||||
const CHORE_POINTS = 10
|
||||
const REWARD_COST = 20
|
||||
const INITIAL_CHILD_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 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: 'E2E pending-reset 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('Pending status resets on task/reward modification', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
let choreId = ''
|
||||
let rewardId = ''
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME, INITIAL_CHILD_POINTS)
|
||||
choreId = await createTask(request, CHORE_NAME, CHORE_POINTS)
|
||||
rewardId = await createReward(request, REWARD_NAME, REWARD_COST)
|
||||
|
||||
// Assign chore + reward
|
||||
await request.put(`/api/child/${childId}/set-tasks`, {
|
||||
data: { task_ids: [choreId], type: 'chore' },
|
||||
})
|
||||
await request.put(`/api/child/${childId}/set-rewards`, {
|
||||
data: { reward_ids: [rewardId] },
|
||||
})
|
||||
|
||||
// Create interval schedule for chore (no deadline)
|
||||
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,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
if (choreId) await request.delete(`/api/task/${choreId}`)
|
||||
if (rewardId) await request.delete(`/api/reward/${rewardId}`)
|
||||
})
|
||||
|
||||
test('10.1 Editing chore points clears pending status', async ({ page, request }) => {
|
||||
// Create pending via child confirm-chore API
|
||||
await request.post(`/api/child/${childId}/confirm-chore`, {
|
||||
data: { task_id: choreId },
|
||||
})
|
||||
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Verify PENDING stamp is visible
|
||||
const stamp = card.locator('.chore-stamp')
|
||||
await expect(stamp).toHaveText('PENDING')
|
||||
|
||||
// Edit the parent task's points via API (triggers SSE → clears pending)
|
||||
await request.put(`/api/task/${choreId}/edit`, { data: { points: CHORE_POINTS + 1 } })
|
||||
|
||||
// Wait for SSE to propagate — PENDING should disappear
|
||||
await expect(stamp).not.toBeVisible({ timeout: 5000 })
|
||||
})
|
||||
|
||||
test('10.2 Changing chore schedule clears pending status', async ({ page, request }) => {
|
||||
// Create pending again (10.1 cleared the previous one)
|
||||
await request.post(`/api/child/${childId}/confirm-chore`, {
|
||||
data: { task_id: choreId },
|
||||
})
|
||||
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
const stamp = card.locator('.chore-stamp')
|
||||
await expect(stamp).toHaveText('PENDING')
|
||||
|
||||
// Change the schedule via API (triggers SSE → clears pending)
|
||||
await request.put(`/api/child/${childId}/task/${choreId}/schedule`, {
|
||||
data: {
|
||||
mode: 'interval',
|
||||
interval_days: 2,
|
||||
anchor_date: new Date().toLocaleDateString('en-CA'),
|
||||
interval_has_deadline: false,
|
||||
},
|
||||
})
|
||||
|
||||
await expect(stamp).not.toBeVisible({ timeout: 5000 })
|
||||
})
|
||||
|
||||
test('10.5 Editing task name only does NOT clear pending', async ({ page, request }) => {
|
||||
// Create pending again
|
||||
await request.post(`/api/child/${childId}/confirm-chore`, {
|
||||
data: { task_id: choreId },
|
||||
})
|
||||
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
const stamp = card.locator('.chore-stamp')
|
||||
await expect(stamp).toHaveText('PENDING')
|
||||
|
||||
// Edit name only (no points/type change) — should NOT clear pending
|
||||
await request.put(`/api/task/${choreId}/edit`, { data: { name: CHORE_NAME } })
|
||||
|
||||
// Wait briefly for SSE to propagate, then verify PENDING is still there
|
||||
await page.waitForTimeout(2000)
|
||||
await expect(stamp).toHaveText('PENDING')
|
||||
|
||||
// Clean up: cancel the pending confirmation for subsequent tests
|
||||
await request.post(`/api/child/${childId}/cancel-confirm-chore`, {
|
||||
data: { task_id: choreId },
|
||||
})
|
||||
})
|
||||
|
||||
test('10.4 Completed chores remain completed after point edit', async ({ page, request }) => {
|
||||
// Directly trigger-task (parent approval) → creates approved confirmation for scheduled chore
|
||||
await request.post(`/api/child/${childId}/trigger-task`, {
|
||||
data: { task_id: choreId },
|
||||
})
|
||||
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = choreSection(page).locator('.item-card').filter({ hasText: CHORE_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Verify COMPLETED is visible
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
|
||||
// Edit points — only status='pending' is cleared, not approved
|
||||
await request.put(`/api/task/${choreId}/edit`, { data: { points: CHORE_POINTS + 2 } })
|
||||
|
||||
// Wait for SSE, then verify COMPLETED stamp is still visible
|
||||
await page.waitForTimeout(2000)
|
||||
await expect(card.getByText('COMPLETED')).toBeVisible()
|
||||
})
|
||||
|
||||
test('10.3 Editing reward cost clears pending reward request', async ({ page, request }) => {
|
||||
await page.goto(`/parent/${childId}`)
|
||||
const card = rewardSection(page).locator('.item-card').filter({ hasText: REWARD_NAME })
|
||||
await card.waitFor({ state: 'visible' })
|
||||
|
||||
// Create pending reward request via API
|
||||
await request.post(`/api/child/${childId}/request-reward`, {
|
||||
data: { reward_id: rewardId },
|
||||
})
|
||||
|
||||
// Wait for SSE → PENDING on reward (use .pending class to avoid matching reward name)
|
||||
const pendingBadge = card.locator('.pending')
|
||||
await expect(pendingBadge).toBeVisible({ timeout: 5000 })
|
||||
|
||||
// Edit reward cost via API → clears pending
|
||||
await request.put(`/api/reward/${rewardId}/edit`, { data: { cost: REWARD_COST + 5 } })
|
||||
|
||||
// Wait for SSE — PENDING should disappear
|
||||
await expect(pendingBadge).not.toBeVisible({ timeout: 5000 })
|
||||
})
|
||||
})
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,165 @@
|
||||
// spec: e2e/plans/bugs-1.0.6-set01.plan.md §6
|
||||
|
||||
import { test, expect, type APIRequestContext, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
const CHILD_NAME = 'ScrollEditChild'
|
||||
const CHORE_COUNT = 12
|
||||
const REWARD_COUNT = 6
|
||||
const CHORE_PREFIX = 'ScrollEditChore'
|
||||
const REWARD_PREFIX = 'ScrollEditReward'
|
||||
const NARROW_VIEWPORT = { width: 480, height: 800 }
|
||||
|
||||
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 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: 'scroll 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) {
|
||||
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('Scroll to edited task after save', () => {
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
let childId = ''
|
||||
const choreIds: string[] = []
|
||||
const rewardIds: string[] = []
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
childId = await createChild(request, CHILD_NAME)
|
||||
|
||||
for (let i = 1; i <= CHORE_COUNT; i++) {
|
||||
choreIds.push(await createTask(request, `${CHORE_PREFIX}${i}`, 5 + i))
|
||||
}
|
||||
for (let i = 1; i <= REWARD_COUNT; i++) {
|
||||
rewardIds.push(await createReward(request, `${REWARD_PREFIX}${i}`, 10 + i))
|
||||
}
|
||||
|
||||
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: rewardIds },
|
||||
})
|
||||
})
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
if (childId) await request.delete(`/api/child/${childId}`)
|
||||
for (const id of choreIds) await request.delete(`/api/task/${id}`)
|
||||
for (const id of rewardIds) await request.delete(`/api/reward/${id}`)
|
||||
})
|
||||
|
||||
test('Edited chore card scrolls into viewport after override save', async ({ page }) => {
|
||||
await page.setViewportSize(NARROW_VIEWPORT)
|
||||
await page.goto(`/parent/${childId}`)
|
||||
|
||||
// Target the last chore — it should be scrolled off-screen in a narrow viewport
|
||||
const targetName = `${CHORE_PREFIX}${CHORE_COUNT}`
|
||||
const targetCard = choreSection(page).locator('.item-card').filter({ hasText: targetName })
|
||||
await choreSection(page).locator('.item-card').first().waitFor({ state: 'visible' })
|
||||
|
||||
// Click the target chore to bring up the kebab menu (first click centers + shows menu)
|
||||
await targetCard.click()
|
||||
await expect(targetCard).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
|
||||
// Open the kebab menu → "Edit Points"
|
||||
await targetCard.getByRole('button', { name: 'Options' }).click()
|
||||
await page.getByText('Edit Points').click()
|
||||
|
||||
// Override modal should be visible with input
|
||||
const input = page.locator('#custom-value')
|
||||
await expect(input).toBeVisible()
|
||||
|
||||
// Set a new value and save
|
||||
await input.fill('99')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
|
||||
// After SSE override event → list refreshes → card scrolls into view
|
||||
// Use expect.poll to retry, allowing scroll animation to complete
|
||||
await expect(targetCard).toBeVisible({ timeout: 5000 })
|
||||
await expect.poll(() => isInViewport(targetCard), { timeout: 3000 }).toBe(true)
|
||||
})
|
||||
|
||||
test('Edited reward card scrolls into viewport after override save', async ({ page }) => {
|
||||
await page.setViewportSize(NARROW_VIEWPORT)
|
||||
await page.goto(`/parent/${childId}`)
|
||||
|
||||
// Target the last reward
|
||||
const targetName = `${REWARD_PREFIX}${REWARD_COUNT}`
|
||||
const targetCard = rewardSection(page).locator('.item-card').filter({ hasText: targetName })
|
||||
await rewardSection(page).locator('.item-card').first().waitFor({ state: 'visible' })
|
||||
|
||||
// Click the target reward to center it and show the edit button
|
||||
await targetCard.click()
|
||||
await expect(targetCard).toHaveClass(/item-ready/, { timeout: 3000 })
|
||||
|
||||
// Click the Edit button
|
||||
await targetCard.locator('.edit-button').click()
|
||||
|
||||
// Override modal should be visible
|
||||
const input = page.locator('#custom-value')
|
||||
await expect(input).toBeVisible()
|
||||
|
||||
// Set a new value and save
|
||||
await input.fill('77')
|
||||
await page.getByRole('button', { name: 'Save' }).click()
|
||||
|
||||
// After SSE override event → list refreshes → card scrolls into view
|
||||
// Use expect.poll to retry, allowing scroll animation to complete
|
||||
await expect(targetCard).toBeVisible({ timeout: 5000 })
|
||||
await expect.poll(() => isInViewport(targetCard), { timeout: 3000 }).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user