Skip to content

Commit 9ea734d

Browse files
Fix failing tests
1 parent bf1d423 commit 9ea734d

8 files changed

Lines changed: 84 additions & 32 deletions

File tree

src/application/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useEffect, useState } from "react";
22
import { useReactiveVar, gql, useQuery, makeVar } from "@apollo/client";
33

4-
import { currentScreen, Screens } from "./components/Layouts/Navigation";
4+
import { currentScreen } from "./components/Layouts/Navigation";
5+
import { Screens } from "./components/Layouts/screens";
56
import { Queries } from "./components/Queries/Queries";
67
import { Mutations } from "./components/Mutations/Mutations";
78
import { Explorer } from "./components/Explorer/Explorer";
@@ -69,8 +70,8 @@ export const App = (): JSX.Element => {
6970
<Screen
7071
isVisible={undefined}
7172
navigationProps={{
72-
queriesCount: data?.client?.watchedQueries?.count,
73-
mutationsCount: data?.client?.mutationLog?.count,
73+
queriesCount: data?.client?.watchedQueries?.count ?? 0,
74+
mutationsCount: data?.client?.mutationLog?.count ?? 0,
7475
}}
7576
embeddedExplorerProps={{
7677
embeddedExplorerIFrame,

src/application/__tests__/App.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from "react";
22
import { waitFor } from "@testing-library/react";
33

44
import { renderWithApolloClient } from "../utilities/testing/renderWithApolloClient";
5-
import { currentScreen, Screens } from "../components/Layouts/Navigation";
5+
import { currentScreen } from "../components/Layouts/Navigation";
66
import { App, reloadStatus } from "../App";
7+
import { Screens } from "../components/Layouts/screens";
78

89
jest.mock("../components/Queries/Queries", () => ({
910
Queries: ({ navigationProps }) => (
@@ -37,7 +38,7 @@ describe("<App />", () => {
3738

3839
test("after reload, renders the Queries screen", async () => {
3940
currentScreen(Screens.Mutations);
40-
const { getByText, debug } = renderWithApolloClient(<App />);
41+
const { getByText } = renderWithApolloClient(<App />);
4142
const element = getByText("Mutations (0)");
4243
expect(element).toBeInTheDocument();
4344
await waitFor(() => {

src/application/components/Cache/__tests__/Cache.test.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { within, waitFor, fireEvent } from "@testing-library/react";
33

44
import { Cache } from "../Cache";
55
import { renderWithApolloClient } from "../../../utilities/testing/renderWithApolloClient";
6-
import { client, writeData } from "../../../index";
6+
import { client, currentClient, writeData } from "../../../index";
77

88
const CACHE_DATA = {
99
"Result:1": {
@@ -65,15 +65,20 @@ describe("Cache component tests", () => {
6565

6666
describe("With cache data", () => {
6767
beforeEach(() => {
68-
client.resetStore();
69-
68+
const clientId = "client-1";
69+
currentClient(clientId);
7070
writeData({
71+
id: clientId,
7172
queries: [],
7273
mutations: [],
7374
cache: JSON.stringify(CACHE_DATA),
7475
});
7576
});
7677

78+
afterEach(() => {
79+
client.resetStore();
80+
});
81+
7782
it("should show list of root cache ids in the sidebar", () => {
7883
const { getByTestId } = renderWithApolloClient(
7984
<Cache navigationProps={navigationProps} />
@@ -122,7 +127,10 @@ describe("Cache component tests", () => {
122127
const selectedMainStyles = "background-color: yellow";
123128

124129
beforeEach(() => {
130+
const clientId = "client-1";
131+
currentClient(clientId);
125132
writeData({
133+
id: clientId,
126134
queries: [],
127135
mutations: [],
128136
cache: JSON.stringify(CACHE_DATA),

src/application/components/Layouts/Navigation.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import { rem } from "polished";
77
import { colors } from "@apollo/space-kit/colors";
88
import { ApolloLogo } from "@apollo/space-kit/icons/ApolloLogo";
99
import { clients, currentClient } from "../..";
10-
11-
export enum Screens {
12-
Cache = "cache",
13-
Queries = "queries",
14-
Mutations = "mutations",
15-
Explorer = "explorer",
16-
}
10+
import { Screens } from "./screens";
1711

1812
type NavButtonProps = {
1913
isSelected: boolean;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum Screens {
2+
Cache = "cache",
3+
Queries = "queries",
4+
Mutations = "mutations",
5+
Explorer = "explorer",
6+
}

src/application/components/Mutations/__tests__/Mutations.test.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ import { within, waitFor } from "@testing-library/react";
33
import user from "@testing-library/user-event";
44

55
import { renderWithApolloClient } from "../../../utilities/testing/renderWithApolloClient";
6-
import { client, GET_MUTATIONS } from "../../../index";
6+
import { client, currentClient, GET_MUTATIONS } from "../../../index";
77
import { Mutations } from "../Mutations";
88

99
jest.mock("../MutationViewer", () => ({
1010
MutationViewer: () => null,
1111
}));
1212

13+
14+
const clientId = "client-1";
15+
1316
describe("<Mutations />", () => {
1417
const mutations = [
1518
{
1619
id: 0,
20+
clientId,
1721
__typename: "Mutation",
1822
name: null,
1923
},
2024
{
2125
id: 1,
26+
clientId,
2227
__typename: "Mutation",
2328
name: "AddColorToFavorites",
2429
},
@@ -34,14 +39,22 @@ describe("<Mutations />", () => {
3439
});
3540

3641
test("queries render in the sidebar", async () => {
42+
currentClient(clientId);
3743
client.writeQuery({
3844
query: GET_MUTATIONS,
3945
data: {
40-
mutationLog: {
41-
mutations,
42-
count: mutations.length,
43-
},
46+
client: {
47+
id: clientId,
48+
__typename: "Client",
49+
mutationLog: {
50+
mutations,
51+
count: mutations.length,
52+
},
53+
}
4454
},
55+
variables: {
56+
clientId
57+
}
4558
});
4659

4760
const { getByTestId } = renderWithApolloClient(
@@ -63,14 +76,22 @@ describe("<Mutations />", () => {
6376
});
6477

6578
test("renders query name", async () => {
79+
currentClient(clientId)
6680
client.writeQuery({
6781
query: GET_MUTATIONS,
6882
data: {
69-
mutationLog: {
70-
mutations,
71-
count: mutations.length,
72-
},
83+
client: {
84+
id: clientId,
85+
__typename: "Client",
86+
mutationLog: {
87+
mutations,
88+
count: mutations.length,
89+
}
90+
}
7391
},
92+
variables: {
93+
clientId
94+
}
7495
});
7596

7697
const { getByTestId } = renderWithApolloClient(

src/application/components/Queries/RunInExplorerButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
postMessageToEmbed,
88
SET_OPERATION,
99
} from "../Explorer/postMessageHelpers";
10-
import { currentScreen, Screens } from "../Layouts/Navigation";
10+
import { currentScreen } from "../Layouts/Navigation";
11+
import { Screens } from "../Layouts/screens";
1112

1213
interface RunInExplorerButtonProps {
1314
operation: string;

src/application/components/Queries/__tests__/Queries.test.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ import { within, waitFor } from "@testing-library/react";
33
import user from "@testing-library/user-event";
44

55
import { renderWithApolloClient } from "../../../utilities/testing/renderWithApolloClient";
6-
import { client, GET_QUERIES } from "../../../index";
6+
import { client, currentClient, GET_QUERIES } from "../../../index";
77
import { Queries } from "../Queries";
88

99
jest.mock("../QueryViewer", () => ({
1010
QueryViewer: () => null,
1111
}));
1212

13+
const clientId = "client-1";
14+
1315
describe("<Queries />", () => {
1416
const queries = [
1517
{
1618
id: 0,
1719
__typename: "WatchedQuery",
20+
clientId,
1821
name: null,
1922
},
2023
{
2124
id: 1,
2225
__typename: "WatchedQuery",
26+
clientId,
2327
name: "GetColors",
2428
},
2529
];
@@ -34,14 +38,22 @@ describe("<Queries />", () => {
3438
});
3539

3640
test("queries render in the sidebar", async () => {
41+
currentClient(clientId);
3742
client.writeQuery({
3843
query: GET_QUERIES,
3944
data: {
40-
watchedQueries: {
41-
queries,
42-
count: queries.length,
45+
client: {
46+
id: clientId,
47+
__typename: "Client",
48+
watchedQueries: {
49+
queries,
50+
count: queries.length,
51+
},
4352
},
4453
},
54+
variables: {
55+
clientId,
56+
},
4557
});
4658

4759
const { getByTestId } = renderWithApolloClient(
@@ -61,14 +73,22 @@ describe("<Queries />", () => {
6173
});
6274

6375
test("renders query name", async () => {
76+
currentClient(clientId);
6477
client.writeQuery({
6578
query: GET_QUERIES,
6679
data: {
67-
watchedQueries: {
68-
queries,
69-
count: queries.length,
80+
client: {
81+
id: clientId,
82+
__typename: "Client",
83+
watchedQueries: {
84+
queries,
85+
count: queries.length,
86+
},
7087
},
7188
},
89+
variables: {
90+
clientId,
91+
},
7292
});
7393

7494
const { getByTestId } = renderWithApolloClient(

0 commit comments

Comments
 (0)