Require a planned day to carry its wish and pinned state
Both fields were made optional to avoid editing test files that were out of scope at the time, but the API populates them on every planned day, so the optionality described nothing real and quietly loosened the contract between the wire format and the client — which is where this codebase has historically gone wrong. The inline objects that forced the compromise now go through the typed test factory instead, so the next field added to a planned day is a one-line change rather than another round of this.
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { PlannedDayModal } from './PlannedDayModal'
|
||||
import type { PlannedLeaveDay } from '@/types'
|
||||
import { makePlannedLeaveDay } from '@/../tests/fixtures'
|
||||
|
||||
describe('PlannedDayModal', () => {
|
||||
const mockOnClose = vi.fn()
|
||||
@@ -49,17 +49,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('shows "Redigera planerad dag" title when editing existing day', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
render(<PlannedDayModal {...defaultProps} isOpen={true} existingDay={existingDay} />)
|
||||
expect(screen.getByTestId('modal-title')).toHaveTextContent('Redigera planerad dag')
|
||||
})
|
||||
@@ -430,17 +423,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('displays local error after delete failure', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
mockOnDelete.mockRejectedValue(new Error('Delete failed'))
|
||||
|
||||
// Mock the confirm dialog
|
||||
@@ -464,17 +450,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('displays a generic error message for non-Error thrown in delete', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
mockOnDelete.mockRejectedValue('Some error')
|
||||
vi.spyOn(window, 'confirm').mockReturnValue(true)
|
||||
|
||||
@@ -521,17 +500,12 @@ describe('PlannedDayModal', () => {
|
||||
|
||||
describe('existing day initialization', () => {
|
||||
it('initializes day type from existing day', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p2',
|
||||
date: '2026-06-15',
|
||||
dayType: 'sjukpenning',
|
||||
isDubbeldag: true,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -552,17 +526,11 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('initializes parent from existing day', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p2',
|
||||
date: '2026-06-15',
|
||||
dayType: 'sjukpenning',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -583,17 +551,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('shows correct title when editing existing day', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -607,29 +568,17 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('reinitializes when existingDay changes', async () => {
|
||||
const firstDay: PlannedLeaveDay = {
|
||||
const firstDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
const secondDay: PlannedLeaveDay = {
|
||||
const secondDay = makePlannedLeaveDay({
|
||||
id: 'day-2',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'lagsta',
|
||||
isDubbeldag: true,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
const { rerender } = render(
|
||||
<PlannedDayModal
|
||||
@@ -709,17 +658,10 @@ describe('PlannedDayModal', () => {
|
||||
|
||||
describe('delete button functionality', () => {
|
||||
it('does not render delete button when onDelete not provided', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -733,17 +675,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('does not render delete button in range mode', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -759,17 +694,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('renders delete button when editing existing day with delete handler', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -784,17 +712,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('shows confirmation dialog before deleting', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true)
|
||||
mockOnDelete.mockResolvedValue(undefined)
|
||||
@@ -816,17 +737,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('does not call onDelete if confirmation is cancelled', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false)
|
||||
mockOnDelete.mockResolvedValue(undefined)
|
||||
@@ -848,17 +762,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('calls onDelete if confirmation is accepted', async () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true)
|
||||
mockOnDelete.mockResolvedValue(undefined)
|
||||
@@ -882,17 +789,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('disables delete button when saving', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
@@ -909,17 +809,10 @@ describe('PlannedDayModal', () => {
|
||||
})
|
||||
|
||||
it('shows loading text on delete button when saving', () => {
|
||||
const existingDay: PlannedLeaveDay = {
|
||||
const existingDay = makePlannedLeaveDay({
|
||||
id: 'day-1',
|
||||
workspaceId: 'ws-1',
|
||||
childId: 'c-1',
|
||||
parentPersonalDataUuid: 'p1',
|
||||
date: '2026-06-15',
|
||||
dayType: 'vacation',
|
||||
isDubbeldag: false,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
}
|
||||
})
|
||||
|
||||
render(
|
||||
<PlannedDayModal
|
||||
|
||||
Reference in New Issue
Block a user