Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Will Lopez <[email protected]>
  • Loading branch information
willopez committed Aug 6, 2019
1 parent 689b9e4 commit 0919acb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 43 deletions.
42 changes: 26 additions & 16 deletions imports/plugins/core/graphql/lib/hocs/withCatalogItems.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { act } from "react-dom/test-utils";
import { mount } from "enzyme";
import { MockedProvider } from "react-apollo/test-utils";
import { MockedProvider } from "@apollo/react-testing";
import waitForFalseyProp from "/imports/test-utils/helpers/waitForFalseyProp";
import getCatalogItems from "../queries/getCatalogItems";
import withCatalogItems from "./withCatalogItems";
Expand Down Expand Up @@ -105,11 +106,14 @@ const mocks = [
];

test("renders child component with correct catalogItems connection", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent shopId={fakeOpaqueShopId} tagId={fakeOpaqueTagId} />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent shopId={fakeOpaqueShopId} tagId={fakeOpaqueTagId} />
</MockedProvider>
));
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingCatalogItems");

Expand All @@ -120,23 +124,29 @@ test("renders child component with correct catalogItems connection", async () =>
});

test("doesn't query GraphQL if no shopId is provided", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent />
</MockedProvider>
));
});

const mockComponentInstance = wrapper.find("MockComponent");
expect(mockComponentInstance.prop("catalogItems")).toBe(undefined);
expect(mockComponentInstance.prop("isLoadingCatalogItems")).toBe(undefined);
});

test("returns an empty array for catalogItems if invalid shopId is provided", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent shopId="invalidShopId" />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks}>
<TestComponent shopId="invalidShopId" />
</MockedProvider>
));
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingCatalogItems");

Expand Down
12 changes: 7 additions & 5 deletions imports/plugins/core/graphql/lib/hocs/withPrimaryShopId.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { act } from "react-dom/test-utils";
import { mount } from "enzyme";
import { MockedProvider } from "react-apollo/test-utils";
import { MockedProvider } from "@apollo/react-testing";
import waitForFalseyProp from "/imports/test-utils/helpers/waitForFalseyProp";
import getPrimaryShopId from "../queries/getPrimaryShopId";
import withPrimaryShopId from "./withPrimaryShopId";
Expand All @@ -19,11 +20,12 @@ test("renders child component with correct shop id", async () => {
}
}];

const wrapper = mount((
<MockedProvider mocks={mocks}>
let wrapper;
act(() => {
wrapper = mount(<MockedProvider mocks={mocks}>
<TestComponent />
</MockedProvider>
));
</MockedProvider>);
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingPrimaryShopId");

Expand Down
42 changes: 26 additions & 16 deletions imports/plugins/core/graphql/lib/hocs/withShopId.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { act } from "react-dom/test-utils";
import { mount } from "enzyme";
import { MockedProvider } from "react-apollo/test-utils";
import { MockedProvider } from "@apollo/react-testing";
import waitForFalseyProp from "/imports/test-utils/helpers/waitForFalseyProp";
import getShopId from "../queries/getShopId";
import withShopId from "./withShopId";
Expand Down Expand Up @@ -40,35 +41,44 @@ const mocks = [
];

test("renders child component with correct shop id", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent shopSlug="reaction" />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent shopSlug="reaction" />
</MockedProvider>
));
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingShopId");

expect(wrapper.find("MockComponent").prop("shopId")).toBe(fakeOpaqueShopId);
});

test("doesn't query GraphQL if no shopSlug is provided", () => {
const wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent />
</MockedProvider>
));
});

const mockComponentInstance = wrapper.find("MockComponent");
expect(mockComponentInstance.prop("shopId")).toBe(undefined);
expect(mockComponentInstance.prop("isLoadingShopId")).toBe(undefined);
});

test("passes shouldSkipGraphql to child component if invalid shopSlug is provided", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent shopSlug="fakeSlug" />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent shopSlug="fakeSlug" />
</MockedProvider>
));
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingShopId");

Expand Down
16 changes: 10 additions & 6 deletions imports/plugins/core/graphql/lib/hocs/withTagId.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { act } from "react-dom/test-utils";
import { mount } from "enzyme";
import { MockedProvider } from "react-apollo/test-utils";
import { MockedProvider } from "@apollo/react-testing";
import waitForFalseyProp from "/imports/test-utils/helpers/waitForFalseyProp";
import getTagId from "../queries/getTagId";
import withTagId from "./withTagId";
Expand Down Expand Up @@ -65,11 +66,14 @@ test("doesn't query GraphQL if no tagSlug is provided", async () => {
});

test("passes shouldSkipGraphql to child component if invalid tagSlug is provided", async () => {
const wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent tagSlugOrId="fakeSlug" />
</MockedProvider>
));
let wrapper;
act(() => {
wrapper = mount((
<MockedProvider mocks={mocks} addTypename={false}>
<TestComponent tagSlugOrId="fakeSlug" />
</MockedProvider>
));
});

await waitForFalseyProp(wrapper, "MockComponent", "isLoadingTagId");

Expand Down

0 comments on commit 0919acb

Please sign in to comment.