-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducers.test.js
115 lines (102 loc) · 3.2 KB
/
reducers.test.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import '@testing-library/jest-dom'
import { restaurants } from './restaurants'
import { session } from './session'
import { initialStateTestData } from '../test-data'
describe('Reducers', () => {
let restaurantsTestData, sessionTestData, restaurantsState, sessionState
beforeEach(() => {
restaurantsState = []
sessionState = initialStateTestData.session
sessionTestData = {
searchApplied: true,
filteredRestaurants: ['1', '2'],
currentPageNumber: 1,
genreFilter: 'genre1',
stateFilter: 'state1',
attireFilter: 'attire1',
}
restaurantsTestData = initialStateTestData.restaurants
})
it('should return restaurants state with updated restaurants info', () => {
const action = {
type: 'FETCH_RESTAURANTS',
restaurantsSortedByName: restaurantsTestData,
}
const result = restaurants(restaurantsState, action)
expect(result).toEqual(restaurantsTestData)
})
it('should return session state with filtered restaurants info', () => {
const action = {
type: 'FILTER_RESTAURANTS',
filteredRestaurants: sessionTestData.filteredRestaurants,
}
const result = session(sessionState, action)
expect(result).toEqual({
...sessionState,
currentPageNumber: 1,
searchApplied: true,
filteredRestaurants: sessionTestData.filteredRestaurants,
})
})
it('should return session state with cleared searched', () => {
const action = {
type: 'CLEAR_SEARCH',
}
const result = session(
{ ...sessionState, genreFilter: sessionTestData.genreFilter },
action,
)
expect(result).toEqual({
...sessionState,
genreFilter: sessionTestData.genreFilter,
})
})
it('should return session state with cleared session info', () => {
const action = {
type: 'CLEAR_ALL',
}
const result = session(sessionTestData, action)
expect(result).toEqual(sessionState)
})
it('should return session state with updated current page number', () => {
const action = {
type: 'SET_CURRENT_PAGE_NUMBER',
currentPageNumber: 3,
}
const result = session(sessionState, action)
expect(result).toEqual({ ...sessionState, currentPageNumber: 3 })
})
it('should return session state with updated genre filter', () => {
const action = {
type: 'SET_GENRE_FILTER',
genreFilter: sessionTestData.genreFilter,
}
const result = session(sessionState, action)
expect(result).toEqual({
...sessionState,
genreFilter: sessionTestData.genreFilter,
})
})
it('should return session state with updated state filter', () => {
const action = {
type: 'SET_STATE_FILTER',
stateFilter: sessionTestData.stateFilter,
}
const result = session(sessionState, action)
expect(result).toEqual({
...sessionState,
stateFilter: sessionTestData.stateFilter,
})
})
it('should return session state with updated attire filter', () => {
const action = {
type: 'SET_ATTIRE_FILTER',
attireFilter: sessionTestData.attireFilter,
}
const result = session(sessionState, action)
expect(result).toEqual({
...sessionState,
attireFilter: sessionTestData.attireFilter,
})
})
})