Skip to content

Commit d71e4db

Browse files
committed
Add tests for wizard nav PF4
1 parent 6d3bc17 commit d71e4db

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
4+
import WizardNavigationClass from '../../form-fields/wizard/wizard-nav';
5+
6+
describe('WizardNav', () => {
7+
it('WizardNavigationClass rerender nav schema only when values are changed', () => {
8+
const initialProps = {
9+
activeStepIndex: 0,
10+
formOptions: { valid: true },
11+
maxStepIndex: 0,
12+
jumpToStep: jest.fn(),
13+
navSchema: [
14+
{ title: 'step' },
15+
],
16+
setPrevSteps: jest.fn(),
17+
values: { name: 'value 1' },
18+
crossroads: [ 'name' ],
19+
};
20+
21+
const wrapper = mount(<WizardNavigationClass { ...initialProps }/>);
22+
23+
expect(initialProps.setPrevSteps).not.toHaveBeenCalled();
24+
25+
wrapper.setProps({ values: { name: 'different value' }});
26+
27+
expect(initialProps.setPrevSteps.mock.calls).toHaveLength(1);
28+
29+
wrapper.setProps({ values: { name: 'different value' }});
30+
31+
expect(initialProps.setPrevSteps.mock.calls).toHaveLength(1);
32+
33+
wrapper.setProps({ values: { name: 'another value' }});
34+
35+
expect(initialProps.setPrevSteps.mock.calls).toHaveLength(2);
36+
37+
wrapper.setProps({ values: { name: 'another value', password: 'do not render nav' }});
38+
39+
expect(initialProps.setPrevSteps.mock.calls).toHaveLength(2);
40+
});
41+
42+
it('WizardNavigationClass change maxStepIndex to activeStepIndex when switching', () => {
43+
const activeStepIndex = 3;
44+
45+
const initialProps = {
46+
activeStepIndex,
47+
formOptions: { valid: true },
48+
maxStepIndex: 5,
49+
jumpToStep: jest.fn(),
50+
navSchema: [
51+
{ title: 'step' },
52+
],
53+
setPrevSteps: jest.fn(),
54+
values: { name: 'value 1' },
55+
crossroads: [ 'name' ],
56+
};
57+
58+
const wrapper = mount(<WizardNavigationClass { ...initialProps }/>);
59+
60+
expect(initialProps.setPrevSteps).not.toHaveBeenCalled();
61+
62+
wrapper.setProps({ values: { name: 'different value' }});
63+
64+
expect(wrapper.state().maxStepIndex).toEqual(activeStepIndex);
65+
});
66+
});

0 commit comments

Comments
 (0)