-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTaskSectionList.test.tsx
More file actions
110 lines (93 loc) 路 3.05 KB
/
Copy pathTaskSectionList.test.tsx
File metadata and controls
110 lines (93 loc) 路 3.05 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { screen, within } from '@testing-library/react'
import { RootState } from '../../app/store'
import { testRender } from '../../testUtils'
import { DEFAULT_SECTIONS, GroupModel } from './tasks-slice'
import TaskSectionList from './TaskSectionList'
const defaultGroup: GroupModel = {
name: 'default group',
tasks: [
{
id: 'test-1',
description: 'Testing #1',
completed: false,
createdAt: new Date().toISOString(),
},
{
id: 'test-2',
description: 'Testing #2',
completed: false,
createdAt: new Date().toISOString(),
},
],
sections: [
{
id: 'open-tasks',
name: 'Open tasks',
},
{
id: 'completed-tasks',
name: 'Completed tasks',
},
],
}
it('renders the open tasks container', async () => {
testRender(<TaskSectionList group={defaultGroup} />)
const openTasksContainer = screen.getByTestId('open-tasks-section')
expect(openTasksContainer).toBeInTheDocument()
expect(openTasksContainer).toHaveTextContent('Open tasks')
const taskItems = within(openTasksContainer).getAllByTestId('task-item')
expect(taskItems).toHaveLength(2)
const completedTasksActions = screen.queryByTestId('completed-tasks-actions')
expect(completedTasksActions).not.toBeInTheDocument()
})
it('renders the completed tasks section', () => {
const groupWithCompletedTask = defaultGroup
groupWithCompletedTask.tasks.push({
id: 'test-3',
description: 'Testing #3',
completed: true,
createdAt: new Date().toISOString(),
})
testRender(<TaskSectionList group={groupWithCompletedTask} />)
const completedTasksSection = screen.getByTestId('completed-tasks-section')
expect(completedTasksSection).toBeInTheDocument()
expect(completedTasksSection).toHaveTextContent('Completed')
const taskItems = within(completedTasksSection).getAllByTestId('task-item')
expect(taskItems).toHaveLength(1)
const completedTasksActions = screen.getByTestId('completed-tasks-actions')
expect(completedTasksActions).toBeInTheDocument()
})
it('renders default sections', () => {
const defaultState: Partial<RootState> = {
settings: {
canEdit: true,
isRunningOnMobile: false,
spellCheckerEnabled: true,
},
tasks: {
schemaVersion: '1.0.0',
defaultSections: DEFAULT_SECTIONS,
groups: [],
},
}
const group: GroupModel = {
name: 'Test group',
tasks: [
...defaultGroup.tasks,
{
id: 'test-3',
description: 'Testing #3',
completed: true,
createdAt: new Date().toISOString(),
},
],
}
testRender(<TaskSectionList group={group} />, {}, defaultState)
const completedTasksSection = screen.getByTestId('completed-tasks-section')
expect(completedTasksSection).toBeInTheDocument()
expect(completedTasksSection).toHaveTextContent('Completed')
const taskItems = within(completedTasksSection).getAllByTestId('task-item')
expect(taskItems).toHaveLength(1)
const completedTasksActions = screen.getByTestId('completed-tasks-actions')
expect(completedTasksActions).toBeInTheDocument()
})