import { createPinia, setActivePinia } from 'pinia' import { beforeEach, describe, expect, it } from 'vitest' import { useTimetableStore } from '@/stores/useTimetableStore' import { ArtistEngagementStatus, type Performance } from '@/types/timetable' function p(): 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: 1, notes: null, warnings: [], created_at: null, updated_at: null, deleted_at: null, } } describe('useTimetableStore', () => { beforeEach(() => setActivePinia(createPinia())) it('initialises with cancelled OFF in status filter', () => { const store = useTimetableStore() expect(store.isStatusVisible(ArtistEngagementStatus.CONFIRMED)).toBe(true) expect(store.isStatusVisible(ArtistEngagementStatus.CANCELLED)).toBe(false) }) it('toggleStatus flips a single status', () => { const store = useTimetableStore() store.toggleStatus(ArtistEngagementStatus.CONFIRMED) expect(store.isStatusVisible(ArtistEngagementStatus.CONFIRMED)).toBe(false) store.toggleStatus(ArtistEngagementStatus.CONFIRMED) expect(store.isStatusVisible(ArtistEngagementStatus.CONFIRMED)).toBe(true) }) it('selectPerformance maps to id and clears on null', () => { // activeDayId / setActiveDay intentionally REMOVED from the store // (Step 5: ?day URL is the source of truth, page derives via computed). const store = useTimetableStore() expect((store as unknown as { activeDayId?: string }).activeDayId).toBeUndefined() expect((store as unknown as { setActiveDay?: unknown }).setActiveDay).toBeUndefined() store.selectPerformance('p1') expect(store.selectedPerformanceId).toBe('p1') store.selectPerformance(null) expect(store.selectedPerformanceId).toBeNull() }) it('startDrag/endDrag manages snapshot + ghost', () => { const store = useTimetableStore() expect(store.isDragging).toBe(false) store.startDrag(p()) expect(store.isDragging).toBe(true) expect(store.dragOriginSnapshot?.id).toBe('p1') store.updateDragGhost({ stageId: 's1', startAt: '2026-07-10T18:30:00Z', endAt: '2026-07-10T19:30:00Z', lane: 1 }) expect(store.dragGhost?.lane).toBe(1) store.endDrag() expect(store.isDragging).toBe(false) expect(store.dragGhost).toBeNull() }) it('isStatusVisible handles null gracefully', () => { const store = useTimetableStore() expect(store.isStatusVisible(null)).toBe(false) expect(store.isStatusVisible(undefined)).toBe(false) }) })