Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update Apollo packages to support hooks #5427

Merged
merged 3 commits into from
Aug 7, 2019
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
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
Loading