M12 / ST-1109: PBI krijgt een status (Ready / Blocked / Done) (#16)

* feat(ST-1109.2): add PbiStatus enum and status field to Pbi model

- New PbiStatus enum (READY/BLOCKED/DONE) for PBI lifecycle tracking
- Pbi.status PbiStatus @default(READY)
- Index on (product_id, status) for filter queries
- Migration: 20260429150643_add_pbi_status
- ERD regenerated via prisma generate

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.3): add PBI status API mappers

- pbiStatusToApi / pbiStatusFromApi following same pattern as task/story
- PbiStatusApi type derived from PBI_DB_TO_API
- PBI_STATUS_API_VALUES export for downstream Zod schemas
- Lowercase API surface (ready/blocked/done), DB stays UPPER_SNAKE

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.4): support status in PBI create/update actions

- Optional status field in Zod schemas (lowercase API: ready/blocked/done)
- pbiStatusFromApi() maps to DB enum before persistence
- Status omitted on create => Prisma @default(READY) takes effect
- Update preserves existing status when not provided
- Demo-check unchanged

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.5): auto-mark PBI as DONE when all its stories are DONE on sprint close

Extends completeSprintAction's $transaction with PBI status cascade:
- Pre-transaction: identify PBIs touched by this close (via stories.pbi_id),
  fetch each with all its stories
- Skip PBIs already DONE; skip PBIs with 0 stories
- Mark PBI DONE only when every story (post-decision) is DONE — stories
  outside the sprint are evaluated against their current DB status
- Promote-only: never demotes a PBI that becomes "incomplete" again

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.6): add Popover primitive (base-ui wrapper)

- Mirrors the Tooltip pattern: render-prop composition, data-slot attrs
- Exports Popover (Root), PopoverTrigger, PopoverContent (Portal+Positioner+Popup)
- MD3 popover/popover-foreground tokens, animated open/close states
- Will be used to consolidate the backlog filter UI in ST-1109.8

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.7): add status select to PBI dialog

- New components/shared/pbi-status-select.tsx mirrors PrioritySelect:
  PBI_STATUS_LABELS (NL), PBI_STATUS_COLORS, PbiStatusSelect component
- Reuses existing --status-todo/blocked/done MD3 tokens
- PbiDialog: status state with sync-on-open; default 'ready' for create,
  pbi.status for edit; hidden input submits lowercase API value
- Priority + Status sit side-by-side in 2-col grid
- PbiDialogPbi.status is optional; pbi-list.tsx will populate in ST-1109.8

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.8): show PBI status badge and consolidate filters into popover

- Pbi.status (lowercase API) flows from page.tsx via pbiStatusToApi
- Status badge rendered in BacklogCard's badge slot using PBI_STATUS_COLORS
- Two old Select dropdowns replaced by single Popover with three pill-button
  sections (Sorteren, Prioriteit, Status) and a "Wis filters" footer
- Filter trigger shows active count "(n)" badge in label
- Active priority/status filters still surface as dismissable chips next to
  the trigger for at-a-glance feedback
- onEdit passes the full Pbi (incl. status) so the dialog opens with the
  correct current status — closes the data flow loop opened in ST-1109.7

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(ST-1109.9): cover PBI status mappers and sprint-close cascade

- __tests__/lib/task-status.test.ts: 11 cases incl. round-trip + invalid
  input for task/story/pbi mappers; verifies PBI_STATUS_API_VALUES shape
- __tests__/actions/sprints-cascade.test.ts: 8 cases for completeSprintAction:
  promote on all-DONE, no promote on partial OPEN, respect out-of-sprint
  story status, skip already-DONE PBIs, multi-PBI cascade, 0-story guard,
  demo-user block
- Full vitest run: 170/170 green across 21 files

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(ST-1109.10): document PbiStatus enum, sprint-close cascade, and filter UI

- docs/scrum4me-architecture.md: pbis-table updated with status column +
  index; PbiStatus enum + Pbi model in the Prisma schema sample;
  cascade-on-sprint-close rule documented inline
- docs/scrum4me-styling.md: short note pointing to PBI_STATUS_LABELS /
  PBI_STATUS_COLORS in components/shared/pbi-status-select.tsx so future
  components don't ad-hoc-copy the color map
- docs/plans/ST-1109-pbi-status.md: in-repo mirror of the approved plan
  (per feedback_plan_location memory) with cascade pseudo-code and
  end-to-end verification checklist

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ST-1109.11): persist backlog filters in localStorage

Filters reset op reload was verwarrend. Nu net als sortMode:
- scrum4me:pbi_filter_priority — 'all' | '1' | '2' | '3' | '4'
- scrum4me:pbi_filter_status — 'all' | 'ready' | 'blocked' | 'done'

useState-init met SSR-guard; ongeldige waarden vallen terug op 'all'.
Wis filters reset alle drie de keys correct (sortMode -> 'priority',
beide filters -> 'all'), waardoor de localStorage-staat consistent wordt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-04-29 17:52:34 +02:00 committed by GitHub
parent 50faebb82c
commit 8a9fb9d32b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 767 additions and 48 deletions

View file

@ -0,0 +1,238 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('next/cache', () => ({ revalidatePath: vi.fn() }))
vi.mock('next/headers', () => ({ cookies: vi.fn().mockResolvedValue({}) }))
vi.mock('iron-session', () => ({
getIronSession: vi.fn().mockResolvedValue({ userId: 'user-1', isDemo: false }),
}))
vi.mock('@/lib/session', () => ({
sessionOptions: { cookieName: 'test', password: 'test' },
}))
vi.mock('@/lib/product-access', () => ({
productAccessFilter: vi.fn().mockReturnValue({}),
getAccessibleProduct: vi.fn().mockResolvedValue({ id: 'product-1' }),
}))
vi.mock('@/lib/prisma', () => ({
prisma: {
sprint: {
findFirst: vi.fn(),
update: vi.fn(),
},
story: {
findMany: vi.fn(),
update: vi.fn(),
},
pbi: {
findMany: vi.fn(),
update: vi.fn(),
},
$transaction: vi.fn().mockResolvedValue([]),
},
}))
import { prisma } from '@/lib/prisma'
import { completeSprintAction } from '@/actions/sprints'
const mockPrisma = prisma as unknown as {
sprint: {
findFirst: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
story: {
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
pbi: {
findMany: ReturnType<typeof vi.fn>
update: ReturnType<typeof vi.fn>
}
$transaction: ReturnType<typeof vi.fn>
}
const SPRINT = { id: 'sprint-1', product_id: 'product-1', status: 'ACTIVE' }
beforeEach(() => {
vi.clearAllMocks()
mockPrisma.sprint.findFirst.mockResolvedValue(SPRINT)
mockPrisma.$transaction.mockResolvedValue([])
})
describe('completeSprintAction — PBI auto-DONE cascade', () => {
it('marks PBI DONE when all its stories are decided DONE', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
{ id: 'story-b', pbi_id: 'pbi-1' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{
id: 'pbi-1',
stories: [
{ id: 'story-a', status: 'IN_SPRINT' },
{ id: 'story-b', status: 'IN_SPRINT' },
],
},
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
'story-b': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).toHaveBeenCalledTimes(1)
expect(mockPrisma.pbi.update).toHaveBeenCalledWith({
where: { id: 'pbi-1' },
data: { status: 'DONE' },
})
})
it('does not mark PBI DONE when a story is decided OPEN', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
{ id: 'story-b', pbi_id: 'pbi-1' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{
id: 'pbi-1',
stories: [
{ id: 'story-a', status: 'IN_SPRINT' },
{ id: 'story-b', status: 'IN_SPRINT' },
],
},
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
'story-b': 'OPEN',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
})
it('does not mark PBI DONE when it has stories outside this sprint that are not DONE', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{
id: 'pbi-1',
stories: [
{ id: 'story-a', status: 'IN_SPRINT' },
{ id: 'story-b', status: 'OPEN' },
],
},
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
})
it('marks PBI DONE when its in-sprint stories are DONE and out-of-sprint stories are already DONE', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{
id: 'pbi-1',
stories: [
{ id: 'story-a', status: 'IN_SPRINT' },
{ id: 'story-b', status: 'DONE' },
],
},
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).toHaveBeenCalledWith({
where: { id: 'pbi-1' },
data: { status: 'DONE' },
})
})
it('skips PBIs that are already DONE (promote-only)', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
])
// pbi.findMany filters via { status: { not: 'DONE' } } in the action,
// so an already-DONE PBI just doesn't appear in candidatePbis.
mockPrisma.pbi.findMany.mockResolvedValue([])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
expect(mockPrisma.pbi.findMany).toHaveBeenCalledWith({
where: { id: { in: ['pbi-1'] }, status: { not: 'DONE' } },
select: { id: true, stories: { select: { id: true, status: true } } },
})
})
it('cascades across multiple PBIs in one sprint close', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
{ id: 'story-b', pbi_id: 'pbi-2' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{ id: 'pbi-1', stories: [{ id: 'story-a', status: 'IN_SPRINT' }] },
{ id: 'pbi-2', stories: [{ id: 'story-b', status: 'IN_SPRINT' }] },
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
'story-b': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).toHaveBeenCalledTimes(2)
expect(mockPrisma.pbi.update).toHaveBeenCalledWith({
where: { id: 'pbi-1' },
data: { status: 'DONE' },
})
expect(mockPrisma.pbi.update).toHaveBeenCalledWith({
where: { id: 'pbi-2' },
data: { status: 'DONE' },
})
})
it('does not include 0-story PBIs in cascade', async () => {
mockPrisma.story.findMany.mockResolvedValue([
{ id: 'story-a', pbi_id: 'pbi-1' },
])
mockPrisma.pbi.findMany.mockResolvedValue([
{ id: 'pbi-1', stories: [] },
])
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
})
expect(result).toEqual({ success: true })
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
})
it('blocks sprint close for demo users', async () => {
const { getIronSession } = await import('iron-session')
;(getIronSession as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
userId: 'user-demo',
isDemo: true,
})
const result = await completeSprintAction('sprint-1', {
'story-a': 'DONE',
})
expect(result).toEqual({ error: 'Niet beschikbaar in demo-modus' })
expect(mockPrisma.$transaction).not.toHaveBeenCalled()
expect(mockPrisma.pbi.update).not.toHaveBeenCalled()
})
})

View file

@ -0,0 +1,85 @@
import { describe, it, expect } from 'vitest'
import {
taskStatusToApi,
taskStatusFromApi,
storyStatusToApi,
storyStatusFromApi,
pbiStatusToApi,
pbiStatusFromApi,
TASK_STATUS_API_VALUES,
STORY_STATUS_API_VALUES,
PBI_STATUS_API_VALUES,
} from '@/lib/task-status'
describe('task-status mappers', () => {
describe('taskStatus', () => {
it('round-trips every API value', () => {
for (const api of TASK_STATUS_API_VALUES) {
const db = taskStatusFromApi(api)
expect(db).not.toBeNull()
expect(taskStatusToApi(db!)).toBe(api)
}
})
it('returns null for invalid input', () => {
expect(taskStatusFromApi('NOT_A_STATUS')).toBeNull()
})
it('is case-insensitive on the API side', () => {
expect(taskStatusFromApi('IN_PROGRESS')).toBe('IN_PROGRESS')
expect(taskStatusFromApi('In_Progress')).toBe('IN_PROGRESS')
})
})
describe('storyStatus', () => {
it('round-trips every API value', () => {
for (const api of STORY_STATUS_API_VALUES) {
const db = storyStatusFromApi(api)
expect(db).not.toBeNull()
expect(storyStatusToApi(db!)).toBe(api)
}
})
it('returns null for invalid input', () => {
expect(storyStatusFromApi('archived')).toBeNull()
})
})
describe('pbiStatus', () => {
it('round-trips every API value', () => {
for (const api of PBI_STATUS_API_VALUES) {
const db = pbiStatusFromApi(api)
expect(db).not.toBeNull()
expect(pbiStatusToApi(db!)).toBe(api)
}
})
it('maps DB to lowercase API', () => {
expect(pbiStatusToApi('READY')).toBe('ready')
expect(pbiStatusToApi('BLOCKED')).toBe('blocked')
expect(pbiStatusToApi('DONE')).toBe('done')
})
it('maps API to UPPER_SNAKE DB', () => {
expect(pbiStatusFromApi('ready')).toBe('READY')
expect(pbiStatusFromApi('blocked')).toBe('BLOCKED')
expect(pbiStatusFromApi('done')).toBe('DONE')
})
it('is case-insensitive on the API side', () => {
expect(pbiStatusFromApi('READY')).toBe('READY')
expect(pbiStatusFromApi('Blocked')).toBe('BLOCKED')
})
it('returns null for invalid input', () => {
expect(pbiStatusFromApi('archived')).toBeNull()
expect(pbiStatusFromApi('')).toBeNull()
expect(pbiStatusFromApi('todo')).toBeNull()
})
it('exposes exactly three API values', () => {
expect(PBI_STATUS_API_VALUES).toEqual(['ready', 'blocked', 'done'])
})
})
})