* feat(ST-cmovhveef): add PLANNED to GRILL_TRIGGERABLE_FROM and PLANNED→GRILLING transition - GRILL_TRIGGERABLE_FROM now includes 'PLANNED' in actions/ideas.ts - ALLOWED_TRANSITIONS PLANNED entry extended with 'GRILLING' in lib/idea-status.ts - Updated canTransition test to reflect the new re-grill-from-PLANNED behavior * test(ST-cmovhvef3): add exhaustive re-grill canTransition test covering PLANNED Adds a loop test that asserts canTransition(status, 'GRILLING') for all statuses in GRILL_TRIGGERABLE_FROM that support the transition, explicitly documenting PLANNED as a valid re-grill entry point. * feat(ST-cmovhvegf): add existingPbi pre-check in materializeIdeaPlanAction - Adds options.allowAlongside parameter to control behaviour when a PBI with executed tasks already exists. - Returns 409 PBI_HAS_ACTIVE_TASKS:<code> when tasks are DONE/IN_PROGRESS and allowAlongside is not set. - Auto-deletes the old PBI inside the transaction when no tasks have been executed (atomic replace). - Alongside mode (allowAlongside=true) skips deletion and creates a new PBI. * test(ST-cmovhveh3): add pre-check integration tests for materializeIdeaPlanAction Three new scenarios in ideas-crud.test.ts: - auto-vervang: old PBI deleted in transaction when no executed tasks - conflict-409: returns PBI_HAS_ACTIVE_TASKS:<code> with active tasks - alongside: skips delete and creates new PBI when allowAlongside=true Also adds task.count, pbi.findUnique, pbi.delete to prisma mock. * feat(ST-cmovhveih): remove PLANNED-blokkering in idea-row-actions, add inline Bekijk-PBI button - Removed grillBlockedReason guard for status==='planned', enabling re-grill from PLANNED - Removed the early return for PLANNED that hid all standard buttons - Added conditional 'Bekijk <code>' button at the start of the standard button set, visible only when status==='planned' and PBI + product_id are present * feat(ST-cmovhvej7): add PBI_HAS_ACTIVE_TASKS alongside-dialoog in materialize handler When materializeIdeaPlanAction returns code 409 with PBI_HAS_ACTIVE_TASKS:<code>, a confirm dialog offers the user a choice: create new PBI alongside the existing one or cancel. Alongside=true retries the action; cancel leaves the idea in PLAN_READY.
107 lines
3.7 KiB
TypeScript
107 lines
3.7 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import {
|
|
ideaStatusToApi,
|
|
ideaStatusFromApi,
|
|
canTransition,
|
|
isIdeaEditable,
|
|
isGrillMdEditable,
|
|
isPlanMdEditable,
|
|
IDEA_STATUS_API_VALUES,
|
|
} from '@/lib/idea-status'
|
|
|
|
describe('idea-status mappers', () => {
|
|
it('round-trips every API value', () => {
|
|
for (const api of IDEA_STATUS_API_VALUES) {
|
|
const db = ideaStatusFromApi(api)
|
|
expect(db).not.toBeNull()
|
|
expect(ideaStatusToApi(db!)).toBe(api)
|
|
}
|
|
})
|
|
|
|
it('returns null for invalid input', () => {
|
|
expect(ideaStatusFromApi('NOT_A_STATUS')).toBeNull()
|
|
})
|
|
|
|
it('is case-insensitive on the API side', () => {
|
|
expect(ideaStatusFromApi('PLAN_READY')).toBe('PLAN_READY')
|
|
expect(ideaStatusFromApi('Plan_Ready')).toBe('PLAN_READY')
|
|
})
|
|
})
|
|
|
|
describe('canTransition', () => {
|
|
it('allows valid forward transitions', () => {
|
|
expect(canTransition('DRAFT', 'GRILLING')).toBe(true)
|
|
expect(canTransition('GRILLING', 'GRILLED')).toBe(true)
|
|
expect(canTransition('GRILLED', 'PLANNING')).toBe(true)
|
|
expect(canTransition('PLANNING', 'PLAN_READY')).toBe(true)
|
|
expect(canTransition('PLAN_READY', 'PLANNED')).toBe(true)
|
|
})
|
|
|
|
it('allows re-grill from GRILLED and PLAN_READY-ish states', () => {
|
|
expect(canTransition('GRILLED', 'GRILLING')).toBe(true)
|
|
expect(canTransition('PLAN_FAILED', 'PLANNING')).toBe(true)
|
|
})
|
|
|
|
it('allows fail-side transitions', () => {
|
|
expect(canTransition('GRILLING', 'GRILL_FAILED')).toBe(true)
|
|
expect(canTransition('PLANNING', 'PLAN_FAILED')).toBe(true)
|
|
})
|
|
|
|
it('allows recovery from failed states', () => {
|
|
expect(canTransition('GRILL_FAILED', 'GRILLING')).toBe(true)
|
|
expect(canTransition('PLAN_FAILED', 'GRILLED')).toBe(true)
|
|
})
|
|
|
|
it('allows PLANNED → PLAN_READY (relink) and PLANNED → GRILLING (re-grill)', () => {
|
|
expect(canTransition('PLANNED', 'PLAN_READY')).toBe(true)
|
|
expect(canTransition('PLANNED', 'GRILLING')).toBe(true)
|
|
expect(canTransition('PLANNED', 'DRAFT')).toBe(false)
|
|
})
|
|
|
|
it('canTransition to GRILLING from all statuses that allow re-grill', () => {
|
|
// DRAFT, GRILLED, GRILL_FAILED, PLANNED are in GRILL_TRIGGERABLE_FROM and support the transition.
|
|
const regrill = ['DRAFT', 'GRILLED', 'GRILL_FAILED', 'PLANNED'] as const
|
|
for (const status of regrill) {
|
|
expect(canTransition(status, 'GRILLING')).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('rejects invalid jumps', () => {
|
|
expect(canTransition('DRAFT', 'PLANNED')).toBe(false)
|
|
expect(canTransition('DRAFT', 'PLAN_READY')).toBe(false)
|
|
expect(canTransition('GRILLING', 'PLANNED')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isIdeaEditable', () => {
|
|
it('allows edit in non-running, non-PLANNED states', () => {
|
|
expect(isIdeaEditable('DRAFT')).toBe(true)
|
|
expect(isIdeaEditable('GRILLED')).toBe(true)
|
|
expect(isIdeaEditable('GRILL_FAILED')).toBe(true)
|
|
expect(isIdeaEditable('PLAN_FAILED')).toBe(true)
|
|
expect(isIdeaEditable('PLAN_READY')).toBe(true)
|
|
})
|
|
|
|
it('blocks edit while a job is running or after PLANNED', () => {
|
|
expect(isIdeaEditable('GRILLING')).toBe(false)
|
|
expect(isIdeaEditable('PLANNING')).toBe(false)
|
|
expect(isIdeaEditable('PLANNED')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isGrillMdEditable / isPlanMdEditable', () => {
|
|
it('grill_md only editable in GRILLED or PLAN_READY', () => {
|
|
expect(isGrillMdEditable('GRILLED')).toBe(true)
|
|
expect(isGrillMdEditable('PLAN_READY')).toBe(true)
|
|
expect(isGrillMdEditable('DRAFT')).toBe(false)
|
|
expect(isGrillMdEditable('PLANNED')).toBe(false)
|
|
})
|
|
|
|
it('plan_md only editable in PLAN_READY', () => {
|
|
expect(isPlanMdEditable('PLAN_READY')).toBe(true)
|
|
expect(isPlanMdEditable('GRILLED')).toBe(false)
|
|
expect(isPlanMdEditable('PLAN_FAILED')).toBe(false)
|
|
expect(isPlanMdEditable('PLANNED')).toBe(false)
|
|
})
|
|
})
|