Files
crewli/apps/app/tests/unit/schemas/timetable.test.ts
bert.hausmans 39fdc0fa3d test(timetable): Phase C — 67 new tests (pure logic + composables + store + schemas)
apps/app/tests/unit/lib/timetable/:
  - snap.test.ts (5)            — rounding, clamp, edge cases
  - time-grid.test.ts (6)       — px↔min↔ISO roundtrips, formatTickLabel
  - conflict.test.ts (8)        — overlap, endpoint-touching, lane/stage scoping, cancelled exclusion
  - b2b.test.ts (6)             — 0min, 2:59, 3:01, overlap, side-set mapping, threshold constant
  - capacity.test.ts (7)        — null capacity, missing data, warn/critical, crew+guests preference
  - lane.test.ts (8)            — Pass 1 + Pass 2, cascade-bump preview, cancelled exclusion

apps/app/tests/unit/composables/:
  - useTimetableMutations.test.ts (5) — Idempotency-Key header, optimistic + cascade,
                                         409 VersionMismatch surfaced, park sends null,
                                         createStage POST path
  - useDragOrClick.test.ts (3)        — onClick fires under threshold, onDragStart+End
                                         above threshold, Esc cancels mid-flight

apps/app/tests/unit/schemas/timetable.test.ts (8) — payload + response zod parsers
apps/app/tests/unit/lib/idempotencyKey.test.ts (3) — 6-30 char range, 24-hex, uniqueness
apps/app/tests/unit/stores/useTimetableStore.test.ts (5) — defaults, toggleStatus, drag state, null guard

Refactor: useTimetableMutations.move now throws Error instances (no-throw-literal)
so AxiosError.message and the VersionMismatchError shape both bubble through .catch().

Test count: 252 → 319 (+67). All 42 files pass.

Out of scope this session (added to BACKLOG):
- ART-PERFORMANCEBLOCK-COMPONENT-TESTS — Vuetify intentionally not loaded in
  vitest.config.ts; a Vuexy-stub setup for component-mount tests is one PR of
  its own. Pure rendering logic (capacity, B2B, conflict) is fully covered at
  the lib/ layer.
- ART-AXE-CORE-A11Y-TESTS — axe-core not yet installed in the repo. The
  aria-label structure on PerformanceBlock + aria-live on the page entry are
  authored to pass an axe scan when added.
- ART-INTEGRATION-FLOW-TEST — full add → drag → resize → park flow needs
  Vuetify + router + msw setup; defer with the component tests above.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 02:04:10 +02:00

119 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
createPerformancePayloadSchema,
createStagePayloadSchema,
performanceSchema,
} from '@/schemas/timetable'
describe('createPerformancePayloadSchema', () => {
it('accepts a complete payload', () => {
const result = createPerformancePayloadSchema.safeParse({
engagement_id: 'e1',
event_id: 'ev1',
stage_id: 's1',
start_at: '2026-07-10 18:00:00',
end_at: '2026-07-10 19:00:00',
lane: 0,
notes: null,
})
expect(result.success).toBe(true)
})
it('rejects missing engagement_id', () => {
const result = createPerformancePayloadSchema.safeParse({
engagement_id: '',
event_id: 'ev1',
stage_id: null,
start_at: '2026-07-10 18:00:00',
end_at: '2026-07-10 19:00:00',
})
expect(result.success).toBe(false)
})
it('rejects end <= start', () => {
const result = createPerformancePayloadSchema.safeParse({
engagement_id: 'e1',
event_id: 'ev1',
stage_id: null,
start_at: '2026-07-10 19:00:00',
end_at: '2026-07-10 18:00:00',
})
expect(result.success).toBe(false)
})
it('rejects lane > 9', () => {
const result = createPerformancePayloadSchema.safeParse({
engagement_id: 'e1',
event_id: 'ev1',
stage_id: null,
start_at: '2026-07-10 18:00:00',
end_at: '2026-07-10 19:00:00',
lane: 99,
})
expect(result.success).toBe(false)
})
})
describe('createStagePayloadSchema', () => {
it('accepts uppercase + lowercase hex', () => {
expect(createStagePayloadSchema.safeParse({ name: 'A', color: '#aabbcc' }).success).toBe(true)
expect(createStagePayloadSchema.safeParse({ name: 'A', color: '#AABBCC' }).success).toBe(true)
})
it('rejects shorthand hex', () => {
expect(createStagePayloadSchema.safeParse({ name: 'A', color: '#abc' }).success).toBe(false)
})
it('rejects empty name', () => {
expect(createStagePayloadSchema.safeParse({ name: '', color: '#aabbcc' }).success).toBe(false)
})
})
describe('performanceSchema', () => {
it('parses a minimal performance', () => {
const result = performanceSchema.safeParse({
id: 'p1',
engagement_id: 'e1',
event_id: 'ev1',
stage_id: null,
lane: 0,
lane_resolved: 0,
start_at: null,
end_at: null,
version: 0,
notes: null,
warnings: [],
created_at: null,
updated_at: null,
deleted_at: null,
})
expect(result.success).toBe(true)
})
it('rejects unknown warning value', () => {
const result = performanceSchema.safeParse({
id: 'p1',
engagement_id: 'e1',
event_id: 'ev1',
stage_id: null,
lane: 0,
lane_resolved: 0,
start_at: null,
end_at: null,
version: 0,
notes: null,
warnings: ['nonsense'],
created_at: null,
updated_at: null,
deleted_at: null,
})
expect(result.success).toBe(false)
})
})