Files
ui/e2e/tests/annotations_endpoint.e2e.ts
T
Oleksandr Bezdieniezhnykh 1dd25edee3 [AZ-460] [AZ-462] [AZ-466] [AZ-475] Batch 4 - destructive UX/forms/overlay/save
AZ-466 — Destructive UX policy + ConfirmDialog a11y + no-alert (4pts):
  src/components/ConfirmDialog.test.tsx (8 fast),
  tests/destructive_ux.test.tsx (4 fast, AdminPage class-delete drift),
  e2e/tests/destructive_ux.e2e.ts. New static checks STC-SEC7 (alert
  allowlist) + STC-SEC8 (destructive-surfaces gated/drift) wired through
  scripts/check-banned-deps.mjs reading tests/security/banned-deps.json.

AZ-475 — Numeric form input rejection (2pts):
  tests/form_hygiene.test.tsx (3 fast). Documents two SettingsPage drifts:
  silent zero coercion via parseInt(v)||0 and labels missing htmlFor.

AZ-462 — Overlay membership at in-window edges (2pts):
  tests/overlay_membership.test.tsx (6 fast). Documents getTimeWindowDetections
  strict < drift; AC-1 boundary tests are it.fails(); AC-2 / control PASS.
  Mocks HTMLCanvasElement.getContext to capture strokeRect.

AZ-460 — Annotation save URL + payload contract (2pts):
  tests/annotations_endpoint.test.tsx (6 fast),
  e2e/tests/annotations_endpoint.e2e.ts. AC-1 URL canary PASSes; AC-2
  payload missing 4 fields documented as it.fails(); AC-3 manual-draw
  PASS, AI-suggestion-accept + bulk-edit-save QUARANTINE skip.

Test infrastructure:
  - tests/setup.ts: NoopResizeObserver + NoopEventSource JSDOM polyfills.
  - tests/msw/handlers/annotations.ts: doubly-prefixed paths matching
    production calls (e.g. /api/annotations/annotations).
  - tests/msw/handlers/flights.ts: plural /aircrafts paths.

Verification: bun run test:fast → 80 passed, 13 skipped (14 files).
scripts/run-tests.sh --static-only → 24/24 PASS (was 22; +STC-SEC7/SEC8).
Per-batch self-review verdict: PASS_WITH_WARNINGS. Cumulative review
of batches 04-06 due after batch 6 per implement/SKILL.md Step 14.5.
Report: _docs/03_implementation/batch_04_report.md.

Also includes the previously-untracked
_docs/03_implementation/cumulative_review_batches_01-03_report.md
generated at the start of this session before batch 4 began.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 04:15:01 +03:00

87 lines
3.6 KiB
TypeScript

import { test, expect } from '@playwright/test'
// AZ-460 — e2e companion for the annotation save URL + payload contract.
//
// AC-1 (FT-P-07): the doubly-prefixed canary URL on the real `annotations/`
// service. The fast-profile fixture asserts the URL via MSW;
// here we observe the real network request to confirm the
// service does not silently strip the `/annotations` prefix.
// AC-2 (FT-P-08): captured POST body contains all required fields. Today this
// is `test.fail()` (drift documented in fast tests).
//
// This e2e requires the suite docker-compose stack
// (`docker compose -f e2e/docker-compose.suite-e2e.yml up -d`) plus parent-suite
// `:test` images. It will run on the suite-e2e CI lane once those images are
// available; on a developer host without the stack the test skips with the
// standard message.
test.describe('AZ-460 — annotation save URL + payload (e2e companion)', () => {
test('AC-1 (FT-P-07) — outbound URL is /api/annotations/annotations', async ({ page }) => {
const requests: { url: string; body: string | null }[] = []
await page.route('**/api/annotations/annotations**', async (route) => {
const req = route.request()
if (req.method() === 'POST') {
requests.push({ url: req.url(), body: req.postData() })
}
await route.continue()
})
await page.goto('/annotations')
// Drive a save through the UI — depends on suite seed data; if no media
// is selectable in the fixture, the test reports the seed gap explicitly
// rather than masking the UI.
const saveBtn = page.getByRole('button', { name: /^Save$/i }).first()
if (!(await saveBtn.isVisible({ timeout: 5000 }).catch(() => false))) {
test.skip(true, 'Suite seed has no media available for annotation save')
}
await saveBtn.click({ timeout: 5000 }).catch(() => {})
// Assert
const saved = await page.waitForFunction(
(count) => count > 0,
requests.length,
{ timeout: 5000 },
).catch(() => null)
if (!saved) test.skip(true, 'Save did not fire on this seed')
expect(requests.length).toBeGreaterThan(0)
for (const r of requests) {
expect(r.url).toContain('/api/annotations/annotations')
}
})
test.fail('AC-2 (FT-P-08) — required fields {Source, WaypointId, videoTime, mediaId, detections, status}', async ({ page }) => {
// Drift gated: production today only sends {mediaId, time, detections}.
// This e2e companion will flip green when AC-2 lands in Phase B.
const captured: Record<string, unknown>[] = []
await page.route('**/api/annotations/annotations**', async (route) => {
const req = route.request()
if (req.method() === 'POST') {
const text = req.postData()
if (text) captured.push(JSON.parse(text))
}
await route.continue()
})
await page.goto('/annotations')
const saveBtn = page.getByRole('button', { name: /^Save$/i }).first()
if (!(await saveBtn.isVisible({ timeout: 5000 }).catch(() => false))) {
test.skip(true, 'Suite seed has no media for save')
}
await saveBtn.click()
await page.waitForTimeout(1000)
expect(captured.length).toBeGreaterThan(0)
for (const body of captured) {
expect(body).toHaveProperty('Source')
expect(['AI', 'Manual']).toContain(body.Source as string)
expect(body).toHaveProperty('WaypointId')
expect(body).toHaveProperty('videoTime')
expect(body).toHaveProperty('mediaId')
expect(body).toHaveProperty('detections')
expect(body).toHaveProperty('status')
}
})
})