-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTask.test.js
More file actions
64 lines (58 loc) · 2.21 KB
/
Task.test.js
File metadata and controls
64 lines (58 loc) · 2.21 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
import '@testing-library/jest-dom/extend-expect'
import createSample from '../test-util/sample';
import {render} from '@testing-library/react';
import Task from './Task'
import userEvent from '@testing-library/user-event';
describe('task view', () => {
test('render profile and tasks', () => {
// given
const sample = createSample()
const profile = sample.profile()
const tasks = sample.taskArray({quantity: 3, profile})
const props = {
profile,
tasks,
taskName: '',
errors: [],
taskNameChanged: jest.fn(),
addTaskRequest: jest.fn(),
updateTaskRequest: jest.fn(),
deleteTasksRequest: jest.fn()
}
// when
const rendered = render(<Task {...props}/>)
// then
expect(rendered.getByText(`3 tasks in profile ${profile.name}`)).toBeInTheDocument()
expect(rendered.getByText(tasks[0].name)).toBeInTheDocument()
expect(rendered.queryByText(tasks[1].name)).toBeInTheDocument()
expect(rendered.getByText(tasks[2].name)).toBeInTheDocument()
})
test('task name changed function invoked when typing', () => {
// given
const sample = createSample()
const profile = sample.profile()
const tasks = sample.taskArray({quantity: 3, profile})
const taskNameChanged = jest.fn()
const shouldNotBeCalled = name => () => {
throw Error(`should not have called function ${name}`)
}
const props = {
profile,
tasks,
taskName: '',
errors: [],
taskNameChanged,
addTaskRequest: shouldNotBeCalled('addTaskRequest'),
updateTaskRequest: shouldNotBeCalled('updateTaskRequest'),
deleteTasksRequest: shouldNotBeCalled('deleteTasksRequest')
}
const rendered = render(<Task {...props}/>)
const taskNameDataEntry = rendered.getByPlaceholderText('task name')
// when
userEvent.type(taskNameDataEntry, 'the-name')
// then
expect(taskNameChanged.mock.calls).toEqual([
['t'], ['h'], ['e'], ['-'], ['n'], ['a'], ['m'], ['e']
])
})
})