@@ -4,26 +4,30 @@ import { mount } from 'enzyme';
4
4
import { Button } from '@material-ui/core' ;
5
5
6
6
import { componentMapper , FormTemplate } from '../index' ;
7
- import WizardStep from '../files/wizard/wizard-step' ;
8
7
9
8
describe ( 'wizard' , ( ) => {
10
9
let initialProps ;
11
10
let schema ;
12
11
let onSubmit ;
12
+ let onCancel ;
13
13
14
14
beforeEach ( ( ) => {
15
15
schema = {
16
16
fields : [
17
17
{
18
18
component : componentTypes . WIZARD ,
19
19
name : 'wizard' ,
20
- title : 'A title' ,
21
- description : 'A description' ,
20
+ stepsInfo : [
21
+ {
22
+ title : 'AWS step'
23
+ } ,
24
+ {
25
+ title : 'Summary'
26
+ }
27
+ ] ,
22
28
fields : [
23
29
{
24
30
name : 'first-step' ,
25
- title : 'AWS step' ,
26
- description : 'This is a AWS step' ,
27
31
nextStep : 'summary' ,
28
32
fields : [
29
33
{
@@ -35,8 +39,6 @@ describe('wizard', () => {
35
39
} ,
36
40
{
37
41
name : 'summary' ,
38
- title : 'Summary' ,
39
- description : 'Review your progress' ,
40
42
fields : [
41
43
{
42
44
component : componentTypes . TEXTAREA ,
@@ -49,11 +51,13 @@ describe('wizard', () => {
49
51
]
50
52
} ;
51
53
onSubmit = jest . fn ( ) ;
54
+ onCancel = jest . fn ( ) ;
52
55
initialProps = {
53
56
componentMapper,
54
57
FormTemplate : ( props ) => < FormTemplate { ...props } showFormControls = { false } /> ,
55
58
schema,
56
- onSubmit : ( values ) => onSubmit ( values )
59
+ onSubmit : ( values ) => onSubmit ( values ) ,
60
+ onCancel : ( values ) => onCancel ( values )
57
61
} ;
58
62
} ) ;
59
63
@@ -62,21 +66,21 @@ describe('wizard', () => {
62
66
63
67
expect (
64
68
wrapper
65
- . find ( WizardStep )
66
- . find ( 'h5' )
69
+ . find ( '.MuiStepLabel-active' )
70
+ . first ( )
67
71
. text ( )
68
72
) . toEqual ( 'AWS step' ) ;
69
73
70
74
wrapper
71
75
. find ( Button )
72
76
. last ( )
73
- . simulate ( 'click' ) ;
77
+ . simulate ( 'click' ) ; // disabled next
74
78
wrapper . update ( ) ;
75
79
76
80
expect (
77
81
wrapper
78
- . find ( WizardStep )
79
- . find ( 'h5' )
82
+ . find ( '.MuiStepLabel-active' )
83
+ . first ( )
80
84
. text ( )
81
85
) . toEqual ( 'AWS step' ) ;
82
86
@@ -87,26 +91,26 @@ describe('wizard', () => {
87
91
wrapper
88
92
. find ( Button )
89
93
. last ( )
90
- . simulate ( 'click' ) ;
94
+ . simulate ( 'click' ) ; // next
91
95
wrapper . update ( ) ;
92
96
93
97
expect (
94
98
wrapper
95
- . find ( WizardStep )
96
- . find ( 'h5' )
99
+ . find ( '.MuiStepLabel-active' )
100
+ . first ( )
97
101
. text ( )
98
102
) . toEqual ( 'Summary' ) ;
99
103
100
104
wrapper
101
105
. find ( Button )
102
- . first ( )
103
- . simulate ( 'click' ) ;
106
+ . at ( 1 )
107
+ . simulate ( 'click' ) ; // back
104
108
wrapper . update ( ) ;
105
109
106
110
expect (
107
111
wrapper
108
- . find ( WizardStep )
109
- . find ( 'h5' )
112
+ . find ( '.MuiStepLabel-active' )
113
+ . first ( )
110
114
. text ( )
111
115
) . toEqual ( 'AWS step' ) ;
112
116
} ) ;
@@ -119,11 +123,17 @@ describe('wizard', () => {
119
123
name : 'wizard' ,
120
124
title : 'A title' ,
121
125
description : 'A description' ,
126
+ stepsInfo : [
127
+ {
128
+ title : 'First step'
129
+ } ,
130
+ {
131
+ title : 'Last step'
132
+ }
133
+ ] ,
122
134
fields : [
123
135
{
124
136
name : 'first-step' ,
125
- title : 'AWS step' ,
126
- description : 'This is a AWS step' ,
127
137
nextStep : {
128
138
when : 'aws' ,
129
139
stepMapper : {
@@ -141,22 +151,18 @@ describe('wizard', () => {
141
151
} ,
142
152
{
143
153
name : 'summary' ,
144
- title : 'Summary' ,
145
- description : 'Review your progress' ,
146
154
fields : [
147
155
{
148
- component : componentTypes . TEXTAREA ,
156
+ component : componentTypes . TEXT_FIELD ,
149
157
name : 'summary'
150
158
}
151
159
]
152
160
} ,
153
161
{
154
162
name : 'google' ,
155
- title : 'Google' ,
156
- description : 'Some google stuff' ,
157
163
fields : [
158
164
{
159
- component : componentTypes . TEXTAREA ,
165
+ component : componentTypes . TEXT_FIELD ,
160
166
name : 'googlesummary'
161
167
}
162
168
]
@@ -170,10 +176,10 @@ describe('wizard', () => {
170
176
171
177
expect (
172
178
wrapper
173
- . find ( WizardStep )
174
- . find ( 'h5' )
179
+ . find ( '.MuiStepLabel-active' )
180
+ . first ( )
175
181
. text ( )
176
- ) . toEqual ( 'AWS step' ) ;
182
+ ) . toEqual ( 'First step' ) ;
177
183
178
184
wrapper . find ( 'input' ) . instance ( ) . value = 'aws' ;
179
185
wrapper . find ( 'input' ) . simulate ( 'change' ) ;
@@ -182,45 +188,47 @@ describe('wizard', () => {
182
188
wrapper
183
189
. find ( Button )
184
190
. last ( )
185
- . simulate ( 'click' ) ;
191
+ . simulate ( 'click' ) ; // next
186
192
wrapper . update ( ) ;
187
193
188
194
expect (
189
195
wrapper
190
- . find ( WizardStep )
191
- . find ( 'h5' )
196
+ . find ( '.MuiStepLabel-active' )
197
+ . first ( )
192
198
. text ( )
193
- ) . toEqual ( 'Summary' ) ;
199
+ ) . toEqual ( 'Last step' ) ;
200
+ expect ( wrapper . find ( 'input' ) . instance ( ) . name ) . toEqual ( 'summary' ) ;
194
201
195
202
wrapper
196
203
. find ( Button )
197
- . first ( )
204
+ . at ( 1 ) // back
198
205
. simulate ( 'click' ) ;
199
206
wrapper . update ( ) ;
200
207
201
208
expect (
202
209
wrapper
203
- . find ( WizardStep )
204
- . find ( 'h5' )
210
+ . find ( '.MuiStepLabel-active' )
211
+ . first ( )
205
212
. text ( )
206
- ) . toEqual ( 'AWS step' ) ;
213
+ ) . toEqual ( 'First step' ) ;
207
214
208
215
wrapper . find ( 'input' ) . instance ( ) . value = 'google' ;
209
216
wrapper . find ( 'input' ) . simulate ( 'change' ) ;
210
217
wrapper . update ( ) ;
211
218
212
219
wrapper
213
220
. find ( Button )
214
- . last ( )
221
+ . last ( ) // next
215
222
. simulate ( 'click' ) ;
216
223
wrapper . update ( ) ;
217
224
218
225
expect (
219
226
wrapper
220
- . find ( WizardStep )
221
- . find ( 'h5' )
227
+ . find ( '.MuiStepLabel-active' )
228
+ . first ( )
222
229
. text ( )
223
- ) . toEqual ( 'Google' ) ;
230
+ ) . toEqual ( 'Last step' ) ;
231
+ expect ( wrapper . find ( 'input' ) . instance ( ) . name ) . toEqual ( 'googlesummary' ) ;
224
232
} ) ;
225
233
226
234
it ( 'conditional submit' , ( ) => {
@@ -234,8 +242,6 @@ describe('wizard', () => {
234
242
fields : [
235
243
{
236
244
name : 'first-step' ,
237
- title : 'AWS step' ,
238
- description : 'This is a AWS step' ,
239
245
nextStep : {
240
246
when : 'aws' ,
241
247
stepMapper : {
@@ -253,8 +259,6 @@ describe('wizard', () => {
253
259
} ,
254
260
{
255
261
name : 'summary' ,
256
- title : 'Summary' ,
257
- description : 'Review your progress' ,
258
262
fields : [
259
263
{
260
264
component : componentTypes . TEXTAREA ,
@@ -264,8 +268,6 @@ describe('wizard', () => {
264
268
} ,
265
269
{
266
270
name : 'google' ,
267
- title : 'Google' ,
268
- description : 'Some google stuff' ,
269
271
fields : [
270
272
{
271
273
component : componentTypes . TEXTAREA ,
@@ -314,7 +316,7 @@ describe('wizard', () => {
314
316
315
317
wrapper
316
318
. find ( Button )
317
- . first ( )
319
+ . at ( 1 )
318
320
. simulate ( 'click' ) ;
319
321
wrapper . update ( ) ;
320
322
@@ -350,4 +352,22 @@ describe('wizard', () => {
350
352
} ) ;
351
353
onSubmit . mockClear ( ) ;
352
354
} ) ;
355
+
356
+ it ( 'sends values to cancel' , ( ) => {
357
+ const wrapper = mount ( < FormRenderer { ...initialProps } /> ) ;
358
+
359
+ wrapper . find ( 'input' ) . instance ( ) . value = 'something' ;
360
+ wrapper . find ( 'input' ) . simulate ( 'change' ) ;
361
+ wrapper . update ( ) ;
362
+
363
+ wrapper
364
+ . find ( Button )
365
+ . first ( )
366
+ . simulate ( 'click' ) ; // disabled next
367
+ wrapper . update ( ) ;
368
+
369
+ expect ( onCancel ) . toHaveBeenCalledWith ( {
370
+ aws : 'something'
371
+ } ) ;
372
+ } ) ;
353
373
} ) ;
0 commit comments