014503e89b
The planner knew exactly how many semesterdagar a parent was about to forfeit and never placed a single day to prevent it. It also had no weekend-wrap logic at all: REASON_VACATION_WRAP_WEEKEND was stamped on every tier-3 interior vacation day, including a lone Tuesday in February. Two changes. Spend better. A workday adjacent to a free stretch, or in the middle of a gap of three or fewer fenced by free days, now takes vacation -- _vacation_bridge_reason, consulted for every parent type. This departs from spec 6.1's "wrapping suppressed for hourly": the FP-preservation argument is salary-type independent, only the pay argument was hourly-moot. In a both-parents window, both now take vacation on such a date rather than one paying with FP. After funding, reallocate_vacation_by_value swaps vacation onto higher-ranked dates 1-for-1 with FP days, so which dates hold vacation improves while how many never drops -- greedy first, re-timed after, never withheld. An invariant test asserts the count can only rise. Name the losses. A new pass proposes concrete dates for vacation that would otherwise expire, current year only, ranked red-day bridge then weekend bridge then interior, later dates first. They ride on PlanProposal.rescue_days, kept off `days` so nothing downstream commits them, and surface on the Dashboard with accept-one, accept-all (one batched /api/plan/apply, not N) and dismiss. Dismissal reuses the tip_dismissal table, keyed on (parent, year) identity rather than the group's dates -- those are recomputed from the whole plan's residual on every propose, so date-hashing made dismissal self-defeating. Dismiss does not bump the plan version; it changes no data and must not trigger a write. Measured on the seeded demo: 12 forfeiting days for one parent now yield 12 proposed dates, all Fridays or Mondays. Total vacation placed is unchanged at 203 days, confirming the reallocation only re-times. Three defects here were found by driving a browser, while 2273 unit tests passed -- all three lived in the seam between layers that unit tests mock away. Adds API-level tests over the real request sequence. Rate limiting is now off in tests (one file consumed the whole registration budget) with the suite's first real 429 assertion. PROPOSE_VS_SYNC_BUG.md documents a pre-existing, unfixed issue found along the way: Dashboard figures swing on the first sync with no user action. Backend 946 tests, frontend 1341, coverage above all gates. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZaX6xbuMEMXuyKA1fq2Mm
336 lines
9.3 KiB
TypeScript
336 lines
9.3 KiB
TypeScript
/**
|
|
* Shared test fixtures — return values of `src/context/*` and `src/hooks/*`.
|
|
*
|
|
* None of these hooks export their result interface (e.g. `useAnalytics`'s
|
|
* `UseAnalyticsResult` is private to useAnalytics.ts), and this file
|
|
* deliberately does not add exports to make that possible — `ReturnType<typeof
|
|
* theHook>` gets the same fully-typed result without touching source files.
|
|
* `import type` erases at compile time, so this doesn't pull the hooks'
|
|
* runtime code (or React) into the test bundle.
|
|
*/
|
|
|
|
import { vi } from 'vitest'
|
|
import type { useWorkspace } from '@/context/WorkspaceContext'
|
|
import type { useAuth } from '@/context/AuthContext'
|
|
import type { usePlanSyncContext } from '@/context/PlanSyncProvider'
|
|
import type { useAnalytics } from '@/hooks/useAnalytics'
|
|
import type { useParentalLeave } from '@/hooks/useParentalLeave'
|
|
import type { usePlannedDays } from '@/hooks/usePlannedDays'
|
|
import type { useScraperFetch } from '@/hooks/useScraperFetch'
|
|
import type { useWorkspaceMembers } from '@/hooks/useWorkspaceMembers'
|
|
import type { useOptimizationTips } from '@/hooks/useOptimizationTips'
|
|
import type { usePlannedDayExclusions } from '@/hooks/usePlannedDayExclusions'
|
|
import type { useDayOverrides } from '@/hooks/useDayOverrides'
|
|
import type { useLeaveWishes } from '@/hooks/useLeaveWishes'
|
|
import type { usePlanProposal } from '@/hooks/usePlanProposal'
|
|
import type { usePlanSync } from '@/hooks/usePlanSync'
|
|
import type { useVacationDays } from '@/hooks/useVacationDays'
|
|
import type { useChildSettings } from '@/hooks/useChildSettings'
|
|
import type { useCalendarDays } from '@/hooks/useCalendarDays'
|
|
import type { usePreschoolPlanningDays } from '@/hooks/usePreschoolPlanningDays'
|
|
import type { usePreschoolPlanningDaysList } from '@/hooks/usePreschoolPlanningDaysList'
|
|
import type { useRescueDayActions } from '@/hooks/useRescueDayActions'
|
|
import type { useShowWeekNumbers } from '@/hooks/useCalendarPreferences'
|
|
import { makeChild, makePersonalData, makeVacationDays, makeWorkspace, makeParentalLeaveFetch } from './mockData'
|
|
import { makeWorkspaceOverview } from './analytics'
|
|
import { makeCalendarWindow } from './calendar'
|
|
import { makePreschoolPlanningDays } from './workspace'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Contexts
|
|
// ---------------------------------------------------------------------------
|
|
|
|
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,
|
|
isLoading: false,
|
|
error: null,
|
|
workspaceId: workspace.id,
|
|
setWorkspaceId: vi.fn(),
|
|
refetch: vi.fn(),
|
|
children: [{ id: child.id, name: child.name, birth_date: child.birthDate }],
|
|
selectedChildId: child.id,
|
|
selectChild: vi.fn(),
|
|
personalDataUuid: parent.uuid,
|
|
parentName: parent.name,
|
|
refreshContext: vi.fn(),
|
|
planVersion: 0,
|
|
bumpPlanVersion: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanSyncContextValue(
|
|
overrides: Partial<ReturnType<typeof usePlanSyncContext>> = {},
|
|
): ReturnType<typeof usePlanSyncContext> {
|
|
return {
|
|
pendingEvictionPreview: null,
|
|
clearPendingEvictionPreview: vi.fn(),
|
|
latestProposal: null,
|
|
latestProposalVersion: 0,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeAuthContextValue(
|
|
overrides: Partial<ReturnType<typeof useAuth>> = {},
|
|
): ReturnType<typeof useAuth> {
|
|
return {
|
|
accessToken: 'token-123',
|
|
isAuthenticated: true,
|
|
isLoading: false,
|
|
login: vi.fn(),
|
|
register: vi.fn(),
|
|
logout: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Data-fetching hooks
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeAnalyticsResult(
|
|
overrides: Partial<ReturnType<typeof useAnalytics>> = {},
|
|
): ReturnType<typeof useAnalytics> {
|
|
return {
|
|
data: makeWorkspaceOverview(),
|
|
isLoading: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeParentalLeaveResult(
|
|
overrides: Partial<ReturnType<typeof useParentalLeave>> = {},
|
|
): ReturnType<typeof useParentalLeave> {
|
|
return {
|
|
data: makeParentalLeaveFetch(),
|
|
isLoading: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlannedDaysResult(
|
|
overrides: Partial<ReturnType<typeof usePlannedDays>> = {},
|
|
): ReturnType<typeof usePlannedDays> {
|
|
return {
|
|
data: [],
|
|
isLoading: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
add: vi.fn(),
|
|
update: vi.fn(),
|
|
remove: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeScraperFetchResult(
|
|
overrides: Partial<ReturnType<typeof useScraperFetch>> = {},
|
|
): ReturnType<typeof useScraperFetch> {
|
|
return {
|
|
sessionId: null,
|
|
pollData: null,
|
|
resolvedIds: null,
|
|
error: null,
|
|
isUnauthorized: false,
|
|
start: vi.fn(),
|
|
cancel: vi.fn(),
|
|
isRunning: false,
|
|
isTerminal: false,
|
|
partnerDeduction: null,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeWorkspaceMembersResult(
|
|
overrides: Partial<ReturnType<typeof useWorkspaceMembers>> = {},
|
|
): ReturnType<typeof useWorkspaceMembers> {
|
|
return {
|
|
data: [makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })],
|
|
isLoading: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeOptimizationTipsResult(
|
|
overrides: Partial<ReturnType<typeof useOptimizationTips>> = {},
|
|
): ReturnType<typeof useOptimizationTips> {
|
|
return {
|
|
data: [],
|
|
isLoading: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
dismiss: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeDayOverridesResult(
|
|
overrides: Partial<ReturnType<typeof useDayOverrides>> = {},
|
|
): ReturnType<typeof useDayOverrides> {
|
|
return {
|
|
data: [],
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
upsert: vi.fn(),
|
|
remove: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlannedDayExclusionsResult(
|
|
overrides: Partial<ReturnType<typeof usePlannedDayExclusions>> = {},
|
|
): ReturnType<typeof usePlannedDayExclusions> {
|
|
return {
|
|
data: [],
|
|
isLoading: false,
|
|
error: null,
|
|
exclude: vi.fn(),
|
|
restore: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeLeaveWishesResult(
|
|
overrides: Partial<ReturnType<typeof useLeaveWishes>> = {},
|
|
): ReturnType<typeof useLeaveWishes> {
|
|
return {
|
|
data: [],
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
add: vi.fn(),
|
|
update: vi.fn(),
|
|
remove: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanProposalResult(
|
|
overrides: Partial<ReturnType<typeof usePlanProposal>> = {},
|
|
): ReturnType<typeof usePlanProposal> {
|
|
return {
|
|
data: null,
|
|
isLoading: false,
|
|
error: null,
|
|
propose: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanSyncResult(
|
|
overrides: Partial<ReturnType<typeof usePlanSync>> = {},
|
|
): ReturnType<typeof usePlanSync> {
|
|
return {
|
|
isSyncing: false,
|
|
error: null,
|
|
lastChanges: null,
|
|
sync: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeVacationDaysResult(
|
|
overrides: Partial<ReturnType<typeof useVacationDays>> = {},
|
|
): ReturnType<typeof useVacationDays> {
|
|
return {
|
|
data: [makeVacationDays()],
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
upsert: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeChildSettingsResult(
|
|
overrides: Partial<ReturnType<typeof useChildSettings>> = {},
|
|
): ReturnType<typeof useChildSettings> {
|
|
return {
|
|
data: makeChild(),
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
update: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeCalendarDaysResult(
|
|
overrides: Partial<ReturnType<typeof useCalendarDays>> = {},
|
|
): ReturnType<typeof useCalendarDays> {
|
|
return {
|
|
data: makeCalendarWindow(),
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
refetch: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePreschoolPlanningDaysResult(
|
|
overrides: Partial<ReturnType<typeof usePreschoolPlanningDays>> = {},
|
|
): ReturnType<typeof usePreschoolPlanningDays> {
|
|
return {
|
|
data: makePreschoolPlanningDays(),
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
setPlanned: vi.fn(),
|
|
recordTaken: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeRescueDayActionsResult(
|
|
overrides: Partial<ReturnType<typeof useRescueDayActions>> = {},
|
|
): ReturnType<typeof useRescueDayActions> {
|
|
return {
|
|
isLoading: false,
|
|
error: null,
|
|
acceptDay: vi.fn(),
|
|
acceptAll: vi.fn(),
|
|
dismiss: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePreschoolPlanningDaysListResult(
|
|
overrides: Partial<ReturnType<typeof usePreschoolPlanningDaysList>> = {},
|
|
): ReturnType<typeof usePreschoolPlanningDaysList> {
|
|
return {
|
|
data: [makePreschoolPlanningDays()],
|
|
isLoading: false,
|
|
isRefreshing: false,
|
|
error: null,
|
|
refresh: vi.fn(),
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Local-storage-backed preference hook (a tuple, not an object)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeShowWeekNumbersTuple(
|
|
show = false,
|
|
setShow: (show: boolean) => void = vi.fn(),
|
|
): ReturnType<typeof useShowWeekNumbers> {
|
|
return [show, setShow]
|
|
}
|