test(ST-1369): unit-tests voor deriveScreenState()
Dekt alle vier de kinds (NO_SPRINT, DRAFT, ACTIVE, EDITING), de building-flag en de draft-voorrang boven een actieve sprint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
07b3cf6822
commit
3171daed9e
1 changed files with 83 additions and 0 deletions
83
__tests__/stores/product-workspace/screen-state.test.ts
Normal file
83
__tests__/stores/product-workspace/screen-state.test.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
deriveScreenState,
|
||||
type ScreenStateInput,
|
||||
} from '@/stores/product-workspace/screen-state'
|
||||
|
||||
const base: ScreenStateInput = {
|
||||
activeSprintItem: null,
|
||||
buildingSprintIds: [],
|
||||
hasPendingDraft: false,
|
||||
pendingAdds: [],
|
||||
pendingRemoves: [],
|
||||
}
|
||||
|
||||
describe('deriveScreenState', () => {
|
||||
it('returns NO_SPRINT without draft or active sprint', () => {
|
||||
expect(deriveScreenState(base)).toEqual({ kind: 'NO_SPRINT' })
|
||||
})
|
||||
|
||||
it('returns DRAFT when a pending draft exists', () => {
|
||||
expect(deriveScreenState({ ...base, hasPendingDraft: true })).toEqual({
|
||||
kind: 'DRAFT',
|
||||
})
|
||||
})
|
||||
|
||||
it('lets a draft win over an active sprint with pending changes', () => {
|
||||
expect(
|
||||
deriveScreenState({
|
||||
...base,
|
||||
hasPendingDraft: true,
|
||||
activeSprintItem: { id: 's1' },
|
||||
pendingAdds: ['x'],
|
||||
}),
|
||||
).toEqual({ kind: 'DRAFT' })
|
||||
})
|
||||
|
||||
it('returns ACTIVE for an active sprint with no pending changes', () => {
|
||||
expect(
|
||||
deriveScreenState({ ...base, activeSprintItem: { id: 's1' } }),
|
||||
).toEqual({ kind: 'ACTIVE', building: false })
|
||||
})
|
||||
|
||||
it('flags building when the active sprint is in buildingSprintIds', () => {
|
||||
expect(
|
||||
deriveScreenState({
|
||||
...base,
|
||||
activeSprintItem: { id: 's1' },
|
||||
buildingSprintIds: ['s1'],
|
||||
}),
|
||||
).toEqual({ kind: 'ACTIVE', building: true })
|
||||
})
|
||||
|
||||
it('returns EDITING when there are pending adds', () => {
|
||||
expect(
|
||||
deriveScreenState({
|
||||
...base,
|
||||
activeSprintItem: { id: 's1' },
|
||||
pendingAdds: ['x'],
|
||||
}),
|
||||
).toEqual({ kind: 'EDITING', building: false })
|
||||
})
|
||||
|
||||
it('returns EDITING when there are pending removes', () => {
|
||||
expect(
|
||||
deriveScreenState({
|
||||
...base,
|
||||
activeSprintItem: { id: 's1' },
|
||||
pendingRemoves: ['y'],
|
||||
}),
|
||||
).toEqual({ kind: 'EDITING', building: false })
|
||||
})
|
||||
|
||||
it('flags building on EDITING when the active sprint is building', () => {
|
||||
expect(
|
||||
deriveScreenState({
|
||||
...base,
|
||||
activeSprintItem: { id: 's1' },
|
||||
pendingAdds: ['x'],
|
||||
buildingSprintIds: ['s1'],
|
||||
}),
|
||||
).toEqual({ kind: 'EDITING', building: true })
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue