Scrum4Me/__tests__/components/jobs/job-detail-pane.test.tsx
Scrum4Me Agent 864cb81f3c refactor(jobs): extraheer job-mapper naar lib/jobs-mapper.ts + voeg breadcrumb-velden toe
Verplaatst JobWithRelations, JOB_INCLUDE, RawJob, PriceRow, pickDescription,
computeCost en mapJob naar lib/jobs-mapper.ts (zonder 'use server'). Voegt
buildPriceMap helper toe en breidt de types uit met productCode, storyCode en
pbiCode via task->story->pbi en product.code includes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 00:48:18 +02:00

78 lines
2.3 KiB
TypeScript

// @vitest-environment jsdom
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import type { JobWithRelations } from '@/actions/jobs-page'
vi.mock('@/actions/claude-jobs', () => ({
restartClaudeJobAction: vi.fn(),
}))
vi.mock('sonner', () => ({ toast: { error: vi.fn() } }))
import { restartClaudeJobAction } from '@/actions/claude-jobs'
import JobDetailPane from '@/components/jobs/job-detail-pane'
const mockAction = restartClaudeJobAction as ReturnType<typeof vi.fn>
function makeJob(status: JobWithRelations['status']): JobWithRelations {
return {
id: 'job-1',
kind: 'TASK_IMPLEMENTATION',
status,
taskCode: 'T-1',
taskTitle: 'Test taak',
ideaCode: null,
ideaTitle: null,
sprintGoal: null,
sprintCode: null,
productName: 'Scrum4Me',
productCode: null,
storyCode: null,
pbiCode: null,
modelId: null,
inputTokens: null,
outputTokens: null,
cacheReadTokens: null,
cacheWriteTokens: null,
costUsd: null,
branch: null,
prUrl: null,
error: null,
summary: null,
description: null,
verifyResult: null,
startedAt: null,
finishedAt: null,
createdAt: new Date('2026-01-01'),
sprintRunId: null,
}
}
beforeEach(() => {
vi.clearAllMocks()
mockAction.mockResolvedValue({ success: true })
})
describe('JobDetailPane restart button', () => {
it('toont de knop voor FAILED-jobs', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeInTheDocument()
})
it('toont de knop niet voor DONE-jobs', () => {
render(<JobDetailPane job={makeJob('DONE')} isDemo={false} />)
expect(screen.queryByRole('button', { name: /opnieuw starten/i })).not.toBeInTheDocument()
})
it('roept restartClaudeJobAction aan met het juiste id bij klik', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={false} />)
fireEvent.click(screen.getByRole('button', { name: /opnieuw starten/i }))
expect(mockAction).toHaveBeenCalledWith('job-1')
})
it('knop is disabled in demo-modus', () => {
render(<JobDetailPane job={makeJob('FAILED')} isDemo={true} />)
expect(screen.getByRole('button', { name: /opnieuw starten/i })).toBeDisabled()
})
})