修复 WUI Kanban 看板选择与隔离 (#594)
* fix: add explicit kanban board selection * fix: tighten kanban board counts and management
This commit is contained in:
@@ -8,7 +8,12 @@ vi.mock('../../packages/client/src/api/client', () => ({
|
||||
}))
|
||||
|
||||
import {
|
||||
listBoards,
|
||||
createBoard,
|
||||
archiveBoard,
|
||||
getCapabilities,
|
||||
listTasks,
|
||||
getTask,
|
||||
createTask,
|
||||
completeTasks,
|
||||
blockTask,
|
||||
@@ -23,16 +28,36 @@ describe('Kanban API', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('serializes list filters into query params', async () => {
|
||||
it('serializes board and list filters into query params', async () => {
|
||||
mockRequest.mockResolvedValue({ tasks: [{ id: 'task-1' }] })
|
||||
|
||||
const result = await listTasks({ status: 'blocked', assignee: 'alice', tenant: 'ops' })
|
||||
const result = await listTasks({ board: 'default', status: 'blocked', assignee: 'alice', tenant: 'ops' })
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban?status=blocked&assignee=alice&tenant=ops')
|
||||
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban?board=default&status=blocked&assignee=alice&tenant=ops')
|
||||
expect(result).toEqual([{ id: 'task-1' }])
|
||||
})
|
||||
|
||||
it('posts create and action payloads in the expected shape', async () => {
|
||||
it('keeps default board explicit when no board is supplied', async () => {
|
||||
mockRequest
|
||||
.mockResolvedValueOnce({ tasks: [] })
|
||||
.mockResolvedValueOnce({ stats: { total: 0, by_status: {}, by_assignee: {} } })
|
||||
.mockResolvedValueOnce({ assignees: [] })
|
||||
.mockResolvedValueOnce({ task: { id: 'task-1' }, comments: [], events: [], runs: [] })
|
||||
|
||||
await listTasks()
|
||||
await getStats()
|
||||
await getAssignees()
|
||||
await getTask('task-1')
|
||||
|
||||
expect(mockRequest.mock.calls.map(call => call[0])).toEqual([
|
||||
'/api/hermes/kanban?board=default',
|
||||
'/api/hermes/kanban/stats?board=default',
|
||||
'/api/hermes/kanban/assignees?board=default',
|
||||
'/api/hermes/kanban/task-1?board=default',
|
||||
])
|
||||
})
|
||||
|
||||
it('posts create and action payloads with explicit board in the URL', async () => {
|
||||
mockRequest
|
||||
.mockResolvedValueOnce({ task: { id: 'task-1' } })
|
||||
.mockResolvedValueOnce({ ok: true })
|
||||
@@ -40,27 +65,44 @@ describe('Kanban API', () => {
|
||||
.mockResolvedValueOnce({ ok: true })
|
||||
.mockResolvedValueOnce({ ok: true })
|
||||
|
||||
expect(await createTask({ title: 'Ship', assignee: 'alice', priority: 3 })).toEqual({ id: 'task-1' })
|
||||
await completeTasks(['task-1'], 'done')
|
||||
await blockTask('task-1', 'waiting')
|
||||
await unblockTasks(['task-1'])
|
||||
await assignTask('task-1', 'bob')
|
||||
expect(await createTask({ title: 'Ship', assignee: 'alice', priority: 3 }, { board: 'project-a' })).toEqual({ id: 'task-1' })
|
||||
await completeTasks(['task-1'], 'done', { board: 'project-a' })
|
||||
await blockTask('task-1', 'waiting', { board: 'project-a' })
|
||||
await unblockTasks(['task-1'], { board: 'project-a' })
|
||||
await assignTask('task-1', 'bob', { board: 'project-a' })
|
||||
|
||||
expect(mockRequest.mock.calls).toEqual([
|
||||
['/api/hermes/kanban', { method: 'POST', body: JSON.stringify({ title: 'Ship', assignee: 'alice', priority: 3 }) }],
|
||||
['/api/hermes/kanban/complete', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'], summary: 'done' }) }],
|
||||
['/api/hermes/kanban/task-1/block', { method: 'POST', body: JSON.stringify({ reason: 'waiting' }) }],
|
||||
['/api/hermes/kanban/unblock', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'] }) }],
|
||||
['/api/hermes/kanban/task-1/assign', { method: 'POST', body: JSON.stringify({ profile: 'bob' }) }],
|
||||
['/api/hermes/kanban?board=project-a', { method: 'POST', body: JSON.stringify({ title: 'Ship', assignee: 'alice', priority: 3 }) }],
|
||||
['/api/hermes/kanban/complete?board=project-a', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'], summary: 'done' }) }],
|
||||
['/api/hermes/kanban/task-1/block?board=project-a', { method: 'POST', body: JSON.stringify({ reason: 'waiting' }) }],
|
||||
['/api/hermes/kanban/unblock?board=project-a', { method: 'POST', body: JSON.stringify({ task_ids: ['task-1'] }) }],
|
||||
['/api/hermes/kanban/task-1/assign?board=project-a', { method: 'POST', body: JSON.stringify({ profile: 'bob' }) }],
|
||||
])
|
||||
})
|
||||
|
||||
it('unwraps stats and assignee response envelopes', async () => {
|
||||
it('lists and manages boards through explicit board endpoints', async () => {
|
||||
mockRequest
|
||||
.mockResolvedValueOnce({ boards: [{ slug: 'default' }] })
|
||||
.mockResolvedValueOnce({ board: { slug: 'project-a' } })
|
||||
.mockResolvedValueOnce({ ok: true })
|
||||
.mockResolvedValueOnce({ capabilities: { source: 'hermes-cli', supports: { boardsList: true }, missing: [] } })
|
||||
.mockResolvedValueOnce({ stats: { total: 3, by_status: {}, by_assignee: {} } })
|
||||
.mockResolvedValueOnce({ assignees: [{ name: 'alice', on_disk: true, counts: { todo: 1 } }] })
|
||||
|
||||
await expect(getStats()).resolves.toEqual({ total: 3, by_status: {}, by_assignee: {} })
|
||||
await expect(getAssignees()).resolves.toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
|
||||
await expect(listBoards({ includeArchived: true })).resolves.toEqual([{ slug: 'default' }])
|
||||
await expect(createBoard({ slug: 'project-a', name: 'Project A' })).resolves.toEqual({ slug: 'project-a' })
|
||||
await expect(archiveBoard('project-a')).resolves.toEqual({ ok: true })
|
||||
await expect(getCapabilities()).resolves.toEqual({ source: 'hermes-cli', supports: { boardsList: true }, missing: [] })
|
||||
await expect(getStats({ board: 'project-a' })).resolves.toEqual({ total: 3, by_status: {}, by_assignee: {} })
|
||||
await expect(getAssignees({ board: 'project-a' })).resolves.toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
|
||||
|
||||
expect(mockRequest.mock.calls).toEqual([
|
||||
['/api/hermes/kanban/boards?includeArchived=true'],
|
||||
['/api/hermes/kanban/boards', { method: 'POST', body: JSON.stringify({ slug: 'project-a', name: 'Project A' }) }],
|
||||
['/api/hermes/kanban/boards/project-a', { method: 'DELETE' }],
|
||||
['/api/hermes/kanban/capabilities'],
|
||||
['/api/hermes/kanban/stats?board=project-a'],
|
||||
['/api/hermes/kanban/assignees?board=project-a'],
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
|
||||
const mockKanbanApi = vi.hoisted(() => ({
|
||||
listBoards: vi.fn(),
|
||||
createBoard: vi.fn(),
|
||||
archiveBoard: vi.fn(),
|
||||
getCapabilities: vi.fn(),
|
||||
listTasks: vi.fn(),
|
||||
getStats: vi.fn(),
|
||||
getAssignees: vi.fn(),
|
||||
@@ -15,20 +19,43 @@ const mockKanbanApi = vi.hoisted(() => ({
|
||||
|
||||
vi.mock('@/api/hermes/kanban', () => mockKanbanApi)
|
||||
|
||||
import { useKanbanStore } from '@/stores/hermes/kanban'
|
||||
import { KANBAN_SELECTED_BOARD_STORAGE_KEY, useKanbanStore } from '@/stores/hermes/kanban'
|
||||
|
||||
describe('Kanban store', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear()
|
||||
setActivePinia(createPinia())
|
||||
vi.clearAllMocks()
|
||||
mockKanbanApi.listBoards.mockResolvedValue([
|
||||
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
|
||||
{ slug: 'project-a', name: 'Project A', archived: false, counts: { todo: 1 }, total: 1 },
|
||||
])
|
||||
mockKanbanApi.getCapabilities.mockResolvedValue({ source: 'hermes-cli', supports: { boardsList: true }, missing: [] })
|
||||
})
|
||||
|
||||
it('fetchTasks uses active filters and updates loading', async () => {
|
||||
it('persists selected board, including default, and falls back to default for missing boards', async () => {
|
||||
const store = useKanbanStore()
|
||||
await store.fetchBoards()
|
||||
|
||||
expect(store.setSelectedBoard('project-a')).toBe('project-a')
|
||||
expect(window.localStorage.getItem(KANBAN_SELECTED_BOARD_STORAGE_KEY)).toBe('project-a')
|
||||
|
||||
expect(store.setSelectedBoard('default')).toBe('default')
|
||||
expect(window.localStorage.getItem(KANBAN_SELECTED_BOARD_STORAGE_KEY)).toBe('default')
|
||||
|
||||
const recovered = store.recoverSelectedBoard('missing-board')
|
||||
expect(recovered).toEqual({ board: 'default', recovered: true })
|
||||
expect(store.selectedBoard).toBe('default')
|
||||
expect(store.boardWarning).toContain('missing-board')
|
||||
})
|
||||
|
||||
it('fetchTasks uses active filters and selected board while updating loading', async () => {
|
||||
mockKanbanApi.listTasks.mockImplementation(
|
||||
() => new Promise(resolve => setTimeout(() => resolve([{ id: 'task-1', status: 'todo' }]), 0))
|
||||
)
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('project-a')
|
||||
store.setFilter('status', 'blocked')
|
||||
store.setFilter('assignee', 'alice')
|
||||
const promise = store.fetchTasks()
|
||||
@@ -36,20 +63,22 @@ describe('Kanban store', () => {
|
||||
expect(store.loading).toBe(true)
|
||||
await promise
|
||||
|
||||
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ status: 'blocked', assignee: 'alice' })
|
||||
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: 'blocked', assignee: 'alice' })
|
||||
expect(store.tasks).toEqual([{ id: 'task-1', status: 'todo' }])
|
||||
expect(store.loading).toBe(false)
|
||||
})
|
||||
|
||||
it('create and status actions update local task state and refresh stats', async () => {
|
||||
it('create and status actions pass selected board, update local task state, and refresh board counts', async () => {
|
||||
mockKanbanApi.createTask.mockResolvedValue({ id: 'task-2', status: 'todo', assignee: null })
|
||||
mockKanbanApi.completeTasks.mockResolvedValue({ ok: true })
|
||||
mockKanbanApi.blockTask.mockResolvedValue({ ok: true })
|
||||
mockKanbanApi.unblockTasks.mockResolvedValue({ ok: true })
|
||||
mockKanbanApi.assignTask.mockResolvedValue({ ok: true })
|
||||
mockKanbanApi.getStats.mockResolvedValue({ total: 2, by_status: { done: 1 }, by_assignee: {} })
|
||||
mockKanbanApi.getAssignees.mockResolvedValue([{ name: 'bob', on_disk: true, counts: { ready: 1 } }])
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('project-a')
|
||||
store.tasks = [{ id: 'task-1', status: 'running', assignee: null }] as any
|
||||
|
||||
await store.createTask({ title: 'Ship' })
|
||||
@@ -58,21 +87,125 @@ describe('Kanban store', () => {
|
||||
await store.unblockTasks(['task-2'])
|
||||
await store.assignTask('task-2', 'bob')
|
||||
|
||||
expect(mockKanbanApi.createTask).toHaveBeenCalledWith({ title: 'Ship' }, { board: 'project-a' })
|
||||
expect(mockKanbanApi.completeTasks).toHaveBeenCalledWith(['task-1'], 'done', { board: 'project-a' })
|
||||
expect(mockKanbanApi.blockTask).toHaveBeenCalledWith('task-2', 'waiting', { board: 'project-a' })
|
||||
expect(mockKanbanApi.unblockTasks).toHaveBeenCalledWith(['task-2'], { board: 'project-a' })
|
||||
expect(mockKanbanApi.assignTask).toHaveBeenCalledWith('task-2', 'bob', { board: 'project-a' })
|
||||
expect(mockKanbanApi.listBoards).toHaveBeenCalledTimes(4)
|
||||
expect(mockKanbanApi.getAssignees).toHaveBeenCalledWith({ board: 'project-a' })
|
||||
expect(store.tasks[0]).toMatchObject({ id: 'task-2', status: 'ready', assignee: 'bob' })
|
||||
expect(store.tasks[1]).toMatchObject({ id: 'task-1', status: 'done' })
|
||||
expect(mockKanbanApi.getStats).toHaveBeenCalledTimes(4)
|
||||
})
|
||||
|
||||
it('refreshAll loads tasks, stats, and assignees together', async () => {
|
||||
it('creates and archives boards without relying on CLI current board', async () => {
|
||||
mockKanbanApi.listBoards.mockResolvedValue([
|
||||
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
|
||||
{ slug: 'new-board', name: 'New Board', archived: false, counts: {}, total: 0 },
|
||||
])
|
||||
mockKanbanApi.createBoard.mockResolvedValue({ slug: 'new-board', name: 'New Board', archived: false, counts: {}, total: 0 })
|
||||
mockKanbanApi.archiveBoard.mockResolvedValue({ ok: true })
|
||||
mockKanbanApi.listTasks.mockResolvedValue([])
|
||||
mockKanbanApi.getStats.mockResolvedValue({ total: 0, by_status: {}, by_assignee: {} })
|
||||
mockKanbanApi.getAssignees.mockResolvedValue([])
|
||||
|
||||
const store = useKanbanStore()
|
||||
await store.createBoard({ slug: 'new-board', name: 'New Board' })
|
||||
expect(mockKanbanApi.createBoard).toHaveBeenCalledWith({ slug: 'new-board', name: 'New Board' })
|
||||
expect(store.selectedBoard).toBe('new-board')
|
||||
|
||||
await store.archiveSelectedBoard()
|
||||
expect(mockKanbanApi.archiveBoard).toHaveBeenCalledWith('new-board')
|
||||
expect(store.selectedBoard).toBe('default')
|
||||
})
|
||||
|
||||
it('refreshAll loads boards, tasks, stats, and assignees for the same board', async () => {
|
||||
mockKanbanApi.listTasks.mockResolvedValue([{ id: 'task-1' }])
|
||||
mockKanbanApi.getStats.mockResolvedValue({ total: 1, by_status: {}, by_assignee: {} })
|
||||
mockKanbanApi.getAssignees.mockResolvedValue([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('project-a')
|
||||
await store.refreshAll()
|
||||
|
||||
expect(mockKanbanApi.listTasks).toHaveBeenCalledWith({ board: 'project-a', status: undefined, assignee: undefined })
|
||||
expect(mockKanbanApi.getStats).toHaveBeenCalledWith({ board: 'project-a' })
|
||||
expect(mockKanbanApi.getAssignees).toHaveBeenCalledWith({ board: 'project-a' })
|
||||
expect(mockKanbanApi.listBoards).toHaveBeenCalledWith({ includeArchived: false })
|
||||
expect(store.tasks).toEqual([{ id: 'task-1' }])
|
||||
expect(store.stats).toEqual({ total: 1, by_status: {}, by_assignee: {} })
|
||||
expect(store.assignees).toEqual([{ name: 'alice', on_disk: true, counts: { todo: 1 } }])
|
||||
})
|
||||
|
||||
it('ignores stale board-list responses after a newer request', async () => {
|
||||
let resolveSlowBoards: (value: unknown) => void = () => {}
|
||||
mockKanbanApi.listBoards
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveSlowBoards = resolve }))
|
||||
.mockResolvedValueOnce([
|
||||
{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 },
|
||||
{ slug: 'project-a', name: 'Project A', archived: false, counts: { todo: 2 }, total: 2 },
|
||||
])
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('project-a')
|
||||
const slowFetch = store.fetchBoards()
|
||||
await store.fetchBoards()
|
||||
resolveSlowBoards([{ slug: 'default', name: 'Default', archived: false, counts: {}, total: 0 }])
|
||||
await slowFetch
|
||||
|
||||
expect(store.selectedBoard).toBe('project-a')
|
||||
expect(store.activeBoards).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ slug: 'project-a', total: 2 }),
|
||||
]))
|
||||
})
|
||||
|
||||
it('ignores stale same-board fetch responses after a newer request', async () => {
|
||||
let resolveSlow: (value: unknown) => void = () => {}
|
||||
mockKanbanApi.listTasks
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveSlow = resolve }))
|
||||
.mockResolvedValueOnce([{ id: 'new-filter-task' }])
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('project-a')
|
||||
const slowFetch = store.fetchTasks()
|
||||
await store.fetchTasks()
|
||||
resolveSlow([{ id: 'old-filter-task' }])
|
||||
await slowFetch
|
||||
|
||||
expect(store.tasks).toEqual([{ id: 'new-filter-task' }])
|
||||
})
|
||||
|
||||
it('does not leave loading stuck when a silent fetch supersedes a visible fetch', async () => {
|
||||
let resolveVisible: (value: unknown) => void = () => {}
|
||||
mockKanbanApi.listTasks
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveVisible = resolve }))
|
||||
.mockResolvedValueOnce([{ id: 'silent-task' }])
|
||||
|
||||
const store = useKanbanStore()
|
||||
const visibleFetch = store.fetchTasks()
|
||||
expect(store.loading).toBe(true)
|
||||
await store.fetchTasks(true)
|
||||
resolveVisible([{ id: 'visible-task' }])
|
||||
await visibleFetch
|
||||
|
||||
expect(store.tasks).toEqual([{ id: 'silent-task' }])
|
||||
expect(store.loading).toBe(false)
|
||||
})
|
||||
|
||||
it('ignores stale fetch responses after a board switch', async () => {
|
||||
let resolveSlow: (value: unknown) => void = () => {}
|
||||
mockKanbanApi.listTasks
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveSlow = resolve }))
|
||||
.mockResolvedValueOnce([{ id: 'new-board-task' }])
|
||||
|
||||
const store = useKanbanStore()
|
||||
store.setSelectedBoard('default')
|
||||
const slowFetch = store.fetchTasks()
|
||||
store.setSelectedBoard('project-a')
|
||||
await store.fetchTasks()
|
||||
resolveSlow([{ id: 'old-board-task' }])
|
||||
await slowFetch
|
||||
|
||||
expect(store.tasks).toEqual([{ id: 'new-board-task' }])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -37,6 +37,7 @@ vi.mock('@/api/hermes/kanban', () => ({
|
||||
|
||||
vi.mock('@/stores/hermes/kanban', () => ({
|
||||
useKanbanStore: () => ({
|
||||
selectedBoard: 'project-a',
|
||||
assignees: [{ name: 'alice', counts: { todo: 1 } }, { name: 'bob', counts: { ready: 1 } }],
|
||||
completeTasks: mockCompleteTasks,
|
||||
blockTask: mockBlockTask,
|
||||
@@ -198,7 +199,7 @@ describe('KanbanTaskDrawer', () => {
|
||||
await sessionsTitle?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban/search-sessions?task_id=task-2&profile=fresh')
|
||||
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/kanban/search-sessions?task_id=task-2&profile=fresh&board=project-a')
|
||||
await wrapper.find('.session-item').trigger('click')
|
||||
expect(mockRouterPush).toHaveBeenCalledWith({ name: 'hermes.chat', query: { session: 'session-2' } })
|
||||
})
|
||||
|
||||
@@ -3,19 +3,40 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent } from 'vue'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
|
||||
const routeState = vi.hoisted(() => ({
|
||||
query: { board: 'project-a' } as Record<string, string>,
|
||||
}))
|
||||
|
||||
const routerReplace = vi.hoisted(() => vi.fn())
|
||||
|
||||
const storeState = vi.hoisted(() => ({
|
||||
tasks: [] as Array<{ id: string; title: string; status: string; created_at: number }>,
|
||||
stats: { by_status: { todo: 1, done: 0 }, by_assignee: {}, total: 1 } as Record<string, any>,
|
||||
assignees: [] as Array<{ name: string; counts: Record<string, number> | null }>,
|
||||
activeBoards: [] as Array<{ slug: string; name: string; icon?: string; total?: number }>,
|
||||
loading: false,
|
||||
boardsLoading: false,
|
||||
selectedBoard: 'default',
|
||||
boardWarning: null as string | null,
|
||||
capabilities: null as Record<string, any> | null,
|
||||
filterStatus: null as string | null,
|
||||
filterAssignee: null as string | null,
|
||||
}))
|
||||
|
||||
const mockFetchBoards = vi.hoisted(() => vi.fn())
|
||||
const mockFetchCapabilities = vi.hoisted(() => vi.fn())
|
||||
const mockRefreshAll = vi.hoisted(() => vi.fn())
|
||||
const mockFetchTasks = vi.hoisted(() => vi.fn())
|
||||
const mockFetchStats = vi.hoisted(() => vi.fn())
|
||||
const mockSetFilter = vi.hoisted(() => vi.fn())
|
||||
const mockRecoverSelectedBoard = vi.hoisted(() => vi.fn())
|
||||
const mockCreateBoard = vi.hoisted(() => vi.fn())
|
||||
const mockArchiveSelectedBoard = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('vue-router', () => ({
|
||||
useRoute: () => routeState,
|
||||
useRouter: () => ({ replace: routerReplace }),
|
||||
}))
|
||||
|
||||
vi.mock('vue-i18n', () => ({
|
||||
useI18n: () => ({
|
||||
@@ -24,12 +45,18 @@ vi.mock('vue-i18n', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/hermes/kanban', () => ({
|
||||
DEFAULT_KANBAN_BOARD: 'default',
|
||||
useKanbanStore: () => ({
|
||||
...storeState,
|
||||
fetchBoards: mockFetchBoards,
|
||||
fetchCapabilities: mockFetchCapabilities,
|
||||
refreshAll: mockRefreshAll,
|
||||
fetchTasks: mockFetchTasks,
|
||||
fetchStats: mockFetchStats,
|
||||
setFilter: mockSetFilter,
|
||||
recoverSelectedBoard: mockRecoverSelectedBoard,
|
||||
createBoard: mockCreateBoard,
|
||||
archiveSelectedBoard: mockArchiveSelectedBoard,
|
||||
}),
|
||||
}))
|
||||
|
||||
@@ -58,6 +85,7 @@ vi.mock('@/components/hermes/kanban/KanbanCreateForm.vue', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('naive-ui', () => ({
|
||||
useMessage: () => ({ warning: vi.fn(), error: vi.fn(), success: vi.fn() }),
|
||||
NButton: defineComponent({
|
||||
name: 'NButton',
|
||||
emits: ['click'],
|
||||
@@ -65,9 +93,21 @@ vi.mock('naive-ui', () => ({
|
||||
}),
|
||||
NSelect: defineComponent({
|
||||
name: 'NSelect',
|
||||
props: { value: null, options: { type: Array, default: () => [] } },
|
||||
props: { value: null, options: { type: Array, default: () => [] }, loading: Boolean },
|
||||
emits: ['update:value'],
|
||||
template: '<div class="n-select-stub"></div>',
|
||||
template: '<button class="n-select-stub" @click="$emit(\'update:value\', options[1]?.value || value)"><span v-for="option in options" :key="option.value">{{ option.label }}</span>{{ value }}</button>',
|
||||
}),
|
||||
NInput: defineComponent({
|
||||
name: 'NInput',
|
||||
props: { value: { type: String, default: '' }, placeholder: { type: String, required: false } },
|
||||
emits: ['update:value'],
|
||||
template: '<input class="n-input-stub" :placeholder="placeholder" :value="value" @input="$emit(\'update:value\', $event.target.value)" />',
|
||||
}),
|
||||
NModal: defineComponent({
|
||||
name: 'NModal',
|
||||
props: { show: Boolean },
|
||||
emits: ['update:show', 'close'],
|
||||
template: '<div v-if="show" class="n-modal-stub"><slot /><slot name="action" /></div>',
|
||||
}),
|
||||
NSpin: defineComponent({
|
||||
name: 'NSpin',
|
||||
@@ -91,6 +131,8 @@ describe('KanbanView', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.clearAllMocks()
|
||||
routeState.query = { board: 'project-a' }
|
||||
routerReplace.mockResolvedValue(undefined)
|
||||
storeState.tasks = [
|
||||
{ id: 'task-1', title: 'Task one', status: 'todo', created_at: 10 },
|
||||
{ id: 'task-2', title: 'Task two', status: 'done', created_at: 20 },
|
||||
@@ -101,12 +143,28 @@ describe('KanbanView', () => {
|
||||
total: 2,
|
||||
}
|
||||
storeState.assignees = []
|
||||
storeState.activeBoards = [
|
||||
{ slug: 'default', name: 'Default', total: 0 },
|
||||
{ slug: 'project-a', name: 'Project A', total: 2 },
|
||||
]
|
||||
storeState.loading = false
|
||||
storeState.boardsLoading = false
|
||||
storeState.selectedBoard = 'default'
|
||||
storeState.boardWarning = null
|
||||
storeState.capabilities = null
|
||||
storeState.filterStatus = null
|
||||
storeState.filterAssignee = null
|
||||
mockFetchBoards.mockResolvedValue(undefined)
|
||||
mockFetchCapabilities.mockResolvedValue(undefined)
|
||||
mockRefreshAll.mockResolvedValue(undefined)
|
||||
mockFetchTasks.mockResolvedValue(undefined)
|
||||
mockFetchStats.mockResolvedValue(undefined)
|
||||
mockCreateBoard.mockResolvedValue({ slug: 'new-board' })
|
||||
mockArchiveSelectedBoard.mockResolvedValue(undefined)
|
||||
mockRecoverSelectedBoard.mockImplementation((candidate: string) => {
|
||||
storeState.selectedBoard = candidate || 'default'
|
||||
return { board: storeState.selectedBoard, recovered: false }
|
||||
})
|
||||
mockSetFilter.mockImplementation((key: 'status' | 'assignee', value: string | null) => {
|
||||
if (key === 'status') storeState.filterStatus = value
|
||||
else storeState.filterAssignee = value
|
||||
@@ -117,11 +175,15 @@ describe('KanbanView', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('starts with collapsed panels and refreshes stats alongside tasks', async () => {
|
||||
it('initializes board from route query and refreshes stats alongside tasks', async () => {
|
||||
const wrapper = mount(KanbanView)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockFetchBoards).toHaveBeenCalledOnce()
|
||||
expect(mockFetchCapabilities).toHaveBeenCalledOnce()
|
||||
expect(mockRecoverSelectedBoard).toHaveBeenCalledWith('project-a')
|
||||
expect(mockRefreshAll).toHaveBeenCalledOnce()
|
||||
expect(routerReplace).not.toHaveBeenCalled()
|
||||
expect(wrapper.find('.n-collapse-stub').attributes('data-default-expanded')).toBe('null')
|
||||
|
||||
await wrapper.find('.drawer-updated').trigger('click')
|
||||
@@ -131,7 +193,56 @@ describe('KanbanView', () => {
|
||||
await vi.advanceTimersByTimeAsync(15000)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockFetchBoards).toHaveBeenCalledTimes(2)
|
||||
expect(mockFetchTasks).toHaveBeenCalledTimes(2)
|
||||
expect(mockFetchStats).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('renders board and assignee count labels with explicit context', async () => {
|
||||
storeState.assignees = [{ name: 'alice', counts: { todo: 2, done: 1 } }]
|
||||
const wrapper = mount(KanbanView)
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('kanban.title: Default · kanban.stats.tasks: 0')
|
||||
expect(wrapper.text()).toContain('kanban.title: Project A · kanban.stats.tasks: 2')
|
||||
expect(wrapper.text()).toContain('kanban.detail.assignee: alice · kanban.stats.tasks: 3')
|
||||
})
|
||||
|
||||
it('creates and archives boards from the board toolbar', async () => {
|
||||
storeState.selectedBoard = 'project-a'
|
||||
const wrapper = mount(KanbanView)
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.findAll('.n-button-stub')[0].trigger('click')
|
||||
await flushPromises()
|
||||
const inputs = wrapper.findAll('.n-input-stub')
|
||||
await inputs[0].setValue('new-board')
|
||||
await inputs[1].setValue('New Board')
|
||||
await wrapper.findAll('.n-button-stub').at(-1)!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(mockCreateBoard).toHaveBeenCalledWith({ slug: 'new-board', name: 'New Board' })
|
||||
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'new-board' } })
|
||||
|
||||
vi.spyOn(window, 'confirm').mockReturnValueOnce(true)
|
||||
await wrapper.findAll('.n-button-stub')[1].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(mockArchiveSelectedBoard).toHaveBeenCalled()
|
||||
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'default' } })
|
||||
})
|
||||
|
||||
it('makes default board explicit when route query is absent', async () => {
|
||||
routeState.query = {}
|
||||
mockRecoverSelectedBoard.mockImplementation(() => {
|
||||
storeState.selectedBoard = 'default'
|
||||
return { board: 'default', recovered: false }
|
||||
})
|
||||
|
||||
mount(KanbanView)
|
||||
await flushPromises()
|
||||
|
||||
expect(routerReplace).toHaveBeenCalledWith({ query: { board: 'default' } })
|
||||
expect(mockRefreshAll).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user