-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returning a fragment to enable testing in enzyme
- Loading branch information
Showing
3 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
client/my-sites/checkout/checkout/test/__snapshots__/ebanx-brazil-payment-box.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<EbanxBrazilPaymentFields /> should render 1`] = ` | ||
<React.Fragment> | ||
<span | ||
className="checkout__form-info-text" | ||
key="ebanx-required-fields" | ||
> | ||
The following fields are also required for payments in %(countryName)s | ||
</span> | ||
<Input | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
autoFocus={false} | ||
isError={false} | ||
key="document" | ||
label="Taxpayer Identification Number" | ||
labelClass="checkout__form-label" | ||
name="document" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
<FormPhoneMediaInput | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
countriesList={ | ||
Object { | ||
"get": [Function], | ||
} | ||
} | ||
countryCode="BR" | ||
isError={false} | ||
key="phone-number" | ||
label="Phone" | ||
labelClass="checkout__form-label" | ||
name="phone-number" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
<Input | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
autoFocus={false} | ||
isError={false} | ||
key="address-1" | ||
label="Address" | ||
labelClass="checkout__form-label" | ||
maxLength={40} | ||
name="address-1" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
<Input | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
autoFocus={false} | ||
inputMode="numeric" | ||
isError={false} | ||
key="street-number" | ||
label="Street Number" | ||
labelClass="checkout__form-label" | ||
name="street-number" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
<HiddenInput | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
isError={false} | ||
key="address-2" | ||
label="Address Line 2" | ||
labelClass="checkout__form-label" | ||
maxLength={40} | ||
name="address-2" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
text="+ Add Address Line 2" | ||
/> | ||
<Input | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
autoFocus={false} | ||
isError={false} | ||
key="city" | ||
label="City" | ||
labelClass="checkout__form-label" | ||
name="city" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
<div | ||
className="checkout__form-state-field" | ||
key="state" | ||
> | ||
<Connect(Localized(StateSelect)) | ||
additionalClasses="checkout__form-field ebanx-brazil" | ||
autoComplete="off" | ||
countryCode="BR" | ||
isError={false} | ||
label="State" | ||
labelClass="checkout__form-label" | ||
name="state" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
/> | ||
</div> | ||
</React.Fragment> | ||
`; |
43 changes: 43 additions & 0 deletions
43
client/my-sites/checkout/checkout/test/ebanx-brazil-payment-box.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @format | ||
* @jest-environment jsdom | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { identity } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { EbanxBrazilPaymentFields } from '../ebanx-brazil-payment-fields'; | ||
|
||
const defaultProps = { | ||
countryCode: 'BR', | ||
countriesList: { | ||
get: () => [ { code: 'BR', name: 'Brazil' } ], | ||
}, | ||
getErrorMessage: jest.fn(), | ||
getFieldValue: jest.fn(), | ||
handleFieldChange: jest.fn(), | ||
fieldClassName: 'ebanx-brazil', | ||
translate: identity, | ||
}; | ||
|
||
describe( '<EbanxBrazilPaymentFields />', () => { | ||
test( 'should render', () => { | ||
const wrapper = shallow( <EbanxBrazilPaymentFields { ...defaultProps } /> ); | ||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should call this.props.handleFieldChange when updating field', () => { | ||
const wrapper = shallow( <EbanxBrazilPaymentFields { ...defaultProps } /> ); | ||
const documentInput = wrapper.find( '[name="document"]' ); | ||
const event = { target: { name: 'document', value: 'spam' } }; | ||
documentInput.simulate( 'change', event ); | ||
expect( defaultProps.handleFieldChange ).toBeCalledWith( 'document', 'spam' ); | ||
} ); | ||
} ); |