Skip to content

Commit

Permalink
Merge pull request #219 from rvsia/wizardOnCloseIconValues
Browse files Browse the repository at this point in the history
fix(pf4wizard): pass formValues to onClose icon cancel action
  • Loading branch information
Hyperkid123 authored Nov 11, 2019
2 parents 095c6fc + ba1403d commit 5c97155
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Wizard extends React.Component {
{ title && <WizardHeader
title={ title }
description={ description }
onClose={ formOptions.onCancel }
onClose={ () => formOptions.onCancel(formOptions.getState().values) }
/> }
<div className="pf-c-wizard__outer-wrap">
<WizardNav>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
>
<WizardHeader
description="wizard description"
onClose={[MockFunction]}
onClose={[Function]}
title="Wizard"
>
<div
className="pf-c-wizard__header"
>
<Component
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
variant="plain"
>
<ComponentWithOuia
Expand All @@ -91,15 +91,15 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
title={null}
/>,
"className": "pf-c-wizard__close",
"onClick": [MockFunction],
"onClick": [Function],
"variant": "plain",
}
}
consumerContext={null}
>
<Button
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
ouiaContext={
Object {
"isOuia": false,
Expand All @@ -113,7 +113,7 @@ exports[`<Wizard /> should render correctly and unmount 1`] = `
aria-label={null}
className="pf-c-button pf-m-plain pf-c-wizard__close"
disabled={false}
onClick={[MockFunction]}
onClick={[Function]}
tabIndex={null}
type="button"
>
Expand Down Expand Up @@ -714,15 +714,15 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
>
<WizardHeader
description="wizard description"
onClose={[MockFunction]}
onClose={[Function]}
title="Wizard"
>
<div
className="pf-c-wizard__header"
>
<Component
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
variant="plain"
>
<ComponentWithOuia
Expand All @@ -738,15 +738,15 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
title={null}
/>,
"className": "pf-c-wizard__close",
"onClick": [MockFunction],
"onClick": [Function],
"variant": "plain",
}
}
consumerContext={null}
>
<Button
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
ouiaContext={
Object {
"isOuia": false,
Expand All @@ -760,7 +760,7 @@ exports[`<Wizard /> should render correctly in modal and unmount 1`] = `
aria-label={null}
className="pf-c-button pf-m-plain pf-c-wizard__close"
disabled={false}
onClick={[MockFunction]}
onClick={[Function]}
tabIndex={null}
type="button"
>
Expand Down Expand Up @@ -1157,7 +1157,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
description
</div>
}
onClose={[MockFunction]}
onClose={[Function]}
title={
<div>
Title
Expand All @@ -1169,7 +1169,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
>
<Component
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
variant="plain"
>
<ComponentWithOuia
Expand All @@ -1185,15 +1185,15 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
title={null}
/>,
"className": "pf-c-wizard__close",
"onClick": [MockFunction],
"onClick": [Function],
"variant": "plain",
}
}
consumerContext={null}
>
<Button
className="pf-c-wizard__close"
onClick={[MockFunction]}
onClick={[Function]}
ouiaContext={
Object {
"isOuia": false,
Expand All @@ -1207,7 +1207,7 @@ exports[`<Wizard /> should render correctly with custom title and description 1`
aria-label={null}
className="pf-c-button pf-m-plain pf-c-wizard__close"
disabled={false}
onClick={[MockFunction]}
onClick={[Function]}
tabIndex={null}
type="button"
>
Expand Down
20 changes: 19 additions & 1 deletion packages/pf4-component-mapper/src/tests/wizard/wizard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe('<Wizard />', () => {
wrapper.update();
};

const closeIconClickWithHeader = (wrapper) => {
wrapper.find('button').at(0).simulate('click');
wrapper.update();
};

const changeValue = (wrapper, value) => {
wrapper.find('input').instance().value = value;
wrapper.find('input').simulate('change');
Expand Down Expand Up @@ -201,7 +206,7 @@ describe('<Wizard />', () => {
});
});

it('should pass values to cancel', () => {
it('should pass values to cancel button', () => {
const onCancel = jest.fn();
const wrapper = mount(<Wizard
{ ...initialProps }
Expand All @@ -214,6 +219,19 @@ describe('<Wizard />', () => {
expect(onCancel).toHaveBeenCalledWith(initialValues);
});

it('should pass values to cancel - close icon', () => {
const onCancel = jest.fn();
const wrapper = mount(<Wizard
{ ...initialProps }
fields={ schema }
formOptions={{ ...initialProps.formOptions, onCancel }}
/>);

closeIconClickWithHeader(wrapper);

expect(onCancel).toHaveBeenCalledWith(initialValues);
});

it('should submit data when nested schema', () => {
const onSubmit = jest.fn();
const wrapper = mount(<Wizard
Expand Down

0 comments on commit 5c97155

Please sign in to comment.