Skip to content

Commit 5c97155

Browse files
authored
Merge pull request #219 from rvsia/wizardOnCloseIconValues
fix(pf4wizard): pass formValues to onClose icon cancel action
2 parents 095c6fc + ba1403d commit 5c97155

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

packages/pf4-component-mapper/src/form-fields/wizard/wizard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class Wizard extends React.Component {
249249
{ title && <WizardHeader
250250
title={ title }
251251
description={ description }
252-
onClose={ formOptions.onCancel }
252+
onClose={ () => formOptions.onCancel(formOptions.getState().values) }
253253
/> }
254254
<div className="pf-c-wizard__outer-wrap">
255255
<WizardNav>

packages/pf4-component-mapper/src/tests/wizard/__snapshots__/wizard.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
6767
>
6868
<WizardHeader
6969
description="wizard description"
70-
onClose={[MockFunction]}
70+
onClose={[Function]}
7171
title="Wizard"
7272
>
7373
<div
7474
className="pf-c-wizard__header"
7575
>
7676
<Component
7777
className="pf-c-wizard__close"
78-
onClick={[MockFunction]}
78+
onClick={[Function]}
7979
variant="plain"
8080
>
8181
<ComponentWithOuia
@@ -91,15 +91,15 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
9191
title={null}
9292
/>,
9393
"className": "pf-c-wizard__close",
94-
"onClick": [MockFunction],
94+
"onClick": [Function],
9595
"variant": "plain",
9696
}
9797
}
9898
consumerContext={null}
9999
>
100100
<Button
101101
className="pf-c-wizard__close"
102-
onClick={[MockFunction]}
102+
onClick={[Function]}
103103
ouiaContext={
104104
Object {
105105
"isOuia": false,
@@ -113,7 +113,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
113113
aria-label={null}
114114
className="pf-c-button pf-m-plain pf-c-wizard__close"
115115
disabled={false}
116-
onClick={[MockFunction]}
116+
onClick={[Function]}
117117
tabIndex={null}
118118
type="button"
119119
>
@@ -714,15 +714,15 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
714714
>
715715
<WizardHeader
716716
description="wizard description"
717-
onClose={[MockFunction]}
717+
onClose={[Function]}
718718
title="Wizard"
719719
>
720720
<div
721721
className="pf-c-wizard__header"
722722
>
723723
<Component
724724
className="pf-c-wizard__close"
725-
onClick={[MockFunction]}
725+
onClick={[Function]}
726726
variant="plain"
727727
>
728728
<ComponentWithOuia
@@ -738,15 +738,15 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
738738
title={null}
739739
/>,
740740
"className": "pf-c-wizard__close",
741-
"onClick": [MockFunction],
741+
"onClick": [Function],
742742
"variant": "plain",
743743
}
744744
}
745745
consumerContext={null}
746746
>
747747
<Button
748748
className="pf-c-wizard__close"
749-
onClick={[MockFunction]}
749+
onClick={[Function]}
750750
ouiaContext={
751751
Object {
752752
"isOuia": false,
@@ -760,7 +760,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
760760
aria-label={null}
761761
className="pf-c-button pf-m-plain pf-c-wizard__close"
762762
disabled={false}
763-
onClick={[MockFunction]}
763+
onClick={[Function]}
764764
tabIndex={null}
765765
type="button"
766766
>
@@ -1157,7 +1157,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
11571157
description
11581158
</div>
11591159
}
1160-
onClose={[MockFunction]}
1160+
onClose={[Function]}
11611161
title={
11621162
<div>
11631163
Title
@@ -1169,7 +1169,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
11691169
>
11701170
<Component
11711171
className="pf-c-wizard__close"
1172-
onClick={[MockFunction]}
1172+
onClick={[Function]}
11731173
variant="plain"
11741174
>
11751175
<ComponentWithOuia
@@ -1185,15 +1185,15 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
11851185
title={null}
11861186
/>,
11871187
"className": "pf-c-wizard__close",
1188-
"onClick": [MockFunction],
1188+
"onClick": [Function],
11891189
"variant": "plain",
11901190
}
11911191
}
11921192
consumerContext={null}
11931193
>
11941194
<Button
11951195
className="pf-c-wizard__close"
1196-
onClick={[MockFunction]}
1196+
onClick={[Function]}
11971197
ouiaContext={
11981198
Object {
11991199
"isOuia": false,
@@ -1207,7 +1207,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
12071207
aria-label={null}
12081208
className="pf-c-button pf-m-plain pf-c-wizard__close"
12091209
disabled={false}
1210-
onClick={[MockFunction]}
1210+
onClick={[Function]}
12111211
tabIndex={null}
12121212
type="button"
12131213
>

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ describe('<Wizard />', () => {
4242
wrapper.update();
4343
};
4444

45+
const closeIconClickWithHeader = (wrapper) => {
46+
wrapper.find('button').at(0).simulate('click');
47+
wrapper.update();
48+
};
49+
4550
const changeValue = (wrapper, value) => {
4651
wrapper.find('input').instance().value = value;
4752
wrapper.find('input').simulate('change');
@@ -201,7 +206,7 @@ describe('<Wizard />', () => {
201206
});
202207
});
203208

204-
it('should pass values to cancel', () => {
209+
it('should pass values to cancel button', () => {
205210
const onCancel = jest.fn();
206211
const wrapper = mount(<Wizard
207212
{ ...initialProps }
@@ -214,6 +219,19 @@ describe('<Wizard />', () => {
214219
expect(onCancel).toHaveBeenCalledWith(initialValues);
215220
});
216221

222+
it('should pass values to cancel - close icon', () => {
223+
const onCancel = jest.fn();
224+
const wrapper = mount(<Wizard
225+
{ ...initialProps }
226+
fields={ schema }
227+
formOptions={{ ...initialProps.formOptions, onCancel }}
228+
/>);
229+
230+
closeIconClickWithHeader(wrapper);
231+
232+
expect(onCancel).toHaveBeenCalledWith(initialValues);
233+
});
234+
217235
it('should submit data when nested schema', () => {
218236
const onSubmit = jest.fn();
219237
const wrapper = mount(<Wizard

0 commit comments

Comments
 (0)