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>
117 lines
3.0 KiB
TypeScript
117 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { findConflicts, wouldConflict } from '@/lib/timetable/conflict'
|
|
import { ArtistEngagementStatus, type Performance } from '@/types/timetable'
|
|
|
|
function p(overrides: Partial<Performance> = {}): Performance {
|
|
return {
|
|
id: 'p1',
|
|
engagement_id: 'e1',
|
|
event_id: 'ev1',
|
|
stage_id: 's1',
|
|
lane: 0,
|
|
lane_resolved: 0,
|
|
start_at: '2026-07-10T18:00:00.000Z',
|
|
end_at: '2026-07-10T19:00:00.000Z',
|
|
version: 0,
|
|
notes: null,
|
|
warnings: [],
|
|
created_at: null,
|
|
updated_at: null,
|
|
deleted_at: null,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('findConflicts', () => {
|
|
it('flags two overlapping performances on the same lane', () => {
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a', start_at: '2026-07-10T18:00:00Z', end_at: '2026-07-10T19:00:00Z' }),
|
|
p({ id: 'b', start_at: '2026-07-10T18:30:00Z', end_at: '2026-07-10T19:30:00Z' }),
|
|
])
|
|
|
|
expect(conflicts).toEqual(new Set(['a', 'b']))
|
|
})
|
|
|
|
it('endpoint-touching is NOT overlap', () => {
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a', start_at: '2026-07-10T18:00:00Z', end_at: '2026-07-10T19:00:00Z' }),
|
|
p({ id: 'b', start_at: '2026-07-10T19:00:00Z', end_at: '2026-07-10T20:00:00Z' }),
|
|
])
|
|
|
|
expect(conflicts.size).toBe(0)
|
|
})
|
|
|
|
it('different lanes on same stage = no conflict', () => {
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a', lane_resolved: 0 }),
|
|
p({ id: 'b', lane_resolved: 1 }),
|
|
])
|
|
|
|
expect(conflicts.size).toBe(0)
|
|
})
|
|
|
|
it('different stages = no conflict', () => {
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a', stage_id: 's1' }),
|
|
p({ id: 'b', stage_id: 's2' }),
|
|
])
|
|
|
|
expect(conflicts.size).toBe(0)
|
|
})
|
|
|
|
it('cancelled performances do not participate', () => {
|
|
const cancelled = p({
|
|
id: 'c',
|
|
engagement: {
|
|
booking_status: { value: ArtistEngagementStatus.CANCELLED, label: 'Geannuleerd' },
|
|
} as Performance['engagement'],
|
|
})
|
|
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a' }),
|
|
cancelled,
|
|
])
|
|
|
|
expect(conflicts.size).toBe(0)
|
|
})
|
|
|
|
it('parked performances (stage_id null) do not participate', () => {
|
|
const conflicts = findConflicts([
|
|
p({ id: 'a', stage_id: null }),
|
|
p({ id: 'b' }),
|
|
])
|
|
|
|
expect(conflicts.size).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe('wouldConflict', () => {
|
|
it('detects 1-pixel overlap', () => {
|
|
const others = [p({ id: 'x', start_at: '2026-07-10T18:00:00Z', end_at: '2026-07-10T19:00:00Z' })]
|
|
|
|
const result = wouldConflict({
|
|
id: 'new',
|
|
stage_id: 's1',
|
|
lane: 0,
|
|
start_at: '2026-07-10T18:59:00Z',
|
|
end_at: '2026-07-10T20:00:00Z',
|
|
}, others)
|
|
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it('returns false when candidate is parked', () => {
|
|
const others = [p({ id: 'x' })]
|
|
|
|
const result = wouldConflict({
|
|
id: 'new',
|
|
stage_id: null,
|
|
lane: 0,
|
|
start_at: '2026-07-10T18:00:00Z',
|
|
end_at: '2026-07-10T19:00:00Z',
|
|
}, others)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
})
|