Replace the shared MOCK_* fixtures with factories

A frozen shared constant forces a test needing one different field to
either mutate shared state, leaking into every other test, or spread it
by hand. The make*(overrides) factories cover both cases and were already
doing the same job, so the constants were redundant.

MOCK_PARENT_A and MOCK_PARENT_B were distinct identities that partner
tests tell apart, so their uuid and name are now passed explicitly at
each call site rather than left to a factory default -- the values those
tests depend on stay visible where they are used.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
2026-09-15 07:47:34 +02:00
parent 46e89a4359
commit 5d9ac5024a
3 changed files with 14 additions and 22 deletions
+13 -10
View File
@@ -26,7 +26,7 @@ import type { useVacationDays } from '@/hooks/useVacationDays'
import type { useChildSettings } from '@/hooks/useChildSettings'
import type { useCalendarDays } from '@/hooks/useCalendarDays'
import type { useShowWeekNumbers } from '@/hooks/useCalendarPreferences'
import { MOCK_CHILD, MOCK_PARENT_A, MOCK_VACATION_DAYS, MOCK_WORKSPACE, makeParentalLeaveFetch } from './mockData'
import { makeChild, makePersonalData, makeVacationDays, makeWorkspace, makeParentalLeaveFetch } from './mockData'
import { makeWorkspaceOverview } from './analytics'
import { makeCalendarWindow } from './calendar'
@@ -37,18 +37,21 @@ import { makeCalendarWindow } from './calendar'
export function makeWorkspaceContextValue(
overrides: Partial<ReturnType<typeof useWorkspace>> = {},
): ReturnType<typeof useWorkspace> {
const workspace = makeWorkspace()
const child = makeChild()
const parent = makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })
return {
workspace: MOCK_WORKSPACE,
workspace,
isLoading: false,
error: null,
workspaceId: MOCK_WORKSPACE.id,
workspaceId: workspace.id,
setWorkspaceId: vi.fn(),
refetch: vi.fn(),
children: [{ id: MOCK_CHILD.id, name: MOCK_CHILD.name, birth_date: MOCK_CHILD.birthDate }],
selectedChildId: MOCK_CHILD.id,
children: [{ id: child.id, name: child.name, birth_date: child.birthDate }],
selectedChildId: child.id,
selectChild: vi.fn(),
personalDataUuid: MOCK_PARENT_A.uuid,
parentName: MOCK_PARENT_A.name,
personalDataUuid: parent.uuid,
parentName: parent.name,
refreshContext: vi.fn(),
...overrides,
}
@@ -132,7 +135,7 @@ export function makeWorkspaceMembersResult(
overrides: Partial<ReturnType<typeof useWorkspaceMembers>> = {},
): ReturnType<typeof useWorkspaceMembers> {
return {
data: [MOCK_PARENT_A],
data: [makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })],
isLoading: false,
error: null,
refresh: vi.fn(),
@@ -210,7 +213,7 @@ export function makeVacationDaysResult(
overrides: Partial<ReturnType<typeof useVacationDays>> = {},
): ReturnType<typeof useVacationDays> {
return {
data: [MOCK_VACATION_DAYS],
data: [makeVacationDays()],
isLoading: false,
error: null,
upsert: vi.fn(),
@@ -222,7 +225,7 @@ export function makeChildSettingsResult(
overrides: Partial<ReturnType<typeof useChildSettings>> = {},
): ReturnType<typeof useChildSettings> {
return {
data: MOCK_CHILD,
data: makeChild(),
isLoading: false,
error: null,
update: vi.fn(),