Initial commit

This commit is contained in:
2026-06-01 16:48:21 +02:00
commit 53d157535a
159 changed files with 13641 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { usePlannedDays } from './usePlannedDays'
import * as api from '@/services/api'
vi.mock('@/services/api')
describe('usePlannedDays', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('initializes with null data', () => {
const { result } = renderHook(() => usePlannedDays(null))
expect(result.current.data).toBeNull()
expect(result.current.isLoading).toBe(false)
})
it('fetches planned days when both ids provided', async () => {
const mockData = [
{
id: '1',
workspace_id: 'ws1',
child_id: 'child1',
date: '2026-06-15',
day_type: 'vacation',
is_dubbeldag: false,
created_at: new Date().toISOString(),
},
]
vi.mocked(api.getPlannedDays).mockResolvedValue(mockData as any)
const { result } = renderHook(() => usePlannedDays('ws1', 'child1'))
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0))
})
expect(api.getPlannedDays).toHaveBeenCalledWith('ws1', 'child1')
})
it('does not fetch without childId', () => {
vi.mocked(api.getPlannedDays).mockResolvedValue([])
renderHook(() => usePlannedDays('ws1'))
expect(api.getPlannedDays).not.toHaveBeenCalled()
})
it('adds planned day and refreshes', async () => {
const mockAdded = {
id: '2',
workspace_id: 'ws1',
child_id: 'child1',
date: '2026-06-16',
day_type: 'vacation',
is_dubbeldag: false,
created_at: new Date().toISOString(),
}
vi.mocked(api.createPlannedDay).mockResolvedValue(mockAdded as any)
vi.mocked(api.getPlannedDays).mockResolvedValue([mockAdded])
const { result } = renderHook(() => usePlannedDays('ws1', 'child1'))
await act(async () => {
await result.current.add('2026-06-16', 'child1', 'vacation')
})
expect(api.createPlannedDay).toHaveBeenCalled()
})
it('removes planned day and refreshes', async () => {
vi.mocked(api.deletePlannedDay).mockResolvedValue(undefined)
vi.mocked(api.getPlannedDays).mockResolvedValue([])
const { result } = renderHook(() => usePlannedDays('ws1', 'child1'))
await act(async () => {
await result.current.remove('pd1')
})
expect(api.deletePlannedDay).toHaveBeenCalledWith('pd1')
})
})