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:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render } from '@testing-library/react'
|
||||
import { DaysBreakdown } from './DaysBreakdown'
|
||||
import { DaysBreakdown, type DaysBreakdownProps } from './DaysBreakdown'
|
||||
|
||||
describe('DaysBreakdown', () => {
|
||||
it('renders empty state when no breakdown provided', () => {
|
||||
@@ -8,6 +8,13 @@ describe('DaysBreakdown', () => {
|
||||
expect(getByTestId('days-breakdown').textContent).toContain('Inga dagar registrerade än')
|
||||
})
|
||||
|
||||
it('renders empty state when breakdown itself is missing (defensive null/undefined guard)', () => {
|
||||
const { getByTestId } = render(
|
||||
<DaysBreakdown breakdown={undefined as unknown as DaysBreakdownProps['breakdown']} />
|
||||
)
|
||||
expect(getByTestId('days-breakdown').textContent).toContain('Inga dagar registrerade än')
|
||||
})
|
||||
|
||||
it('renders table with breakdown data', () => {
|
||||
const breakdown = [
|
||||
{ type: 'vacation', count: 10 },
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { ParentalLeaveBreakdown } from './ParentalLeaveBreakdown'
|
||||
import { LEAVE_RULES } from '@/utils/constants'
|
||||
import { LanguageProvider } from '@/i18n'
|
||||
import type { ParentalLeaveFetch } from '@/types'
|
||||
|
||||
describe('ParentalLeaveBreakdown', () => {
|
||||
@@ -36,6 +37,15 @@ describe('ParentalLeaveBreakdown', () => {
|
||||
expect(screen.getByText(/Ingen data hämtad ännu/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('omits the tier rows when tierData is absent', () => {
|
||||
const dataWithoutTiers = { ...mockData, tierData: undefined } as unknown as ParentalLeaveFetch
|
||||
render(<ParentalLeaveBreakdown data={dataWithoutTiers} />)
|
||||
expect(screen.queryByTestId('breakdown-sjukpenning')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('breakdown-lagsta-niva')).not.toBeInTheDocument()
|
||||
// The rows that don't depend on tierData still render.
|
||||
expect(screen.getByTestId('breakdown-transferable')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders breakdown table with data', () => {
|
||||
render(<ParentalLeaveBreakdown data={mockData} />)
|
||||
expect(screen.getByTestId('parental-leave-breakdown')).toBeInTheDocument()
|
||||
@@ -92,4 +102,26 @@ describe('ParentalLeaveBreakdown', () => {
|
||||
render(<ParentalLeaveBreakdown data={mockData} />)
|
||||
expect(screen.getByText(/2026-06-13/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('formats the provenance date using the en-US locale when the language is English', () => {
|
||||
Object.defineProperty(window.navigator, 'language', { value: 'en-US', configurable: true })
|
||||
vi.stubGlobal('localStorage', {
|
||||
getItem: () => null,
|
||||
setItem: () => undefined,
|
||||
removeItem: () => undefined,
|
||||
})
|
||||
|
||||
try {
|
||||
render(
|
||||
<LanguageProvider>
|
||||
<ParentalLeaveBreakdown data={mockData} />
|
||||
</LanguageProvider>,
|
||||
)
|
||||
// en-US formats as M/D/YYYY, distinct from the sv-SE "2026-06-13" form.
|
||||
expect(screen.getByText(/6\/13\/2026/)).toBeInTheDocument()
|
||||
} finally {
|
||||
Object.defineProperty(window.navigator, 'language', { value: 'sv-SE', configurable: true })
|
||||
vi.unstubAllGlobals()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user