Skip to content

Commit 0a5ca37

Browse files
authored
test refactoring (#166)
* test refactoring
1 parent c1d2734 commit 0a5ca37

10 files changed

+316
-382
lines changed

src/_test/stub.helper.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/* global cy */
2-
import { buildsService, projectsService, testRunService } from "../services";
2+
import {
3+
buildsService,
4+
projectsService,
5+
testRunService,
6+
staticService,
7+
testVariationService,
8+
} from "../services";
39
import { Build, Project, TestRun } from "../types";
410

511
const projectStub = {
@@ -24,4 +30,19 @@ const testRunServiceStub = {
2430
cy.stub(testRunService, "getList").resolves(testRuns),
2531
};
2632

27-
export { projectStub, buildsServiceStub, testRunServiceStub };
33+
const staticServiceStub = {
34+
getImage: () => cy.stub(staticService, "getImage"),
35+
};
36+
37+
const testVariationServiceStub = {
38+
getDetails: () => cy.stub(testVariationService, "getDetails"),
39+
getList: () => cy.stub(testVariationService, "getList"),
40+
};
41+
42+
export {
43+
projectStub,
44+
buildsServiceStub,
45+
testRunServiceStub,
46+
staticServiceStub,
47+
testVariationServiceStub,
48+
};

src/_test/test.data.helper.ts

Lines changed: 215 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Project, TestRun, User } from "../types";
1+
import { Build, Project, TestRun, TestVariation, User } from "../types";
2+
import { BuildStatus } from "../types/buildStatus";
23
import { TestStatus } from "../types/testStatus";
34

4-
export const projectMock: Project = {
5+
export const TEST_PROJECT: Project = {
56
id: "someProjectId",
67
name: "Project name",
78
mainBranchName: "Main branch name",
@@ -10,7 +11,7 @@ export const projectMock: Project = {
1011
createdAt: "2020-09-14T06:57:25.845Z",
1112
};
1213

13-
export const userMock: User = {
14+
export const TEST_USER: User = {
1415
id: "1",
1516
token: 123567,
1617
apiKey: "SOME KEY SECRET",
@@ -41,3 +42,214 @@ export const testRunMock: TestRun = {
4142
baselineBranchName: "baselineBranchName",
4243
merge: false,
4344
};
45+
46+
export const TEST_VARIATION_ONE: TestVariation = {
47+
id: "testVariationId",
48+
name: "test run name",
49+
baselineName: "baselineName.png",
50+
os: "OS",
51+
browser: "browser",
52+
viewport: "viewport",
53+
device: "device",
54+
ignoreAreas: "[]",
55+
comment: "some comment",
56+
branchName: "branch name",
57+
projectId: TEST_PROJECT.id,
58+
baselines: [
59+
{
60+
id: "some baseline id1",
61+
baselineName: "baseline1.png",
62+
testRunId: "testRunId1",
63+
testVariationId: "some test variation id",
64+
createdAt: "2020-09-14T06:57:25.845Z",
65+
updatedAt: "2020-09-14T06:57:25.845Z",
66+
testRun: testRunMock,
67+
},
68+
{
69+
id: "some baseline id2",
70+
baselineName: "baseline2.png",
71+
testRunId: "testRunId2",
72+
testVariationId: "some test variation id",
73+
createdAt: "2020-09-12T06:57:25.845Z",
74+
updatedAt: "2020-09-12T06:57:25.845Z",
75+
testRun: testRunMock,
76+
},
77+
],
78+
};
79+
80+
export const TEST_VARIATION_TWO: TestVariation = {
81+
id: "some test variation id2",
82+
name: "test run name2",
83+
baselineName: "baseline2.png",
84+
os: "OS",
85+
browser: "browser",
86+
viewport: "viewport",
87+
device: "device",
88+
ignoreAreas: "[]",
89+
comment: "some comment",
90+
branchName: "branch name",
91+
projectId: TEST_PROJECT.id,
92+
baselines: [
93+
{
94+
id: "some baseline id1",
95+
baselineName: "baseline1.png",
96+
testRunId: "testRunId1",
97+
testVariationId: "some test variation id",
98+
createdAt: "2020-09-14T06:57:25.845Z",
99+
updatedAt: "2020-09-14T06:57:25.845Z",
100+
testRun: testRunMock,
101+
},
102+
{
103+
id: "some baseline id2",
104+
baselineName: "baseline2.png",
105+
testRunId: "testRunId2",
106+
testVariationId: "some test variation id",
107+
createdAt: "2020-09-12T06:57:25.845Z",
108+
updatedAt: "2020-09-12T06:57:25.845Z",
109+
testRun: testRunMock,
110+
},
111+
],
112+
};
113+
114+
export const TEST_BUILD_FAILED: Build = {
115+
id: "someId",
116+
number: 1,
117+
ciBuildId: "some build id",
118+
projectName: "Project name",
119+
branchName: "Branch name",
120+
status: BuildStatus.failed,
121+
createdAt: "2020-09-14T06:57:25.845Z",
122+
createdBy: "2020-09-14T06:57:25.845Z",
123+
testRuns: [],
124+
unresolvedCount: 0,
125+
passedCount: 2,
126+
failedCount: 1,
127+
isRunning: false,
128+
merge: false,
129+
};
130+
131+
export const TEST_BUILD_PASSED: Build = {
132+
id: "someId2",
133+
number: 2,
134+
ciBuildId: "",
135+
projectName: "Project name",
136+
branchName: "Branch name",
137+
status: BuildStatus.passed,
138+
createdAt: "2020-09-14T06:57:25.845Z",
139+
createdBy: "2020-09-14T06:57:25.845Z",
140+
testRuns: [],
141+
unresolvedCount: 0,
142+
passedCount: 2,
143+
failedCount: 0,
144+
isRunning: false,
145+
merge: false,
146+
};
147+
148+
export const TEST_BUILD_UNRESOLVED: Build = {
149+
id: "someId3",
150+
number: 3,
151+
ciBuildId: "",
152+
projectName: "Project name",
153+
branchName: "Branch name",
154+
status: BuildStatus.unresolved,
155+
createdAt: "2020-09-14T06:57:25.845Z",
156+
createdBy: "2020-09-14T06:57:25.845Z",
157+
testRuns: [],
158+
unresolvedCount: 2,
159+
passedCount: 0,
160+
failedCount: 0,
161+
isRunning: false,
162+
merge: true,
163+
};
164+
165+
export const TEST_UNRESOLVED: TestRun = {
166+
id: "some test run id",
167+
buildId: "some build id",
168+
imageName: "image.png",
169+
diffName: "diff.png",
170+
baselineName: "baseline.png",
171+
diffPercent: 1.24,
172+
diffTollerancePercent: 3.21,
173+
status: TestStatus.unresolved,
174+
testVariationId: "some test variation id",
175+
name: "test run name",
176+
os: "OS",
177+
browser: "browser",
178+
viewport: "viewport",
179+
device: "device",
180+
ignoreAreas: `[{"id":"1606901916571","x":232,"y":123,"width":166,"height":138}]`,
181+
tempIgnoreAreas: `[{"x":100,"y":300,"width":600,"height":700}]`,
182+
comment: "some comment",
183+
branchName: "branch name",
184+
baselineBranchName: "baselineBranchName",
185+
merge: false,
186+
};
187+
188+
export const TEST_RUN_APPROVED: TestRun = {
189+
id: "some test run id2",
190+
buildId: "some build id",
191+
imageName: "imageName",
192+
diffName: "diffName",
193+
diffPercent: 1.24,
194+
diffTollerancePercent: 3.21,
195+
status: TestStatus.approved,
196+
testVariationId: "some test variation id",
197+
name: "test run name2",
198+
baselineName: "baselineName",
199+
os: "OS",
200+
browser: "browser",
201+
viewport: "viewport",
202+
device: "device",
203+
ignoreAreas: "[]",
204+
tempIgnoreAreas: "[]",
205+
comment: "some comment",
206+
branchName: "branch name",
207+
baselineBranchName: "baselineBranchName",
208+
merge: false,
209+
};
210+
211+
export const TEST_RUN_NEW: TestRun = {
212+
id: "some test run id3",
213+
buildId: "some build id",
214+
imageName: "imageName",
215+
diffName: "diffName",
216+
diffPercent: 1.24,
217+
diffTollerancePercent: 3.21,
218+
status: TestStatus.new,
219+
testVariationId: "some test variation id",
220+
name: "test run name3",
221+
baselineName: "baselineName",
222+
os: "",
223+
browser: "",
224+
viewport: "",
225+
device: "",
226+
ignoreAreas: "[]",
227+
tempIgnoreAreas: "[]",
228+
comment: "some comment",
229+
branchName: "branch name",
230+
baselineBranchName: "baselineBranchName",
231+
merge: false,
232+
};
233+
234+
export const TEST_RUN_OK: TestRun = {
235+
id: "some test run id4",
236+
buildId: "some build id",
237+
imageName: "imageName",
238+
diffName: "diffName",
239+
diffPercent: 1.24,
240+
diffTollerancePercent: 3.21,
241+
status: TestStatus.ok,
242+
testVariationId: "some test variation id",
243+
name: "test run name4",
244+
baselineName: "baselineName",
245+
os: "",
246+
browser: "",
247+
viewport: "",
248+
device: "",
249+
ignoreAreas: "[]",
250+
tempIgnoreAreas: "[]",
251+
comment: "some comment",
252+
branchName: "branch name",
253+
baselineBranchName: "baselineBranchName",
254+
merge: false,
255+
};

src/components/Header.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Header from "./Header";
55
import { AuthProvider } from "../contexts";
66
import { BrowserRouter } from "react-router-dom";
77
import { haveUserLogged } from "../_test/precondition.helper";
8-
import { userMock } from "../_test/test.data.helper";
8+
import { TEST_USER } from "../_test/test.data.helper";
99

1010
describe("Header", () => {
1111
describe("image", () => {
@@ -23,7 +23,7 @@ describe("Header", () => {
2323
});
2424

2525
it("Logged", () => {
26-
haveUserLogged(userMock);
26+
haveUserLogged(TEST_USER);
2727
mount(
2828
<BrowserRouter>
2929
<AuthProvider>

src/pages/LoginPage.spec.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
import React from "react";
33
import LoginPage from "./LoginPage";
44
import { mountVrtComponent } from "../_test/test.moun.helper";
5-
import { projectStub } from "../_test/stub.helper";
65

76
describe("Login page", () => {
8-
before(() => {
9-
projectStub.getAll([]);
10-
});
117
it("image", () => {
128
mountVrtComponent({
139
component: <LoginPage />,

src/pages/ProfilePage.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
haveUserLogged,
66
haveWindowsEnvSet,
77
} from "../_test/precondition.helper";
8-
import { projectMock, userMock } from "../_test/test.data.helper";
8+
import { TEST_PROJECT, TEST_USER } from "../_test/test.data.helper";
99
import { mountVrtComponent } from "../_test/test.moun.helper";
1010
import { projectStub } from "../_test/stub.helper";
1111

1212
describe("Profile page", () => {
1313
before(() => {
14-
haveUserLogged(userMock);
14+
haveUserLogged(TEST_USER);
1515
haveWindowsEnvSet({
1616
REACT_APP_API_URL: "http://localhost:4200",
1717
});
18-
projectStub.getAll([projectMock]);
18+
projectStub.getAll([TEST_PROJECT]);
1919
});
2020

2121
it("image", () => {

src/pages/ProjectListPage.spec.tsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
/* global cy */
22
import React from "react";
33
import ProjectListPage from "./ProjectListPage";
4-
import { projectsService } from "../services";
54
import { haveUserLogged } from "../_test/precondition.helper";
6-
import { userMock } from "../_test/test.data.helper";
5+
import { TEST_PROJECT, TEST_USER } from "../_test/test.data.helper";
76
import { mountVrtComponent } from "../_test/test.moun.helper";
7+
import { projectStub } from "../_test/stub.helper";
88

99
describe("Project List page", () => {
10-
before(() => {
11-
haveUserLogged(userMock);
12-
});
13-
1410
it("image", () => {
15-
cy.stub(projectsService, "getAll").resolves([
16-
{
17-
id: "some id",
18-
name: "Project name",
19-
mainBranchName: "Main branch name",
20-
builds: [],
21-
updatedAt: "2020-09-14T06:57:25.845Z",
22-
createdAt: "2020-09-14T06:57:25.845Z",
23-
},
24-
]);
11+
haveUserLogged(TEST_USER);
12+
projectStub.getAll([TEST_PROJECT]);
2513

2614
mountVrtComponent({
2715
component: <ProjectListPage />,

0 commit comments

Comments
 (0)