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:
Vendored
+13
-10
@@ -26,7 +26,7 @@ import type { useVacationDays } from '@/hooks/useVacationDays'
|
|||||||
import type { useChildSettings } from '@/hooks/useChildSettings'
|
import type { useChildSettings } from '@/hooks/useChildSettings'
|
||||||
import type { useCalendarDays } from '@/hooks/useCalendarDays'
|
import type { useCalendarDays } from '@/hooks/useCalendarDays'
|
||||||
import type { useShowWeekNumbers } from '@/hooks/useCalendarPreferences'
|
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 { makeWorkspaceOverview } from './analytics'
|
||||||
import { makeCalendarWindow } from './calendar'
|
import { makeCalendarWindow } from './calendar'
|
||||||
|
|
||||||
@@ -37,18 +37,21 @@ import { makeCalendarWindow } from './calendar'
|
|||||||
export function makeWorkspaceContextValue(
|
export function makeWorkspaceContextValue(
|
||||||
overrides: Partial<ReturnType<typeof useWorkspace>> = {},
|
overrides: Partial<ReturnType<typeof useWorkspace>> = {},
|
||||||
): ReturnType<typeof useWorkspace> {
|
): ReturnType<typeof useWorkspace> {
|
||||||
|
const workspace = makeWorkspace()
|
||||||
|
const child = makeChild()
|
||||||
|
const parent = makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })
|
||||||
return {
|
return {
|
||||||
workspace: MOCK_WORKSPACE,
|
workspace,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
workspaceId: MOCK_WORKSPACE.id,
|
workspaceId: workspace.id,
|
||||||
setWorkspaceId: vi.fn(),
|
setWorkspaceId: vi.fn(),
|
||||||
refetch: vi.fn(),
|
refetch: vi.fn(),
|
||||||
children: [{ id: MOCK_CHILD.id, name: MOCK_CHILD.name, birth_date: MOCK_CHILD.birthDate }],
|
children: [{ id: child.id, name: child.name, birth_date: child.birthDate }],
|
||||||
selectedChildId: MOCK_CHILD.id,
|
selectedChildId: child.id,
|
||||||
selectChild: vi.fn(),
|
selectChild: vi.fn(),
|
||||||
personalDataUuid: MOCK_PARENT_A.uuid,
|
personalDataUuid: parent.uuid,
|
||||||
parentName: MOCK_PARENT_A.name,
|
parentName: parent.name,
|
||||||
refreshContext: vi.fn(),
|
refreshContext: vi.fn(),
|
||||||
...overrides,
|
...overrides,
|
||||||
}
|
}
|
||||||
@@ -132,7 +135,7 @@ export function makeWorkspaceMembersResult(
|
|||||||
overrides: Partial<ReturnType<typeof useWorkspaceMembers>> = {},
|
overrides: Partial<ReturnType<typeof useWorkspaceMembers>> = {},
|
||||||
): ReturnType<typeof useWorkspaceMembers> {
|
): ReturnType<typeof useWorkspaceMembers> {
|
||||||
return {
|
return {
|
||||||
data: [MOCK_PARENT_A],
|
data: [makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -210,7 +213,7 @@ export function makeVacationDaysResult(
|
|||||||
overrides: Partial<ReturnType<typeof useVacationDays>> = {},
|
overrides: Partial<ReturnType<typeof useVacationDays>> = {},
|
||||||
): ReturnType<typeof useVacationDays> {
|
): ReturnType<typeof useVacationDays> {
|
||||||
return {
|
return {
|
||||||
data: [MOCK_VACATION_DAYS],
|
data: [makeVacationDays()],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
upsert: vi.fn(),
|
upsert: vi.fn(),
|
||||||
@@ -222,7 +225,7 @@ export function makeChildSettingsResult(
|
|||||||
overrides: Partial<ReturnType<typeof useChildSettings>> = {},
|
overrides: Partial<ReturnType<typeof useChildSettings>> = {},
|
||||||
): ReturnType<typeof useChildSettings> {
|
): ReturnType<typeof useChildSettings> {
|
||||||
return {
|
return {
|
||||||
data: MOCK_CHILD,
|
data: makeChild(),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
update: vi.fn(),
|
update: vi.fn(),
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Barrel for all typed test fixtures. Import from here:
|
* Barrel for all typed test fixtures. Import from here:
|
||||||
*
|
*
|
||||||
* import { makeWorkspaceOverview, makePlanProposal, MOCK_WORKSPACE } from '../../tests/fixtures'
|
* import { makeWorkspaceOverview, makePlanProposal, makeWorkspace } from '../../tests/fixtures'
|
||||||
*
|
*
|
||||||
* See the sibling files for what each group covers:
|
* See the sibling files for what each group covers:
|
||||||
* - mockData.ts domain entities (Workspace, PersonalData, Child, VacationDays,
|
* - mockData.ts domain entities (Workspace, PersonalData, Child, VacationDays,
|
||||||
|
|||||||
Vendored
-11
@@ -36,8 +36,6 @@ export function makeWorkspace(overrides: Partial<Workspace> = {}): Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MOCK_WORKSPACE: Workspace = makeWorkspace()
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Personal data (parents)
|
// Personal data (parents)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -54,9 +52,6 @@ export function makePersonalData(overrides: Partial<PersonalData> = {}): Persona
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MOCK_PARENT_A: PersonalData = makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })
|
|
||||||
export const MOCK_PARENT_B: PersonalData = makePersonalData({ uuid: 'pd-b', name: 'Förälder B' })
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Child
|
// Child
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -74,8 +69,6 @@ export function makeChild(overrides: Partial<Child> = {}): Child {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MOCK_CHILD: Child = makeChild()
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Vacation days
|
// Vacation days
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -94,8 +87,6 @@ export function makeVacationDays(overrides: Partial<VacationDays> = {}): Vacatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MOCK_VACATION_DAYS: VacationDays = makeVacationDays()
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Parental leave fetch (+ tier data)
|
// Parental leave fetch (+ tier data)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -134,8 +125,6 @@ export function makeParentalLeaveFetch(overrides: Partial<ParentalLeaveFetch> =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MOCK_PARENTAL_LEAVE: ParentalLeaveFetch = makeParentalLeaveFetch()
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Leave wishes
|
// Leave wishes
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user