forked from xcarpentier/rn-tourguide
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutilities.test.ts
175 lines (146 loc) · 4.79 KB
/
utilities.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { IStep } from './types'
import * as utilities from './utilities'
describe('getFirstStep', () => {
test('empty steps array', () => {
const firstStep = utilities.getFirstStep([])
expect(firstStep).toBe(null)
})
test('non-empty array', () => {
const steps = [
{ name: 'Step1', order: 0 },
{ name: 'Step2', order: 1 },
{ name: 'Step3', order: 2 },
]
const firstStep = utilities.getFirstStep(steps as IStep[])
expect(firstStep).toBe(steps[0])
})
test('using step.order instead of array index', () => {
const steps = [
{ name: 'Step3', order: 2 },
{ name: 'Step1', order: 0 },
{ name: 'Step2', order: 1 },
]
const firstStep = utilities.getFirstStep(steps as IStep[])
expect(firstStep).toBe(steps[1])
})
test('shuffled orders', () => {
const steps = [
{ name: 'Step3', order: 203 },
{ name: 'Step1', order: 100 },
{ name: 'Step2', order: 150 },
]
const firstStep = utilities.getFirstStep(steps as IStep[])
expect(firstStep).toBe(steps[1])
})
})
describe('getLastStep', () => {
test('empty steps array', () => {
const lastStep = utilities.getLastStep([])
expect(lastStep).toBe(null)
})
test('non-empty array', () => {
const steps = [
{ name: 'Step1', order: 0 },
{ name: 'Step2', order: 1 },
{ name: 'Step3', order: 2 },
]
const lastStep = utilities.getLastStep(steps as IStep[])
expect(lastStep).toBe(steps[2])
})
test('using step.order instead of array index', () => {
const steps = [
{ name: 'Step3', order: 2 },
{ name: 'Step1', order: 0 },
{ name: 'Step2', order: 1 },
]
const lastStep = utilities.getLastStep(steps as IStep[])
expect(lastStep).toBe(steps[0])
})
test('shuffled orders', () => {
const steps = [
{ name: 'Step3', order: 203 },
{ name: 'Step1', order: 100 },
{ name: 'Step2', order: 150 },
]
const lastStep = utilities.getLastStep(steps as IStep[])
expect(lastStep).toBe(steps[0])
})
})
describe('getStepNumber', () => {
test('empty steps array', () => {
const stepNumber = utilities.getStepNumber([], undefined)
expect(stepNumber).toBe(undefined)
})
test('non-empty steps array', () => {
const steps = [
{ name: 'Step1', order: 1 },
{ name: 'Step2', order: 2 },
{ name: 'Step3', order: 3 },
] as IStep[]
expect(utilities.getStepNumber(steps, steps[0])).toBe(1)
expect(utilities.getStepNumber(steps, steps[1])).toBe(2)
expect(utilities.getStepNumber(steps, steps[2])).toBe(3)
})
test('non-sequential step orders', () => {
const steps = [
{ name: 'Step2', order: 400 },
{ name: 'Step3', order: 670 },
{ name: 'Step1', order: 140 },
] as IStep[]
expect(utilities.getStepNumber(steps, steps[0])).toBe(2)
expect(utilities.getStepNumber(steps, steps[1])).toBe(3)
expect(utilities.getStepNumber(steps, steps[2])).toBe(1)
})
})
describe('getPrevStep', () => {
test('empty steps array', () => {
const prevStep = utilities.getPrevStep([], undefined)
expect(prevStep).toBe(null)
})
test('non-empty steps array', () => {
const steps = [
{ name: 'Step1', order: 1 },
{ name: 'Step2', order: 2 },
{ name: 'Step3', order: 3 },
] as IStep[]
expect(utilities.getPrevStep(steps, steps[0])).toBe(null)
expect(utilities.getPrevStep(steps, steps[1])).toBe(steps[0])
expect(utilities.getPrevStep(steps, steps[2])).toBe(steps[1])
})
test('non-sequential step orders', () => {
const steps = [
{ name: 'Step2', order: 400 },
{ name: 'Step3', order: 670 },
{ name: 'Step1', order: 140 },
] as IStep[]
expect(utilities.getPrevStep(steps, steps[0])).toBe(steps[2])
expect(utilities.getPrevStep(steps, steps[1])).toBe(steps[0])
expect(utilities.getPrevStep(steps, steps[2])).toBe(null)
})
})
describe('getNextStep', () => {
test('empty steps array', () => {
const nextStep = utilities.getNextStep([], undefined)
expect(nextStep).toBe(undefined)
})
test('non-empty steps array', () => {
const steps = [
{ name: 'Step1', order: 1 },
{ name: 'Step2', order: 2 },
{ name: 'Step3', order: 3 },
] as IStep[]
expect(utilities.getNextStep(steps, steps[0])).toBe(steps[1])
expect(utilities.getNextStep(steps, steps[1])).toBe(steps[2])
// expect(utilities.getNextStep(steps, steps[2])).toBe(null);
})
test('non-sequential step orders', () => {
const steps = [
{ name: 'Step2', order: 400 },
{ name: 'Step3', order: 670 },
{ name: 'Step1', order: 140 },
] as IStep[]
expect(utilities.getNextStep(steps, steps[0])).toBe(steps[1])
// expect(utilities.getNextStep(steps, steps[1])).toBe(null);
expect(utilities.getNextStep(steps, steps[2])).toBe(steps[0])
})
})