-
-
Notifications
You must be signed in to change notification settings - Fork 805
/
gitmojiList.spec.js
101 lines (81 loc) · 2.79 KB
/
gitmojiList.spec.js
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
import Router from 'next/router'
import renderer from 'react-test-renderer'
import GitmojiList from '../index'
import * as stubs from './stubs'
jest.mock('next/router', () => ({
query: {},
useRouter: jest.fn().mockImplementation(() => ({
query: {},
push: jest.fn(),
})),
}))
describe('GitmojiList', () => {
describe('when is not list mode', () => {
it('should render the component', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
expect(wrapper).toMatchSnapshot()
})
})
describe('when is list mode', () => {
it('should render the component', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
renderer.act(() => {
instance.findAllByType('button')[1].props.onClick()
})
expect(wrapper).toMatchSnapshot()
})
})
describe('when user search the fire gitmoji', () => {
beforeAll(() => {
Router.useRouter.mockReturnValue(stubs.routerMock())
})
it('should find the fire gitmoji by code', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
const query = 'Fire'
renderer.act(() => {
instance
.findByType('input')
.props.onChange({ target: { value: query } })
})
expect(instance.findAllByType('article').length).toEqual(1)
})
it('should find the fire gitmoji by description', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
const query = 'remove'
renderer.act(() => {
instance
.findByType('input')
.props.onChange({ target: { value: query } })
})
expect(instance.findAllByType('article').length).toEqual(1)
})
})
describe('when search is provided by query string', () => {
beforeAll(() => {
Router.useRouter.mockReturnValue(stubs.routerMock({ search: 'fire' }))
})
it('should set the search input value to query.search', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const query = 'fire'
renderer.act(() => {
wrapper.update(<GitmojiList {...stubs.props} />)
})
expect(wrapper.root.findByType('input').props.value).toEqual(query)
})
describe('when the user deletes the search input', () => {
it('should clear the query string', () => {
const wrapper = renderer.create(<GitmojiList {...stubs.props} />)
const instance = wrapper.root
renderer.act(() => {
instance.findByType('input').props.onChange({ target: { value: '' } })
})
expect(Router.useRouter().push).toHaveBeenCalledWith('/', undefined, {
shallow: true,
})
})
})
})
})