Load/render workspace alignment (#182)
* docs: plan load render workspace alignment * fix: normalize workspace status hydration * fix: avoid duplicate backlog hydration load * refactor: use sprint store active story * refactor: migrate solo to workspace store * chore: stabilize verification ignores
This commit is contained in:
parent
98ee05d458
commit
3b5cee823c
28 changed files with 1845 additions and 577 deletions
|
|
@ -90,7 +90,7 @@ function makeStory(overrides: Partial<BacklogStory> & { id: string; pbi_id: stri
|
|||
acceptance_criteria: overrides.acceptance_criteria ?? null,
|
||||
priority: overrides.priority ?? 2,
|
||||
sort_order: overrides.sort_order ?? 1,
|
||||
status: overrides.status ?? 'open',
|
||||
status: overrides.status ?? 'OPEN',
|
||||
pbi_id: overrides.pbi_id,
|
||||
sprint_id: overrides.sprint_id ?? null,
|
||||
created_at: overrides.created_at ?? new Date('2026-01-01'),
|
||||
|
|
@ -104,7 +104,7 @@ function makeTask(overrides: Partial<BacklogTask> & { id: string; story_id: stri
|
|||
description: overrides.description ?? null,
|
||||
priority: overrides.priority ?? 2,
|
||||
sort_order: overrides.sort_order ?? 1,
|
||||
status: overrides.status ?? 'todo',
|
||||
status: overrides.status ?? 'TO_DO',
|
||||
story_id: overrides.story_id,
|
||||
created_at: overrides.created_at ?? new Date('2026-01-01'),
|
||||
}
|
||||
|
|
@ -168,6 +168,27 @@ describe('hydrateSnapshot', () => {
|
|||
expect(s.loading.loadedProductId).toBe('prod-1')
|
||||
})
|
||||
|
||||
it('normaliseert API-statussen naar het interne store-contract', () => {
|
||||
useProductWorkspaceStore.getState().hydrateSnapshot(
|
||||
snapshotWith(
|
||||
[makePbi({ id: 'pbi-1', status: 'READY' as BacklogPbi['status'] })],
|
||||
{
|
||||
'pbi-1': [
|
||||
makeStory({ id: 'st-1', pbi_id: 'pbi-1', status: 'in_sprint' }),
|
||||
],
|
||||
},
|
||||
{
|
||||
'st-1': [makeTask({ id: 'tk-1', story_id: 'st-1', status: 'todo' })],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
const s = useProductWorkspaceStore.getState()
|
||||
expect(s.entities.pbisById['pbi-1'].status).toBe('ready')
|
||||
expect(s.entities.storiesById['st-1'].status).toBe('IN_SPRINT')
|
||||
expect(s.entities.tasksById['tk-1'].status).toBe('TO_DO')
|
||||
})
|
||||
|
||||
it('reset bestaande entities en relations bij her-hydratie', () => {
|
||||
useProductWorkspaceStore.getState().hydrateSnapshot(
|
||||
snapshotWith([makePbi({ id: 'old-pbi' })]),
|
||||
|
|
@ -236,6 +257,35 @@ describe('selection cascade', () => {
|
|||
expect(s.relations.taskIdsByStory).toEqual({})
|
||||
expect(s.loading.loadedProductId).toBeNull()
|
||||
})
|
||||
|
||||
it('setActiveProduct kan alleen context zetten zonder full backlog load', () => {
|
||||
useProductWorkspaceStore.getState().hydrateSnapshot(
|
||||
snapshotWith(
|
||||
[makePbi({ id: 'p-1' })],
|
||||
{ 'p-1': [makeStory({ id: 's-1', pbi_id: 'p-1' })] },
|
||||
{ 's-1': [makeTask({ id: 't-1', story_id: 's-1' })] },
|
||||
{ id: 'prod-1', name: 'Product 1' },
|
||||
),
|
||||
)
|
||||
useProductWorkspaceStore.setState((s) => {
|
||||
s.context.activePbiId = 'p-1'
|
||||
s.context.activeStoryId = 's-1'
|
||||
})
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch')
|
||||
|
||||
useProductWorkspaceStore
|
||||
.getState()
|
||||
.setActiveProduct(
|
||||
{ id: 'prod-1', name: 'Product 1' },
|
||||
{ load: false, preserveSelection: true },
|
||||
)
|
||||
|
||||
const s = useProductWorkspaceStore.getState()
|
||||
expect(fetchSpy).not.toHaveBeenCalled()
|
||||
expect(s.context.activePbiId).toBe('p-1')
|
||||
expect(s.context.activeStoryId).toBe('s-1')
|
||||
expect(s.entities.pbisById['p-1']).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
|
@ -624,6 +674,7 @@ describe('ensureTaskLoaded — zet detail-flag', () => {
|
|||
await useProductWorkspaceStore.getState().ensureTaskLoaded('t-1')
|
||||
const task = useProductWorkspaceStore.getState().entities.tasksById['t-1'] as TaskDetail
|
||||
expect(task._detail).toBe(true)
|
||||
expect(task.status).toBe('TO_DO')
|
||||
expect(task.implementation_plan).toBe('detailed plan here')
|
||||
expect(useProductWorkspaceStore.getState().loading.loadedTaskIds['t-1']).toBe(true)
|
||||
})
|
||||
|
|
|
|||
131
__tests__/stores/solo-workspace/store.test.ts
Normal file
131
__tests__/stores/solo-workspace/store.test.ts
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useSoloStore } from '@/stores/solo-store'
|
||||
import type { RealtimeEvent } from '@/stores/solo-store'
|
||||
import type { SoloTask, SoloWorkspaceSnapshot } from '@/stores/solo-workspace/types'
|
||||
|
||||
function baseTask(id: string, overrides: Partial<SoloTask> = {}): SoloTask {
|
||||
return {
|
||||
id,
|
||||
title: `Task ${id}`,
|
||||
description: null,
|
||||
implementation_plan: null,
|
||||
priority: 1,
|
||||
sort_order: 1,
|
||||
status: 'TO_DO',
|
||||
verify_only: false,
|
||||
verify_required: 'ALIGNED_OR_PARTIAL',
|
||||
story_id: 'story-1',
|
||||
story_code: 'ST-1',
|
||||
story_title: 'Story 1',
|
||||
task_code: `ST-1.${id}`,
|
||||
pbi_code: null,
|
||||
pbi_title: null,
|
||||
pbi_description: null,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
function snapshot(tasks: SoloTask[]): SoloWorkspaceSnapshot {
|
||||
return {
|
||||
product: { id: 'prod-1', name: 'Product 1' },
|
||||
sprint: { id: 'sprint-1', sprint_goal: 'Goal' },
|
||||
activeUserId: 'user-1',
|
||||
tasks,
|
||||
unassignedStories: [
|
||||
{ id: 'story-b', code: 'ST-2', title: 'Story B', tasks: [] },
|
||||
{ id: 'story-a', code: 'ST-1', title: 'Story A', tasks: [] },
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function taskEvent(overrides: Partial<RealtimeEvent>): RealtimeEvent {
|
||||
return {
|
||||
op: 'U',
|
||||
entity: 'task',
|
||||
id: 'task-1',
|
||||
story_id: 'story-1',
|
||||
product_id: 'prod-1',
|
||||
sprint_id: 'sprint-1',
|
||||
assignee_id: 'user-1',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useSoloStore.setState({
|
||||
context: { activeProduct: null, activeSprint: null, activeUserId: null },
|
||||
entities: { tasksById: {}, unassignedStoriesById: {}, jobsByTaskId: {} },
|
||||
relations: {
|
||||
taskIdsByColumn: { TO_DO: [], IN_PROGRESS: [], DONE: [] },
|
||||
unassignedStoryIds: [],
|
||||
},
|
||||
loading: {
|
||||
loadedProductId: null,
|
||||
loadedSprintId: null,
|
||||
loadingSprintId: null,
|
||||
activeRequestId: null,
|
||||
},
|
||||
sync: {
|
||||
realtimeStatus: 'connecting',
|
||||
showConnectingIndicator: false,
|
||||
lastEventAt: null,
|
||||
lastResyncAt: null,
|
||||
resyncReason: null,
|
||||
},
|
||||
pendingOps: new Set(),
|
||||
tasks: {},
|
||||
unassignedStoriesById: {},
|
||||
claudeJobsByTaskId: {},
|
||||
})
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('solo workspace store', () => {
|
||||
it('hydrateert genormaliseerde taken, kolomrelaties en unassigned stories', () => {
|
||||
useSoloStore.getState().hydrateSnapshot(
|
||||
snapshot([
|
||||
baseTask('task-2', { status: 'DONE', sort_order: 2 }),
|
||||
baseTask('task-1', { status: 'TO_DO', sort_order: 1 }),
|
||||
baseTask('task-3', { status: 'REVIEW', sort_order: 3 }),
|
||||
]),
|
||||
)
|
||||
|
||||
const s = useSoloStore.getState()
|
||||
expect(s.context.activeSprint?.id).toBe('sprint-1')
|
||||
expect(s.relations.taskIdsByColumn.TO_DO).toEqual(['task-1'])
|
||||
expect(s.relations.taskIdsByColumn.IN_PROGRESS).toEqual(['task-3'])
|
||||
expect(s.relations.taskIdsByColumn.DONE).toEqual(['task-2'])
|
||||
expect(s.relations.unassignedStoryIds).toEqual(['story-a', 'story-b'])
|
||||
})
|
||||
|
||||
it('past realtime task updates toe en herbouwt kolomrelaties', () => {
|
||||
useSoloStore.getState().hydrateSnapshot(snapshot([baseTask('task-1')]))
|
||||
useSoloStore.getState().handleRealtimeEvent(
|
||||
taskEvent({ status: 'DONE', sort_order: 5, title: 'Done task' }),
|
||||
)
|
||||
|
||||
const s = useSoloStore.getState()
|
||||
expect(s.tasks['task-1'].status).toBe('DONE')
|
||||
expect(s.tasks['task-1'].title).toBe('Done task')
|
||||
expect(s.relations.taskIdsByColumn.TO_DO).toEqual([])
|
||||
expect(s.relations.taskIdsByColumn.DONE).toEqual(['task-1'])
|
||||
})
|
||||
|
||||
it('resynct actieve scopes via de solo-workspace route', async () => {
|
||||
useSoloStore.getState().hydrateSnapshot(snapshot([baseTask('task-1')]))
|
||||
const next = snapshot([baseTask('task-1', { status: 'IN_PROGRESS' })])
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(next), { status: 200 }),
|
||||
)
|
||||
|
||||
await useSoloStore.getState().resyncActiveScopes('manual')
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalledWith(
|
||||
'/api/products/prod-1/solo-workspace?sprint_id=sprint-1',
|
||||
expect.objectContaining({ cache: 'no-store' }),
|
||||
)
|
||||
const s = useSoloStore.getState()
|
||||
expect(s.tasks['task-1'].status).toBe('IN_PROGRESS')
|
||||
expect(s.sync.resyncReason).toBe('manual')
|
||||
})
|
||||
})
|
||||
|
|
@ -96,7 +96,7 @@ function makeStory(
|
|||
acceptance_criteria: overrides.acceptance_criteria ?? null,
|
||||
priority: overrides.priority ?? 2,
|
||||
sort_order: overrides.sort_order ?? 1,
|
||||
status: overrides.status ?? 'open',
|
||||
status: overrides.status ?? 'OPEN',
|
||||
pbi_id: overrides.pbi_id,
|
||||
sprint_id: overrides.sprint_id ?? null,
|
||||
created_at: overrides.created_at ?? new Date('2026-01-01'),
|
||||
|
|
@ -113,7 +113,7 @@ function makeTask(
|
|||
description: overrides.description ?? null,
|
||||
priority: overrides.priority ?? 2,
|
||||
sort_order: overrides.sort_order ?? 1,
|
||||
status: overrides.status ?? 'todo',
|
||||
status: overrides.status ?? 'TO_DO',
|
||||
story_id: overrides.story_id,
|
||||
sprint_id: overrides.sprint_id ?? null,
|
||||
created_at: overrides.created_at ?? new Date('2026-01-01'),
|
||||
|
|
@ -174,6 +174,20 @@ describe('hydrateSnapshot', () => {
|
|||
expect(s.context.activeProduct).toEqual({ id: 'prod-1', name: 'Product 1' })
|
||||
expect(s.loading.loadedSprintIds['sp-1']).toBe(true)
|
||||
})
|
||||
|
||||
it('normaliseert API-statussen naar het interne store-contract', () => {
|
||||
useSprintWorkspaceStore.getState().hydrateSnapshot(
|
||||
snapshotWith(
|
||||
makeSprint({ id: 'sp-1', product_id: 'prod-1' }),
|
||||
[makeStory({ id: 's-1', pbi_id: 'pbi-1', sprint_id: 'sp-1', status: 'in_sprint' })],
|
||||
{ 's-1': [makeTask({ id: 't-1', story_id: 's-1', status: 'todo' })] },
|
||||
),
|
||||
)
|
||||
|
||||
const s = useSprintWorkspaceStore.getState()
|
||||
expect(s.entities.storiesById['s-1'].status).toBe('IN_SPRINT')
|
||||
expect(s.entities.tasksById['t-1'].status).toBe('TO_DO')
|
||||
})
|
||||
})
|
||||
|
||||
describe('hydrateProductSprints', () => {
|
||||
|
|
@ -692,6 +706,7 @@ describe('ensureTaskLoaded — zet detail-flag', () => {
|
|||
't-1'
|
||||
] as SprintWorkspaceTaskDetail
|
||||
expect(task._detail).toBe(true)
|
||||
expect(task.status).toBe('TO_DO')
|
||||
expect(task.implementation_plan).toBe('detailed plan here')
|
||||
expect(useSprintWorkspaceStore.getState().loading.loadedTaskIds['t-1']).toBe(true)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue