Complete NextSteps roadmap: planning engine UI, calendar cluster, flexible wishes

Works through every numbered item in NextSteps260913.md section 3, plus the
three known verification issues in section 4.1.

Surface what the backend already computed:
- 3.1 render surplus_advice in PlanResults, mirroring the shortfall remedies
- 3.2 surface VacationBalance.is_assumed so assumed statutory years are visible
- 3.3 age-4 expiry given the proposed plan, via a new Age4Projection reusing
  the existing _age4_projections arithmetic (Dashboard stat verified, not rebuilt)

Calendar cluster (one pass over the holiday data):
- new GET /api/calendar/days exposing roda dagar, klamdagar and day overrides,
  paginated four years at a time
- 3.4 shade roda dagar/klamdagar, with R/K badges so colour is not the only signal
- 3.6 click-to-override behind an explicit mode toggle, leaving drag multi-select intact
- 3.7 click month/year to advance
- 3.8 per-year red-days list in Settings, statutory days plus overrides

i18n:
- 3.5 five backend-generated Swedish surfaces converted to message_key + data,
  following the tips_service pattern; old string fields replaced, not kept

Flexible wishes (3.9):
- PLANNING_ENGINE_SPEC section 10: window_mode, candidate search, cost function,
  deterministic tie-break, two-pass ordering, test matrix rows 15-24
- backend: entity, migration 006, _FULL_SCHEMA sync, repository, allocator
- frontend: season-preset toggle in WishEditor, unplaced outcome rendering

Fixes (4.1):
- pin typecheck to the local tsc rather than npx resolving a newer TypeScript
- ignore generated coverage/ and dist/ in the ESLint flat config
- fix the flaky usePlanApply test properly, with waitFor rather than a retry

Tests: backend 361 -> 404, frontend 540 -> 704. Coverage 89.47% -> 96.52% lines.

Not yet verified in a browser.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
2026-09-14 02:33:03 +02:00
parent 3ca1418d94
commit 76b1e712b9
218 changed files with 29867 additions and 6085 deletions
+56
View File
@@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest'
import { LEAVE_RULES } from './constants'
describe('LEAVE_RULES constants', () => {
it('should have correct total föräldrapenning days', () => {
expect(LEAVE_RULES.totalDaysPerChild).toBe(480)
})
it('should have correct tier breakdown', () => {
expect(LEAVE_RULES.sjukpenningDays).toBe(390)
expect(LEAVE_RULES.lagstaNivaDays).toBe(90)
})
it('should have tier days sum to total', () => {
const tierTotal = LEAVE_RULES.sjukpenningDays + LEAVE_RULES.lagstaNivaDays
expect(tierTotal).toBe(LEAVE_RULES.totalDaysPerChild)
})
it('should have correct default per-parent split', () => {
expect(LEAVE_RULES.daysPerParent).toBe(240)
})
it('should have correct reserved days per parent', () => {
expect(LEAVE_RULES.reservedDaysPerParent).toBe(90)
})
it('should derive transferable days correctly', () => {
expect(LEAVE_RULES.transferableDaysPerParent).toBe(150)
expect(LEAVE_RULES.transferableDaysPerParent).toBe(
LEAVE_RULES.daysPerParent - LEAVE_RULES.reservedDaysPerParent
)
})
it('should have correct dubbeldagar limits', () => {
expect(LEAVE_RULES.maxDubbeldagar).toBe(60)
expect(LEAVE_RULES.dubbeldagarMonthsLimit).toBe(15)
})
it('should have correct age-4 restrictions', () => {
expect(LEAVE_RULES.maxSavableDaysAtAge4).toBe(96)
expect(LEAVE_RULES.hardExpiryAgeYears).toBe(12)
})
it('should have correct SGI protection rules', () => {
expect(LEAVE_RULES.sgiProtectedFirstMonths).toBe(12)
expect(LEAVE_RULES.sgiMinDaysPerWeekAfterAge1).toBe(5)
})
it('should have correct preschool planning days default', () => {
expect(LEAVE_RULES.preschoolPlanningDaysPerYear).toBe(6)
})
it('should have correct vacation days per year', () => {
expect(LEAVE_RULES.vacationDaysPerYear).toBe(25)
})
})
+48
View File
@@ -0,0 +1,48 @@
/**
* Swedish parental leave rule constants.
*
* These values mirror backend/app/config.py::LeaveRules and must be kept in sync.
* They are the authoritative source for the domain rules governing föräldrapenning,
* dubbeldagar, age-4 restrictions, and SGI protection.
*
* NOTE: These figures are common-case defaults. Children born before 2014, multiples
* (tvillingtillägg), and single-custody arrangements differ and should become
* configurable when tackled. Update both frontend and backend together.
*
* @see backend/app/config.py#LeaveRules
* @see ARCHITECTURE.md#1
*/
export const LEAVE_RULES = {
// Total föräldrapenning entitlement and tier breakdown
totalDaysPerChild: 480,
sjukpenningDays: 390, // income-based tier
lagstaNivaDays: 90, // flat low-rate tier
// Default joint-custody split (per parent)
daysPerParent: 240,
reservedDaysPerParent: 90, // non-transferable ("reserverade dagar")
// Derived: transferable days per parent (240 - 90)
get transferableDaysPerParent(): number {
return this.daysPerParent - this.reservedDaysPerParent;
},
// Dubbeldagar: both parents taking leave for the same child on the same day
maxDubbeldagar: 60,
dubbeldagarMonthsLimit: 15, // only within the child's first 15 months
// Age-4 rule: max 96 days may be saved after the child's 4th birthday
maxSavableDaysAtAge4: 96,
hardExpiryAgeYears: 12,
// SGI protection and minimum work intensity
sgiProtectedFirstMonths: 12, // protected regardless of days taken
sgiMinDaysPerWeekAfterAge1: 5, // minimum to maintain SGI after age 1
// Default reserve for preschool planning days ("studiedagar") closures
preschoolPlanningDaysPerYear: 6,
// Statutory Swedish vacation days
vacationDaysPerYear: 25,
} as const;
+27
View File
@@ -78,6 +78,33 @@ export function getISOWeekNumber(date: Date): number {
return weekNum
}
/** Swedish weekday names as they appear in the `holidays` library's combined
* form (see backend `app/utils/holidays.py` §4.2/§13.3 caveat), e.g.
* `"Påskdagen; Söndag"`. */
const WEEKDAY_NAME_SEGMENTS = new Set([
'Söndag',
'Lördag',
'Fredag',
'Torsdag',
'Onsdag',
'Tisdag',
'Måndag',
])
/**
* Sensible display form for a calendar-day holiday name. The `holidays`
* library sometimes combines a holiday name with the weekday it falls on
* (e.g. `"Påskdagen; Söndag"`) — the weekday is redundant once the name is
* shown inside a calendar cell that already sits on that weekday, so this
* strips known weekday segments rather than dumping the raw combined string.
*/
export function formatHolidayName(rawName: string): string {
if (!rawName.includes(';')) return rawName
const parts = rawName.split(';').map((p) => p.trim())
const kept = parts.filter((p) => !WEEKDAY_NAME_SEGMENTS.has(p))
return kept.length > 0 ? kept.join(', ') : (parts[0] ?? rawName)
}
/**
* Get all dates in a range (inclusive, ascending order, order-independent).
* Dates should be ISO strings (YYYY-MM-DD).
+41
View File
@@ -0,0 +1,41 @@
import { describe, it, expect } from 'vitest'
import { getColorForType, getLabelForType } from './leaveTypes'
import { translate } from '@/i18n'
describe('getColorForType', () => {
it('returns the vacation color', () => {
expect(getColorForType('vacation')).toBe('#4CAF50')
})
it('returns the sjukpenning color', () => {
expect(getColorForType('sjukpenning')).toBe('#FF9800')
})
it('returns the lagsta color', () => {
expect(getColorForType('lagsta')).toBe('#2196F3')
})
it('falls back to grey for an unknown type', () => {
expect(getColorForType('something-else')).toBe('#9E9E9E')
})
})
describe('getLabelForType', () => {
const t = (key: Parameters<typeof translate>[1]) => translate('sv', key)
it('translates the vacation label', () => {
expect(getLabelForType('vacation', t)).toBe('Semester')
})
it('translates the sjukpenning label', () => {
expect(getLabelForType('sjukpenning', t)).toBe('Sjukpenningnivå')
})
it('translates the lagsta label', () => {
expect(getLabelForType('lagsta', t)).toBe('Lägstanivå')
})
it('falls back to the "unknown" label for an unrecognized type', () => {
expect(getLabelForType('something-else', t)).toBe('Okänd')
})
})
+14 -6
View File
@@ -1,3 +1,5 @@
import type { TranslationKey } from '@/i18n'
export function getColorForType(type: string): string {
const colorMap: Record<string, string> = {
vacation: '#4CAF50',
@@ -7,11 +9,17 @@ export function getColorForType(type: string): string {
return colorMap[type] ?? '#9E9E9E'
}
export function getLabelForType(type: string): string {
const labelMap: Record<string, string> = {
vacation: 'Vacation',
sjukpenning: 'Sick Leave',
lagsta: 'Parental',
/**
* Localized label for a leave-day type. Takes `t` rather than importing
* `useTranslation` itself — this is a plain utility function (not a
* component/hook), called from render bodies that already have `t` in scope.
*/
export function getLabelForType(type: string, t: (key: TranslationKey) => string): string {
const labelKeyMap: Record<string, TranslationKey> = {
vacation: 'leaveType.vacation',
sjukpenning: 'leaveType.sjukpenning',
lagsta: 'leaveType.lagsta',
}
return labelMap[type] ?? 'Unknown'
const key = labelKeyMap[type] ?? 'leaveType.unknown'
return t(key)
}