-
-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathkanban.test.ts
More file actions
93 lines (73 loc) · 2.31 KB
/
Copy pathkanban.test.ts
File metadata and controls
93 lines (73 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {beforeEach, describe, expect, it, vi} from 'vitest'
import {createPinia, setActivePinia} from 'pinia'
vi.mock('vue-router', () => ({
useRouter: () => ({push: vi.fn()}),
}))
vi.mock('vue-i18n', () => ({
useI18n: () => ({t: (key: string) => key}),
createI18n: () => ({global: {t: (key: string) => key}}),
}))
vi.mock('@/stores/base', () => ({
useBaseStore: () => ({
currentProject: null,
setCurrentProject: vi.fn(),
}),
}))
vi.mock('@/stores/auth', () => ({
useAuthStore: () => ({
authUser: true,
info: null,
}),
}))
import {useKanbanStore} from './kanban'
import type {IBucket} from '@/modelTypes/IBucket'
import type {ITask} from '@/modelTypes/ITask'
function makeBucket(id: number, title: string, tasks: ITask[] = []): IBucket {
return {
id,
title,
projectViewId: 1,
tasks,
count: tasks.length,
} as IBucket
}
function makeTask(id: number, bucketId: number): ITask {
return {
id,
title: `Task ${id}`,
bucketId,
} as ITask
}
describe('kanban store: moveTaskToBucket', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('relocates a task from its current bucket into the target bucket', () => {
const kanban = useKanbanStore()
kanban.setBuckets([makeBucket(1, 'To-Do'), makeBucket(2, 'Done')])
const task = makeTask(42, 2)
kanban.addTaskToBucket(task)
expect(kanban.buckets[1].tasks.map(t => t.id)).toEqual([42])
kanban.moveTaskToBucket(task, 1)
expect(kanban.buckets[0].tasks.map(t => t.id)).toEqual([42])
expect(kanban.buckets[0].tasks[0].bucketId).toBe(1)
expect(kanban.buckets[1].tasks.map(t => t.id)).toEqual([])
})
it('is a no-op when the task is already in the target bucket', () => {
const kanban = useKanbanStore()
kanban.setBuckets([makeBucket(1, 'To-Do'), makeBucket(2, 'Done')])
const task = makeTask(42, 1)
kanban.addTaskToBucket(task)
kanban.moveTaskToBucket(task, 1)
expect(kanban.buckets[0].tasks.map(t => t.id)).toEqual([42])
expect(kanban.buckets[1].tasks.map(t => t.id)).toEqual([])
})
it('is a no-op when the task is not present in any bucket', () => {
const kanban = useKanbanStore()
kanban.setBuckets([makeBucket(1, 'To-Do'), makeBucket(2, 'Done')])
const strayTask = makeTask(99, 2)
kanban.moveTaskToBucket(strayTask, 1)
expect(kanban.buckets[0].tasks).toEqual([])
expect(kanban.buckets[1].tasks).toEqual([])
})
})