Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Refactor intl wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
przlada committed Jun 24, 2020
1 parent e9853ed commit 1996837
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 250 deletions.
50 changes: 31 additions & 19 deletions src/@next/components/molecules/AccountTabTiles/test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount, shallow } from "enzyme";
import { mount } from "enzyme";
import "jest-styled-components";
import React from "react";
import { IntlProvider } from "react-intl";
Expand All @@ -16,25 +16,31 @@ jest.mock("@saleor/sdk", () => ({

describe("<PasswordTile />", () => {
it("exists", () => {
const wrapper = mount(<PasswordTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<PasswordTile />
</IntlProvider>
);

expect(wrapper.exists()).toEqual(true);
});

it("should show basic view on load", () => {
const wrapper = mount(<PasswordTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<PasswordTile />
</IntlProvider>
);

expect(wrapper.find(Attribute)).toHaveLength(1);
});

it("should change view to password change view when clicked on edit icon", () => {
const wrapper = mount(<PasswordTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<PasswordTile />
</IntlProvider>
);

wrapper.find(IconButton).simulate("click");

Expand All @@ -44,25 +50,31 @@ describe("<PasswordTile />", () => {

describe("<AccountTile />", () => {
it("exists", () => {
const wrapper = mount(<AccountTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AccountTile />
</IntlProvider>
);

expect(wrapper.exists()).toEqual(true);
});

it("should show basic view on load", () => {
const wrapper = mount(<AccountTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AccountTile />
</IntlProvider>
);

expect(wrapper.find(Attribute)).toHaveLength(2);
});

it("should change view to password change view when clicked on edit icon", () => {
const wrapper = mount(<AccountTile />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AccountTile />
</IntlProvider>
);

wrapper.find(IconButton).simulate("click");

Expand Down
4 changes: 2 additions & 2 deletions src/@next/components/molecules/AddressTile/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const DEFAULT_PROPS = {
storiesOf("@components/molecules/AddressTile", module)
.addParameters({ component: AddressTile })
.add("default", () => (
<IntlProvider>
<IntlProvider locale="en">
<Container>
<AddressTile {...DEFAULT_PROPS} />
</Container>
Expand All @@ -51,7 +51,7 @@ storiesOf("@components/molecules/AddressTile", module)
CHANGED_DEFAULT_ADDRESSES.address.isDefaultBillingAddress = false;
CHANGED_DEFAULT_ADDRESSES.address.isDefaultShippingAddress = false;
return (
<IntlProvider>
<IntlProvider locale="en">
<Container>
<AddressTile {...CHANGED_DEFAULT_ADDRESSES} />
</Container>
Expand Down
66 changes: 41 additions & 25 deletions src/@next/components/molecules/AddressTile/test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount, shallow } from "enzyme";
import { mount } from "enzyme";
import "jest-styled-components";
import React from "react";
import { IntlProvider } from "react-intl";
Expand Down Expand Up @@ -35,37 +35,45 @@ const DEFAULT_PROPS = {

describe("<AddressTile />", () => {
it("exists", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

expect(wrapper.exists()).toEqual(true);
});

it("should run onRemove function for clicking on trash button", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

wrapper.find(IconButton).last().simulate("click");

expect(onRemove).toHaveBeenCalled();
});

it("should run onEdit function for clicking on edit button", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

wrapper.find(IconButton).at(1).simulate("click");

expect(onEdit).toHaveBeenCalled();
});

it("should run setDefault method for clicking on Set default billing address", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

wrapper.find(IconButton).first().simulate("click");
wrapper.find("li").first().simulate("click");
Expand All @@ -74,9 +82,11 @@ describe("<AddressTile />", () => {
});

it("should run setDefault method for clicking on Set default shipping address", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

wrapper.find(IconButton).first().simulate("click");
wrapper.find("li").last().simulate("click");
Expand All @@ -85,9 +95,11 @@ describe("<AddressTile />", () => {
});

it("should present Default address if address is default shipping and billing", () => {
const wrapper = mount(<AddressTile {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...DEFAULT_PROPS} />
</IntlProvider>
);

expect(wrapper.text()).toContain("Default Address");
});
Expand All @@ -97,9 +109,11 @@ describe("<AddressTile />", () => {
CUSTOM_PROPS.address.isDefaultBillingAddress = false;
CUSTOM_PROPS.address.isDefaultShippingAddress = true;

const wrapper = mount(<AddressTile {...CUSTOM_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...CUSTOM_PROPS} />
</IntlProvider>
);

expect(wrapper.text()).toContain("Default Shipping Address");
});
Expand All @@ -109,9 +123,11 @@ describe("<AddressTile />", () => {
CUSTOM_PROPS.address.isDefaultBillingAddress = true;
CUSTOM_PROPS.address.isDefaultShippingAddress = false;

const wrapper = mount(<AddressTile {...CUSTOM_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<AddressTile {...CUSTOM_PROPS} />
</IntlProvider>
);

expect(wrapper.text()).toContain("Default Billing Address");
});
Expand Down
8 changes: 5 additions & 3 deletions src/@next/components/molecules/CartSummaryRow/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ describe("<CartSummaryRow />", () => {
});

it("should display product quantity", () => {
const wrapper = mount(<CartSummaryRow {...DEFAULT_PROPS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<CartSummaryRow {...DEFAULT_PROPS} />
</IntlProvider>
);

expect(wrapper.text()).toContain(`Quantity: ${DEFAULT_PROPS.quantity}`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ storiesOf("@components/molecules/CheckoutProgressBar", module)
.add("default", () => {
const value = number(label, defaultValue, options);
return (
<IntlProvider>
<IntlProvider locale="en">
<MemoryRouter>
<CheckoutProgressBar steps={steps} activeStep={value} />
</MemoryRouter>
Expand Down
24 changes: 11 additions & 13 deletions src/@next/components/molecules/CheckoutProgressBar/test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount, shallow } from "enzyme";
import { mount } from "enzyme";
import "jest-styled-components";
import React from "react";
import { IntlProvider } from "react-intl";
Expand Down Expand Up @@ -27,25 +27,23 @@ const steps = [
describe("<CheckoutProgressBar />", () => {
it("exists", () => {
const wrapper = mount(
<MemoryRouter>
<CheckoutProgressBar steps={steps} activeStep={0} />
</MemoryRouter>,
{
wrappingComponent: IntlProvider,
}
<IntlProvider locale="en">
<MemoryRouter>
<CheckoutProgressBar steps={steps} activeStep={0} />
</MemoryRouter>
</IntlProvider>
);

expect(wrapper.exists()).toEqual(true);
});

it("exists", () => {
const wrapper = mount(
<MemoryRouter>
<CheckoutProgressBar steps={steps} activeStep={0} />
</MemoryRouter>,
{
wrappingComponent: IntlProvider,
}
<IntlProvider locale="en">
<MemoryRouter>
<CheckoutProgressBar steps={steps} activeStep={0} />
</MemoryRouter>
</IntlProvider>
);

expect(wrapper.find("a").length).toEqual(steps.length);
Expand Down
2 changes: 1 addition & 1 deletion src/@next/components/molecules/OrderTabel/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ storiesOf("@components/molecules/OrderTabel", module)
/* eslint-disable-next-line no-extend-native */
Number.prototype.toLocaleString = () => "";
return (
<IntlProvider>
<IntlProvider locale="en">
<OrderTabel history={history} orders={ORDERS} />
</IntlProvider>
);
Expand Down
32 changes: 20 additions & 12 deletions src/@next/components/molecules/OrderTabel/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ const ORDERS = [

describe("<OrderTabel />", () => {
it("exists", () => {
const wrapper = shallow(<OrderTabel history={history} orders={[]} />, {
wrappingComponent: IntlProvider,
});
const wrapper = shallow(
<IntlProvider locale="en">
<OrderTabel history={history} orders={[]} />
</IntlProvider>
);

expect(wrapper.exists()).toEqual(true);
});

it("should render passed orders array", () => {
const wrapper = mount(<OrderTabel history={history} orders={ORDERS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<OrderTabel history={history} orders={ORDERS} />
</IntlProvider>
);

expect(wrapper.text()).toContain("77");
expect(wrapper.text()).toContain("9/4/2019");
Expand All @@ -111,9 +115,11 @@ describe("<OrderTabel />", () => {
});

it("should navigate to particular order when clicking on order row", () => {
const wrapper = mount(<OrderTabel history={history} orders={ORDERS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<OrderTabel history={history} orders={ORDERS} />
</IntlProvider>
);
const historySpy = jest.spyOn(history, "push");

wrapper.find(S.Row).at(1).simulate("click");
Expand All @@ -124,9 +130,11 @@ describe("<OrderTabel />", () => {
});

it("should navigate to product page when clicking on product thumbnail", () => {
const wrapper = mount(<OrderTabel history={history} orders={ORDERS} />, {
wrappingComponent: IntlProvider,
});
const wrapper = mount(
<IntlProvider locale="en">
<OrderTabel history={history} orders={ORDERS} />
</IntlProvider>
);
const historySpy = jest.spyOn(history, "push");
historySpy.mockClear();

Expand Down
4 changes: 2 additions & 2 deletions src/@next/components/molecules/ProductListHeader/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const DEFAULT_PROPS = {
storiesOf("@components/molecules/ProductListHeader", module)
.addParameters({ component: ProductListHeader })
.add("default", () => (
<IntlProvider>
<IntlProvider locale="en">
<ProductListHeader {...DEFAULT_PROPS} />
</IntlProvider>
))
.add("with active filters", () => (
<IntlProvider>
<IntlProvider locale="en">
<ProductListHeader {...DEFAULT_PROPS} activeFilters={3} />
</IntlProvider>
));
Loading

0 comments on commit 1996837

Please sign in to comment.