Skip to content

Commit 0b398d9

Browse files
committed
Update tests for wizard MUI
1 parent cf4711e commit 0b398d9

File tree

2 files changed

+71
-51
lines changed

2 files changed

+71
-51
lines changed

packages/mui-component-mapper/demo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const App = () => {
4747
<FormRenderer
4848
onSubmit={console.log}
4949
componentMapper={compositeMapper}
50-
FormTemplate={(props) => <FormTemplate {...props} showFormControls={false}/>}
50+
FormTemplate={(props) => <FormTemplate {...props} />}
5151
schema={schema}
5252
onCancel={() => console.log('canceling')}
5353
/>

packages/mui-component-mapper/src/tests/wizard.test.js

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@ import { mount } from 'enzyme';
44
import { Button } from '@material-ui/core';
55

66
import { componentMapper, FormTemplate } from '../index';
7-
import WizardStep from '../files/wizard/wizard-step';
87

98
describe('wizard', () => {
109
let initialProps;
1110
let schema;
1211
let onSubmit;
12+
let onCancel;
1313

1414
beforeEach(() => {
1515
schema = {
1616
fields: [
1717
{
1818
component: componentTypes.WIZARD,
1919
name: 'wizard',
20-
title: 'A title',
21-
description: 'A description',
20+
stepsInfo: [
21+
{
22+
title: 'AWS step'
23+
},
24+
{
25+
title: 'Summary'
26+
}
27+
],
2228
fields: [
2329
{
2430
name: 'first-step',
25-
title: 'AWS step',
26-
description: 'This is a AWS step',
2731
nextStep: 'summary',
2832
fields: [
2933
{
@@ -35,8 +39,6 @@ describe('wizard', () => {
3539
},
3640
{
3741
name: 'summary',
38-
title: 'Summary',
39-
description: 'Review your progress',
4042
fields: [
4143
{
4244
component: componentTypes.TEXTAREA,
@@ -49,11 +51,13 @@ describe('wizard', () => {
4951
]
5052
};
5153
onSubmit = jest.fn();
54+
onCancel = jest.fn();
5255
initialProps = {
5356
componentMapper,
5457
FormTemplate: (props) => <FormTemplate {...props} showFormControls={false} />,
5558
schema,
56-
onSubmit: (values) => onSubmit(values)
59+
onSubmit: (values) => onSubmit(values),
60+
onCancel: (values) => onCancel(values)
5761
};
5862
});
5963

@@ -62,21 +66,21 @@ describe('wizard', () => {
6266

6367
expect(
6468
wrapper
65-
.find(WizardStep)
66-
.find('h5')
69+
.find('.MuiStepLabel-active')
70+
.first()
6771
.text()
6872
).toEqual('AWS step');
6973

7074
wrapper
7175
.find(Button)
7276
.last()
73-
.simulate('click');
77+
.simulate('click'); // disabled next
7478
wrapper.update();
7579

7680
expect(
7781
wrapper
78-
.find(WizardStep)
79-
.find('h5')
82+
.find('.MuiStepLabel-active')
83+
.first()
8084
.text()
8185
).toEqual('AWS step');
8286

@@ -87,26 +91,26 @@ describe('wizard', () => {
8791
wrapper
8892
.find(Button)
8993
.last()
90-
.simulate('click');
94+
.simulate('click'); // next
9195
wrapper.update();
9296

9397
expect(
9498
wrapper
95-
.find(WizardStep)
96-
.find('h5')
99+
.find('.MuiStepLabel-active')
100+
.first()
97101
.text()
98102
).toEqual('Summary');
99103

100104
wrapper
101105
.find(Button)
102-
.first()
103-
.simulate('click');
106+
.at(1)
107+
.simulate('click'); // back
104108
wrapper.update();
105109

106110
expect(
107111
wrapper
108-
.find(WizardStep)
109-
.find('h5')
112+
.find('.MuiStepLabel-active')
113+
.first()
110114
.text()
111115
).toEqual('AWS step');
112116
});
@@ -119,11 +123,17 @@ describe('wizard', () => {
119123
name: 'wizard',
120124
title: 'A title',
121125
description: 'A description',
126+
stepsInfo: [
127+
{
128+
title: 'First step'
129+
},
130+
{
131+
title: 'Last step'
132+
}
133+
],
122134
fields: [
123135
{
124136
name: 'first-step',
125-
title: 'AWS step',
126-
description: 'This is a AWS step',
127137
nextStep: {
128138
when: 'aws',
129139
stepMapper: {
@@ -141,22 +151,18 @@ describe('wizard', () => {
141151
},
142152
{
143153
name: 'summary',
144-
title: 'Summary',
145-
description: 'Review your progress',
146154
fields: [
147155
{
148-
component: componentTypes.TEXTAREA,
156+
component: componentTypes.TEXT_FIELD,
149157
name: 'summary'
150158
}
151159
]
152160
},
153161
{
154162
name: 'google',
155-
title: 'Google',
156-
description: 'Some google stuff',
157163
fields: [
158164
{
159-
component: componentTypes.TEXTAREA,
165+
component: componentTypes.TEXT_FIELD,
160166
name: 'googlesummary'
161167
}
162168
]
@@ -170,10 +176,10 @@ describe('wizard', () => {
170176

171177
expect(
172178
wrapper
173-
.find(WizardStep)
174-
.find('h5')
179+
.find('.MuiStepLabel-active')
180+
.first()
175181
.text()
176-
).toEqual('AWS step');
182+
).toEqual('First step');
177183

178184
wrapper.find('input').instance().value = 'aws';
179185
wrapper.find('input').simulate('change');
@@ -182,45 +188,47 @@ describe('wizard', () => {
182188
wrapper
183189
.find(Button)
184190
.last()
185-
.simulate('click');
191+
.simulate('click'); // next
186192
wrapper.update();
187193

188194
expect(
189195
wrapper
190-
.find(WizardStep)
191-
.find('h5')
196+
.find('.MuiStepLabel-active')
197+
.first()
192198
.text()
193-
).toEqual('Summary');
199+
).toEqual('Last step');
200+
expect(wrapper.find('input').instance().name).toEqual('summary');
194201

195202
wrapper
196203
.find(Button)
197-
.first()
204+
.at(1) // back
198205
.simulate('click');
199206
wrapper.update();
200207

201208
expect(
202209
wrapper
203-
.find(WizardStep)
204-
.find('h5')
210+
.find('.MuiStepLabel-active')
211+
.first()
205212
.text()
206-
).toEqual('AWS step');
213+
).toEqual('First step');
207214

208215
wrapper.find('input').instance().value = 'google';
209216
wrapper.find('input').simulate('change');
210217
wrapper.update();
211218

212219
wrapper
213220
.find(Button)
214-
.last()
221+
.last() // next
215222
.simulate('click');
216223
wrapper.update();
217224

218225
expect(
219226
wrapper
220-
.find(WizardStep)
221-
.find('h5')
227+
.find('.MuiStepLabel-active')
228+
.first()
222229
.text()
223-
).toEqual('Google');
230+
).toEqual('Last step');
231+
expect(wrapper.find('input').instance().name).toEqual('googlesummary');
224232
});
225233

226234
it('conditional submit', () => {
@@ -234,8 +242,6 @@ describe('wizard', () => {
234242
fields: [
235243
{
236244
name: 'first-step',
237-
title: 'AWS step',
238-
description: 'This is a AWS step',
239245
nextStep: {
240246
when: 'aws',
241247
stepMapper: {
@@ -253,8 +259,6 @@ describe('wizard', () => {
253259
},
254260
{
255261
name: 'summary',
256-
title: 'Summary',
257-
description: 'Review your progress',
258262
fields: [
259263
{
260264
component: componentTypes.TEXTAREA,
@@ -264,8 +268,6 @@ describe('wizard', () => {
264268
},
265269
{
266270
name: 'google',
267-
title: 'Google',
268-
description: 'Some google stuff',
269271
fields: [
270272
{
271273
component: componentTypes.TEXTAREA,
@@ -314,7 +316,7 @@ describe('wizard', () => {
314316

315317
wrapper
316318
.find(Button)
317-
.first()
319+
.at(1)
318320
.simulate('click');
319321
wrapper.update();
320322

@@ -350,4 +352,22 @@ describe('wizard', () => {
350352
});
351353
onSubmit.mockClear();
352354
});
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+
});
353373
});

0 commit comments

Comments
 (0)