Lead the overview with the days about to be lost
The page opened with generic tiles and a bar reading forty-eight of ninety-six weeks, which was neither weeks nor connected to the age-four ceiling it appeared to describe. It is replaced by one headline and a bar per parent, in days, against each parent's own savable limit as the server reports it. The headline has two framings on the same arithmetic. Before anything is planned it says what there is to plan and what will be lost without a plan, because on the first day almost the whole entitlement is technically at risk and saying so bluntly reads as an accusation. Once a plan exists it warns about the days genuinely at stake. A timeline of the years to the fourth birthday answers what the next four years look like, which a month-at-a-time calendar cannot. Shortfalls, surplus advice and balances sit below the fold, read-only: applying is automatic now, so a second apply button would be a way to get two different answers. Rejection messages move to one shared place that resolves a parent's name, so an identifier can no longer surface in their place.
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { renderRejection } from './rejectionMessages'
|
||||
import { translate } from '@/i18n'
|
||||
import type { PersonalData, Rejection } from '@/types'
|
||||
|
||||
const t = (key: Parameters<typeof translate>[1], params?: Parameters<typeof translate>[2]) =>
|
||||
translate('sv', key, params)
|
||||
|
||||
const member = (overrides: Partial<PersonalData> = {}): PersonalData => ({
|
||||
uuid: 'pd-a',
|
||||
workspaceId: 'ws-1',
|
||||
name: 'Alex',
|
||||
salaryType: 'monthly',
|
||||
employmentStatus: 'employed',
|
||||
createdAt: '2026-01-01',
|
||||
...overrides,
|
||||
})
|
||||
|
||||
const rejection = (overrides: Partial<Rejection> = {}): Rejection => ({
|
||||
messageKey: 'planApply.rejection.insufficientBalance',
|
||||
data: {},
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('renderRejection', () => {
|
||||
it('renders every known message_key to a real (non-raw-key) string', () => {
|
||||
const knownKeys = [
|
||||
'planApply.rejection.invalidDayType',
|
||||
'planApply.rejection.conflictingDuplicate',
|
||||
'planApply.rejection.collisionsNeedReplace',
|
||||
'planApply.rejection.dubbeldagWindowExceeded',
|
||||
'planApply.rejection.dubbeldagQuotaReached',
|
||||
'planApply.rejection.dubbeldagInvalid',
|
||||
'planApply.rejection.dubbeldagBatchQuotaExceeded',
|
||||
'planApply.rejection.outsideEligibleWindow',
|
||||
'planApply.rejection.insufficientBalance',
|
||||
'planApply.rejection.insufficientVacationBalance',
|
||||
]
|
||||
for (const messageKey of knownKeys) {
|
||||
const rendered = renderRejection(rejection({ messageKey }), t, [])
|
||||
expect(rendered).not.toBe(messageKey)
|
||||
}
|
||||
})
|
||||
|
||||
it('falls back to the raw message_key when the backend sends one this build does not recognise', () => {
|
||||
expect(renderRejection(rejection({ messageKey: 'planApply.rejection.somethingNew' }), t, [])).toBe(
|
||||
'planApply.rejection.somethingNew',
|
||||
)
|
||||
})
|
||||
|
||||
it('resolves insufficientVacationBalance with a real parent name, never a raw uuid', () => {
|
||||
const rendered = renderRejection(
|
||||
rejection({
|
||||
messageKey: 'planApply.rejection.insufficientVacationBalance',
|
||||
data: { parent_personal_data_uuid: 'pd-a', year: 2026, needed: 3, remaining: 1 },
|
||||
}),
|
||||
t,
|
||||
[member({ uuid: 'pd-a', name: 'Alex' })],
|
||||
)
|
||||
expect(rendered).toContain('Alex')
|
||||
expect(rendered).not.toContain('pd-a')
|
||||
expect(rendered).toContain('3')
|
||||
expect(rendered).toContain('2026')
|
||||
expect(rendered).toContain('1')
|
||||
})
|
||||
|
||||
it('falls back to a generic label, never the raw uuid, when no member matches', () => {
|
||||
const rendered = renderRejection(
|
||||
rejection({
|
||||
messageKey: 'planApply.rejection.insufficientVacationBalance',
|
||||
data: { parent_personal_data_uuid: 'pd-unknown', year: 2026, needed: 3, remaining: 1 },
|
||||
}),
|
||||
t,
|
||||
[member({ uuid: 'pd-a', name: 'Alex' })],
|
||||
)
|
||||
expect(rendered).not.toContain('pd-unknown')
|
||||
expect(rendered).toContain('Okänd förälder')
|
||||
})
|
||||
|
||||
it('resolves the parent uuid in conflictingDuplicate to a name, not the raw uuid', () => {
|
||||
const rendered = renderRejection(
|
||||
rejection({
|
||||
messageKey: 'planApply.rejection.conflictingDuplicate',
|
||||
data: { date: '2026-06-15', child_id: 'child-1', parent_personal_data_uuid: 'pd-a' },
|
||||
}),
|
||||
t,
|
||||
[member({ uuid: 'pd-a', name: 'Alex' })],
|
||||
)
|
||||
expect(rendered).toContain('Alex')
|
||||
expect(rendered).not.toContain('pd-a')
|
||||
})
|
||||
|
||||
it('leaves data with no parent uuid untouched', () => {
|
||||
const rendered = renderRejection(
|
||||
rejection({
|
||||
messageKey: 'planApply.rejection.insufficientBalance',
|
||||
data: { needed: 2, tier: 'sjukpenning', remaining: 1 },
|
||||
}),
|
||||
t,
|
||||
[],
|
||||
)
|
||||
expect(rendered).toContain('2')
|
||||
expect(rendered).toContain('sjukpenning')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user