Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Updated Intl FormattedMessage component mock. #2792

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/venia-ui/__mocks__/react-intl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const React = require('react');
const reactIntl = jest.requireActual('react-intl');
const messages = require('../i18n/en_US.json');
const intl = reactIntl.createIntl({
Expand All @@ -7,6 +8,6 @@ const intl = reactIntl.createIntl({

module.exports = {
...reactIntl,
FormattedMessage: jest.fn(({ defaultMessage, id }) => defaultMessage || id),
FormattedMessage: props => <mock-FormattedMessage {...props} />,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this pattern for mocking things! Going to start using it.

useIntl: jest.fn(() => intl)
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ exports[`it renders a loading indicator when appropriate 1`] = `
</svg>
</span>
<span>
Fetching Data...
<mock-FormattedMessage
defaultMessage="Fetching Data..."
id="loadingIndicator.message"
/>
</span>
</div>
`;

exports[`it shows error when appropriate 1`] = `
<div>
Data Fetch Error
<mock-FormattedMessage
defaultMessage="Data Fetch Error"
id="category.dataFetchError"
/>
</div>
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ exports[`renders product page correctly when error and product data exist 1`] =

exports[`renders product page failed when error data 1`] = `
<div>
<mockConstructor
<FormattedMessage
defaultMessage="Data Fetch Error"
id="product.errorFetch"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ exports[`it disables the submit button while loading 1`] = `
<span
className="content"
>
Cancel
<mock-FormattedMessage
defaultMessage="Cancel"
id="global.cancelButton"
/>
</span>
</button>
<button
Expand All @@ -96,7 +99,10 @@ exports[`it disables the submit button while loading 1`] = `
<span
className="content"
>
Save
<mock-FormattedMessage
defaultMessage="Save"
id="global.confirmButton"
/>
</span>
</button>
</div>
Expand Down Expand Up @@ -192,7 +198,10 @@ exports[`it renders correctly 1`] = `
<span
className="content"
>
Cancel
<mock-FormattedMessage
defaultMessage="Cancel"
id="global.cancelButton"
/>
</span>
</button>
<button
Expand All @@ -203,7 +212,10 @@ exports[`it renders correctly 1`] = `
<span
className="content"
>
Save
<mock-FormattedMessage
defaultMessage="Save"
id="global.confirmButton"
/>
</span>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ exports[`it renders correctly 1`] = `
onClick={[MockFunction handleSignOut]}
type="button"
>
Sign Out
<mock-FormattedMessage
defaultMessage="Sign Out"
id="accountMenu.signOutButtonText"
/>
</button>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ exports[`renders correctly when there are existing addresses 1`] = `
<span
className="addText"
>
Add an Address
<mock-FormattedMessage
defaultMessage="Add an Address"
id="addressBookPage.addAddressText"
/>
</span>
</span>
</button>
Expand Down Expand Up @@ -85,7 +88,10 @@ exports[`renders correctly when there are no existing addresses 1`] = `
<span
className="addText"
>
Add an Address
<mock-FormattedMessage
defaultMessage="Add an Address"
id="addressBookPage.addAddressText"
/>
</span>
</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ exports[`renders breadcrumbs for a category view 1`] = `
<div
className="root"
>
Home
<mock-FormattedMessage
defaultMessage="Home"
id="global.home"
/>
<span
className="divider"
>
Expand All @@ -34,7 +37,10 @@ exports[`renders breadcrumbs for a product view 1`] = `
<div
className="root"
>
Home
<mock-FormattedMessage
defaultMessage="Home"
id="global.home"
/>
<span
className="divider"
>
Expand All @@ -58,7 +64,10 @@ exports[`renders breadcrumbs for intermediate links 1`] = `
<div
className="root"
>
Home
<mock-FormattedMessage
defaultMessage="Home"
id="global.home"
/>
<span
className="divider"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Array [
unit test card code
</span>
<span>
Balance:
<mock-FormattedMessage
defaultMessage="Balance: "
id="giftCard.balance"
/>
<span>
$
</span>
Expand All @@ -28,7 +31,10 @@ Array [
type="button"
>
<span>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="giftCard.remove"
/>
</span>
</button>,
]
Expand All @@ -41,7 +47,10 @@ Array [
unit test card code
</span>
<span>
Balance:
<mock-FormattedMessage
defaultMessage="Balance: "
id="giftCard.balance"
/>
<span>
$
</span>
Expand All @@ -62,7 +71,10 @@ Array [
type="button"
>
<span>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="giftCard.remove"
/>
</span>
</button>,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="content"
>
Apply
<mock-FormattedMessage
defaultMessage="Apply"
id="giftCards.apply"
/>
</span>
</button>
</div>
Expand All @@ -90,7 +93,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="content"
>
Check balance
<mock-FormattedMessage
defaultMessage="Check balance"
id="giftCards.checkBalance"
/>
</span>
</button>
</div>
Expand All @@ -110,7 +116,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="balance"
>
Balance:
<mock-FormattedMessage
defaultMessage="Balance: "
id="giftCard.balance"
/>
<span>
$
</span>
Expand All @@ -134,7 +143,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="content"
>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="giftCard.remove"
/>
</span>
</button>
<div
Expand All @@ -148,7 +160,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="balance"
>
Balance:
<mock-FormattedMessage
defaultMessage="Balance: "
id="giftCard.balance"
/>
<span>
$
</span>
Expand All @@ -172,7 +187,10 @@ exports[`it renders correctly when it has cards 1`] = `
<span
className="content"
>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="giftCard.remove"
/>
</span>
</button>
</div>
Expand Down Expand Up @@ -256,7 +274,10 @@ exports[`it renders correctly with no cards 1`] = `
<span
className="content"
>
Apply
<mock-FormattedMessage
defaultMessage="Apply"
id="giftCards.apply"
/>
</span>
</button>
</div>
Expand All @@ -269,7 +290,10 @@ exports[`it renders correctly with no cards 1`] = `
<span
className="content"
>
Check balance
<mock-FormattedMessage
defaultMessage="Check balance"
id="giftCards.checkBalance"
/>
</span>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ exports[`disables remove button on click 1`] = `
type="button"
>
<span>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="couponCode.removeButton"
/>
</span>
</button>
</div>
Expand Down Expand Up @@ -65,7 +68,10 @@ exports[`disables submit button on coupon entry 1`] = `
type="submit"
>
<span>
Apply
<mock-FormattedMessage
defaultMessage="Apply"
id="couponCode.apply"
/>
</span>
</button>
</div>
Expand Down Expand Up @@ -117,7 +123,10 @@ exports[`renders CouponCode input and submit button 1`] = `
type="submit"
>
<span>
Apply
<mock-FormattedMessage
defaultMessage="Apply"
id="couponCode.apply"
/>
</span>
</button>
</div>
Expand Down Expand Up @@ -168,7 +177,10 @@ exports[`renders an error message if an error occurs on code entry 1`] = `
type="submit"
>
<span>
Apply
<mock-FormattedMessage
defaultMessage="Apply"
id="couponCode.apply"
/>
</span>
</button>
</div>
Expand All @@ -177,7 +189,10 @@ exports[`renders an error message if an error occurs on code entry 1`] = `

exports[`renders an error state if unable to fetch applied coupons 1`] = `
<div>
Something went wrong. Please refresh and try again.
<mock-FormattedMessage
defaultMessage="Something went wrong. Please refresh and try again."
id="couponCode.errorContainer"
/>
</div>
`;

Expand All @@ -197,7 +212,10 @@ exports[`renders the coupon code view if applied coupons has data 1`] = `
type="button"
>
<span>
Remove
<mock-FormattedMessage
defaultMessage="Remove"
id="couponCode.removeButton"
/>
</span>
</button>
</div>
Expand Down
Loading