Skip to content
This repository was archived by the owner on Mar 13, 2021. It is now read-only.

Commit b4ae11b

Browse files
author
Marcelo
committed
1 parent 53b5792 commit b4ae11b

File tree

14 files changed

+151
-53
lines changed

14 files changed

+151
-53
lines changed

.circleci/config.yml

+22-23
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,19 @@ jobs:
5252
- .cache/Cypress
5353
key: v1-dependencies-{{ checksum "package.json" }}
5454

55-
# test:
56-
# docker:
57-
# - image: circleci/node:10
58-
# working_directory: ~/app
59-
# steps:
60-
# - checkout
61-
# - restore_cache:
62-
# keys:
63-
# - v1-dependencies-{{ checksum "package.json" }}
64-
# - v1-dependencies-
65-
# - run:
66-
# name: Start the application
67-
# command: NODE_ENV=production yarn start
68-
# background: true
69-
# - run:
70-
# name: Run tests
71-
# command: yarn e2e-wait
55+
test:
56+
docker:
57+
- image: circleci/node:10
58+
working_directory: ~/app
59+
steps:
60+
- checkout
61+
- restore_cache:
62+
keys:
63+
- v1-dependencies-{{ checksum "package.json" }}
64+
- v1-dependencies-
65+
- run:
66+
name: Run unit tests
67+
command: yarn test-client
7268

7369
cypress/run:
7470
docker:
@@ -104,10 +100,13 @@ workflows:
104100
- build:
105101
requires:
106102
- setup
107-
- cypress/run:
108-
yarn: true
109-
cache-key: 'yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}'
110-
start: yarn start
111-
wait-on: "http-get://localhost:3000"
112-
requires:
103+
- test
104+
requires:
113105
- build
106+
# - cypress/run:
107+
# yarn: true
108+
# cache-key: 'yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}'
109+
# start: yarn start
110+
# wait-on: "http-get://localhost:3000"
111+
# requires:
112+
# - build

azure-pipelines.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ steps:
88
- task: NodeTool@0
99
inputs:
1010
versionSpec: "10.x"
11-
displayName: "Install dependencies and build app"
11+
displayName: "Install node"
1212

1313
- script: |
1414
yarn install
1515
yarn build
16-
displayName: "yarn install and build"
16+
displayName: "Install dependencies and build app"
17+
18+
- script: |
19+
yarn test-client
20+
displayName: "Run unit tests"

src/client/modules/auth/AuthConnector.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
GetGroupIdFromUserIdGetGroupIdFromUserId,
44
GetUserIdFromSessionGetUserIdFromSession
55
} from "../../__types__/typeDefs";
6-
import Home from "../home/ui";
6+
import { Home } from "../home/ui";
77
import { Auth } from "./ui";
88

99
interface Props {

src/client/modules/controller/ui/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Controller: React.FunctionComponent<Props> = props => {
5959
<Query<GetThingFromTopicQuery, GetThingFromTopicVariables>
6060
query={getThingFromTopic}
6161
variables={{
62-
topic: topic
62+
topic
6363
}}
6464
>
6565
{({ data, loading }) => {
@@ -112,7 +112,7 @@ const Controller: React.FunctionComponent<Props> = props => {
112112
{
113113
query: getThingFromTopic,
114114
variables: {
115-
topic: topic
115+
topic
116116
}
117117
}
118118
]}
@@ -125,7 +125,7 @@ const Controller: React.FunctionComponent<Props> = props => {
125125
await mutate({
126126
variables: {
127127
toggle: JSON.stringify(thingState),
128-
topic: topic
128+
topic
129129
}
130130
});
131131
}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from "react";
2+
import "@testing-library/jest-dom/extend-expect";
3+
import { cleanup, wait } from "@testing-library/react";
4+
import { renderWithRouter } from "../../../../../../utils/renderWithRouter";
5+
import { Components } from "..";
6+
import { act } from "react-dom/test-utils";
7+
8+
afterEach(cleanup);
9+
10+
describe("<Components /> test case", () => {
11+
test("Renders loading feedback and no components", async () => {
12+
const { container } = renderWithRouter(
13+
<Components groupId={{ id: "1" }} />,
14+
{
15+
route: "/"
16+
}
17+
);
18+
19+
act(() => {
20+
expect(container.innerHTML).toMatch("loading...");
21+
});
22+
23+
await wait(() => {
24+
expect(container.innerHTML).toMatch("You have no components yet");
25+
});
26+
});
27+
});

src/client/modules/home/ui/components/Components/index.tsx

+20-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const Components: React.FunctionComponent<Props> = props => {
2020
"This is the topic which you need to subscribe the related module to.";
2121

2222
return (
23-
<div className="components">
23+
<div className="components" data-testid="components">
2424
<Query<GetThingsFromGroupIdQuery, GetThingsFromGroupIdVariables>
2525
query={getThingsFromGroupId}
2626
variables={{
@@ -35,31 +35,45 @@ export const Components: React.FunctionComponent<Props> = props => {
3535
data.getThingsFromGroupId.length === 0
3636
) {
3737
return (
38-
<div className="component no-component">
38+
<div
39+
className="component no-component"
40+
data-testid="no-component"
41+
>
3942
<span>You have no components yet</span>
4043
</div>
4144
);
4245
}
4346
return (
4447
<>
4548
{help ? (
46-
<div className="help-box">
49+
<div className="help-box" data-testid="help-box">
4750
<span>{helpText}</span>
4851
</div>
4952
) : null}
5053
{data.getThingsFromGroupId.map((thing, i) => {
5154
return (
5255
<React.Fragment key={i}>
5356
<Link to={thing.topic}>
54-
<div className="component" key={i}>
55-
<div className="component-space">
57+
<div
58+
className="component"
59+
key={i}
60+
data-testid={`component-${i}`}
61+
>
62+
<div
63+
className="component-space"
64+
data-testid={`component-space-${i}`}
65+
>
5666
<span>{thing.space}</span>
5767
</div>
58-
<div className="component-itself">
68+
<div
69+
className="component-itself"
70+
data-testid={`component-itself-${i}`}
71+
>
5972
<span>{thing.component}</span>
6073
</div>
6174
<div
6275
className="component-topic"
76+
data-testid={`component-topic-${i}`}
6377
onMouseEnter={() => setHelp(true)}
6478
onMouseLeave={() => setHelp(false)}
6579
>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from "react";
2+
import "@testing-library/jest-dom/extend-expect";
3+
import { cleanup, wait } from "@testing-library/react";
4+
import { renderWithRouter } from "../../../../../../utils/renderWithRouter";
5+
import { ComponentsDashboard } from "..";
6+
7+
afterEach(cleanup);
8+
9+
describe("<ComponentsDashboard /> test case", () => {
10+
test("Full component rendering/navigation", async () => {
11+
const { getByTestId } = renderWithRouter(
12+
<ComponentsDashboard groupId={{ id: "1" }} />,
13+
{
14+
route: "/"
15+
}
16+
);
17+
18+
await wait(() => {
19+
expect(getByTestId("components-dashboard-wrapper")).toBeInTheDocument();
20+
expect(getByTestId("components-dashboard")).toBeInTheDocument();
21+
});
22+
});
23+
});

src/client/modules/home/ui/components/ComponentsDashboard/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ export const ComponentsDashboard: React.FunctionComponent<Props> = observer(
1919
return (
2020
<>
2121
<StatusBar groupId={props.groupId} />
22-
<div className="components-dashboard-wrapper">
23-
<div className="components-dashboard">
22+
<div
23+
className="components-dashboard-wrapper"
24+
data-testid="components-dashboard-wrapper"
25+
>
26+
<div
27+
className="components-dashboard"
28+
data-testid="components-dashboard"
29+
>
2430
<NewComponentButton />
2531
{newComponentStore.form ? (
2632
<NewComponentForm groupId={props.groupId} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from "react";
2+
import "@testing-library/jest-dom/extend-expect";
3+
import { cleanup } from "@testing-library/react";
4+
import { renderWithRouter } from "../../../../../../utils/renderWithRouter";
5+
import { ErrorMessage } from "..";
6+
7+
afterEach(cleanup);
8+
9+
describe("<ErrorMessage /> test case", () => {
10+
test("Full component rendering/navigation", () => {
11+
const errorMessage = "Oooops, this is an error message";
12+
const { getByTestId, getByText } = renderWithRouter(
13+
<ErrorMessage errorMessage={errorMessage} />
14+
);
15+
16+
expect(getByTestId("error-message-wrapper")).toBeInTheDocument();
17+
expect(getByTestId("error-message")).toBeInTheDocument();
18+
expect(getByText(errorMessage)).toBeInTheDocument();
19+
});
20+
});

src/client/modules/home/ui/components/ErrorMessage/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ interface Props {
77

88
export const ErrorMessage: React.SFC<Props> = props => {
99
return (
10-
<div className="error-message-wrapper">
11-
<div className="error">
10+
<div className="error-message-wrapper" data-testid="error-message-wrapper">
11+
<div className="error-message" data-testid="error-message">
1212
<span>{props.errorMessage}</span>
1313
</div>
1414
</div>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import * as React from "react";
2-
import Home from "../..";
2+
import { Home } from "../../";
33
import { renderWithRouter } from "../../../../../utils/renderWithRouter";
44
import "@testing-library/jest-dom/extend-expect";
5+
import { cleanup, wait } from "@testing-library/react";
6+
7+
afterEach(cleanup);
58

69
describe("<Home /> test case", () => {
7-
test("Full component rendering/navigation", () => {
8-
const { container, getByTestId } = renderWithRouter(
9-
<Home groupId={{ id: "1" }} />
10-
);
10+
test("Full component rendering/navigation", async () => {
11+
const { getByTestId } = renderWithRouter(<Home groupId={{ id: "1" }} />, {
12+
route: "/"
13+
});
1114

12-
expect(getByTestId("home-wrapper")).toBeInTheDocument();
13-
expect(getByTestId("home")).toBeInTheDocument();
15+
await wait(() => {
16+
expect(getByTestId("home-wrapper")).toBeInTheDocument();
17+
expect(getByTestId("home")).toBeInTheDocument();
18+
});
1419
});
1520
});

src/client/modules/home/ui/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
groupId: GetGroupIdFromUserIdGetGroupIdFromUserId;
88
}
99

10-
const Home: React.FunctionComponent<Props> = props => {
10+
export const Home: React.FunctionComponent<Props> = props => {
1111
return (
1212
<div className="home-wrapper" data-testid="home-wrapper">
1313
<div className="home" data-testid="home">
@@ -16,5 +16,3 @@ const Home: React.FunctionComponent<Props> = props => {
1616
</div>
1717
);
1818
};
19-
20-
export default Home;

src/client/utils/renderWithRouter.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import * as React from "react";
22
import { createMemoryHistory, MemoryHistory } from "history";
33
import { render } from "@testing-library/react";
44
import { Router } from "react-router";
5-
import { MockedProvider } from "@apollo/react-testing";
5+
import { MockedProvider, MockedResponse } from "@apollo/react-testing";
66

77
export const renderWithRouter = (
88
ui: React.ReactElement,
99
{
1010
route = "/",
1111
history = createMemoryHistory({ initialEntries: [route] })
12-
}: { route?: string; history?: MemoryHistory<any> } = {}
12+
}: { route?: string; history?: MemoryHistory<any> } = {},
13+
mocks?: MockedResponse[]
1314
) => {
1415
return {
1516
...render(
16-
<MockedProvider>
17+
<MockedProvider mocks={mocks} addTypename={false}>
1718
<Router history={history}>{ui}</Router>
1819
</MockedProvider>
1920
),

tslint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"curly": [false, "ignore-same-line"],
2626
"no-shadowed-variable": false,
2727
"interface-name": false,
28-
"no-unused-expression": false
28+
"no-unused-expression": false,
29+
"interface-over-type-literal": false
2930
},
3031
"rulesDirectory": []
3132
}

0 commit comments

Comments
 (0)