This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
breadcrumbs-slice.test.ts
60 lines (47 loc) · 1.86 KB
/
breadcrumbs-slice.test.ts
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
import '../../__mocks__/matchMediaMock'
import { AnyAction } from 'redux'
import breadcrumbs, { addBreadcrumbs, removeBreadcrumbs } from '../../breadcrumbs/breadcrumbs-slice'
describe('breadcrumbs slice', () => {
describe('breadcrumbs reducer', () => {
it('should create the proper initial state with empty patients array', () => {
const breadcrumbsStore = breadcrumbs(undefined, {} as AnyAction)
expect(breadcrumbsStore.breadcrumbs).toEqual([])
})
it('should handle the ADD_BREADCRUMBS action', () => {
const breadcrumbsToAdd = [
{ text: 'user', location: '/user' },
{ text: 'Bob', location: '/user/1' },
]
const breadcrumbsStore = breadcrumbs(undefined, {
type: addBreadcrumbs.type,
payload: breadcrumbsToAdd,
})
expect(breadcrumbsStore.breadcrumbs).toEqual(breadcrumbsToAdd)
})
it('should handle the ADD_BREADCRUMBS action with existing breadcreumbs', () => {
const breadcrumbsToAdd = [{ text: 'Bob', location: '/user/1' }]
const state = {
breadcrumbs: [{ text: 'user', location: '/user' }],
}
const breadcrumbsStore = breadcrumbs(state, {
type: addBreadcrumbs.type,
payload: breadcrumbsToAdd,
})
expect(breadcrumbsStore.breadcrumbs).toEqual([...state.breadcrumbs, ...breadcrumbsToAdd])
})
it('should handle the REMOVE_BREADCRUMBS action', () => {
const breadcrumbsToRemove = [{ text: 'Bob', location: '/user/1' }]
const state = {
breadcrumbs: [
{ text: 'user', location: '/user' },
{ text: 'Bob', location: '/user/1' },
],
}
const breadcrumbsStore = breadcrumbs(state, {
type: removeBreadcrumbs.type,
payload: breadcrumbsToRemove,
})
expect(breadcrumbsStore.breadcrumbs).toEqual([{ text: 'user', location: '/user' }])
})
})
})