Skip to content

Commit

Permalink
fix(payment): INT-2754 adding conditional for updateFieldValue on
Browse files Browse the repository at this point in the history
ComponentWillUnmount()
  • Loading branch information
PedroTerriquez committed Aug 17, 2020
1 parent 207f668 commit 6f349d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,22 @@ describe('AccountInstrumentSelect', () => {
const submit = jest.fn();
initialValues.instrumentId = '1234';

const Component = ({ show }: { show: boolean }) =>
const Component = ({ show, selectedInstrumentId }: { show: boolean; selectedInstrumentId?: string }) =>
<Formik initialValues={ initialValues } onSubmit={ submit }>
{ ({ handleSubmit }) => <form onSubmit={ handleSubmit }>
{ show && <Field name="instrumentId">
{ (field: FieldProps<string>) => (
<AccountInstrumentSelect
{ ...field }
{ ...defaultProps }
selectedInstrumentId={ selectedInstrumentId }
/>
) }
</Field> }
</form> }
</Formik>;

const component = mount(<Component show={ true } />);
const component = mount(<Component selectedInstrumentId={ defaultProps.selectedInstrumentId } show={ true } />);

component.find('form')
.simulate('submit')
Expand All @@ -231,6 +232,10 @@ describe('AccountInstrumentSelect', () => {

expect(submit).toHaveBeenCalledWith({ instrumentId: '1234' }, expect.anything());

component
.setProps({ selectedInstrumentId: '' })
.update();

component
.setProps({ show: false })
.update();
Expand Down
6 changes: 5 additions & 1 deletion src/app/payment/storedInstrument/AccountInstrumentSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class AccountInstrumentSelect extends PureComponent<AccountInstrumentSelectProps
}

componentWillUnmount() {
this.updateFieldValue();
const { selectedInstrumentId, field } = this.props;

if (field.value === '' && selectedInstrumentId !== undefined) {
this.updateFieldValue();
}
}

render(): ReactNode {
Expand Down
9 changes: 7 additions & 2 deletions src/app/payment/storedInstrument/InstrumentSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ describe('InstrumentSelect', () => {
const submit = jest.fn();
initialValues.instrumentId = '1234';

const Component = ({ show }: { show: boolean }) =>
const Component = ({ show, selectedInstrumentId }: { show: boolean; selectedInstrumentId?: string }) =>
<Formik initialValues={ initialValues } onSubmit={ submit }>
{ ({ handleSubmit }) => <form onSubmit={ handleSubmit }>
{ show && <Field name="instrumentId">
{ (field: FieldProps<string>) => (
<InstrumentSelect
{ ...field }
{ ...defaultProps }
selectedInstrumentId={ selectedInstrumentId }
/>
) }
</Field> }
</form> }
</Formik>;

const component = mount(<Component show={ true } />);
const component = mount(<Component selectedInstrumentId={ defaultProps.selectedInstrumentId } show={ true } />);

component.find('form')
.simulate('submit')
Expand All @@ -269,6 +270,10 @@ describe('InstrumentSelect', () => {

expect(submit).toHaveBeenCalledWith({ instrumentId: '1234' }, expect.anything());

component
.setProps({ selectedInstrumentId: '' })
.update();

component
.setProps({ show: false })
.update();
Expand Down
6 changes: 5 additions & 1 deletion src/app/payment/storedInstrument/InstrumentSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class InstrumentSelect extends PureComponent<InstrumentSelectProps> {
}

componentWillUnmount() {
this.updateFieldValue();
const { selectedInstrumentId, field } = this.props;

if (field.value === '' && selectedInstrumentId !== undefined) {
this.updateFieldValue();
}
}

render(): ReactNode {
Expand Down

0 comments on commit 6f349d3

Please sign in to comment.