// spec: e2e/plans/create-child.plan.md

import { test, expect } from '@playwright/test'

test.describe('Create Child', () => {
  test('Cancel navigates back without saving', async ({ page }) => {
    // 1. Navigate to app root - router redirects to /parent (children list)
    await page.goto('/')
    await page.getByRole('button', { name: 'Add Child' }).click()
    await expect(page.getByRole('heading', { name: 'Create Child' })).toBeVisible()

    // 2. Fill in 'Frank' and '9', then click Cancel
    await page.getByLabel('Name').fill('Frank')
    await page.getByLabel('Age').fill('9')
    await page.getByRole('button', { name: 'Cancel' }).click()

    // expect: back on /parent and 'Frank' is NOT listed
    await expect(page).toHaveURL('/parent')
    await expect(page.getByText('Frank')).not.toBeVisible()
  })
})
