Raise frontend branch coverage from 86.84% to 93.78%

Branches were the weakest metric and had the least headroom above the
85% floor. These are tests for decision paths that were genuinely
unexercised, not padding.

The largest gaps were systemic rather than per-file: the
`err instanceof Error ? ... : fallback` branch was untested across eight
data hooks, useVacationDays had no dedicated test file at all, and
Calendar.tsx's missing-workspace/child/personalData fallbacks were never
hit.

Left deliberately uncovered, with reasons: `?? fallback` guards whose
fallback cannot occur given how the value is constructed upstream, and
guards behind buttons that are disabled whenever the guard would matter.
Reaching those means calling handlers directly, which tests the test
rather than the app.

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 18:54:56 +02:00
parent 8869ea8e55
commit c5481a05f0
23 changed files with 1063 additions and 5 deletions
+65
View File
@@ -6,6 +6,9 @@ import {
isValidDate,
getDayName,
getMonthName,
getISOWeekNumber,
formatHolidayName,
datesInRange,
} from '@/utils/dates'
describe('dates.ts utilities', () => {
@@ -140,4 +143,66 @@ describe('dates.ts utilities', () => {
expect(result).toBe('')
})
})
describe('getISOWeekNumber', () => {
it('returns 0 for an invalid date', () => {
expect(getISOWeekNumber(new Date('invalid'))).toBe(0)
})
it('computes the ISO week number for a mid-week date', () => {
// 2026-06-15 is a Monday.
expect(getISOWeekNumber(new Date('2026-06-15T00:00:00Z'))).toBe(25)
})
it('handles a Sunday correctly (getUTCDay() === 0 falls back to ISO day 7)', () => {
// 2026-01-11 is a Sunday, closing out ISO week 2 of 2026.
expect(getISOWeekNumber(new Date('2026-01-11T00:00:00Z'))).toBe(2)
})
})
describe('formatHolidayName', () => {
it('returns the name unchanged when it has no ";" segments', () => {
expect(formatHolidayName('Midsommardagen')).toBe('Midsommardagen')
})
it('strips a trailing weekday segment', () => {
expect(formatHolidayName('Påskdagen; Söndag')).toBe('Påskdagen')
})
it('falls back to the first segment when every segment is a weekday name', () => {
// Contrived input where nothing survives the weekday filter — the
// function must not return an empty string in that case.
expect(formatHolidayName('Söndag; Måndag')).toBe('Söndag')
})
})
describe('datesInRange', () => {
it('returns an empty array when the start date is invalid', () => {
expect(datesInRange('invalid', '2026-06-15')).toEqual([])
})
it('returns an empty array when the end date is invalid', () => {
expect(datesInRange('2026-06-15', 'invalid')).toEqual([])
})
it('returns the inclusive range in ascending order for start before end', () => {
expect(datesInRange('2026-06-01', '2026-06-03')).toEqual([
'2026-06-01',
'2026-06-02',
'2026-06-03',
])
})
it('returns the same range regardless of argument order (reversed input)', () => {
expect(datesInRange('2026-06-03', '2026-06-01')).toEqual([
'2026-06-01',
'2026-06-02',
'2026-06-03',
])
})
it('returns a single date when start equals end', () => {
expect(datesInRange('2026-06-01', '2026-06-01')).toEqual(['2026-06-01'])
})
})
})