Skip to content

Commit 95d6a26

Browse files
committed
testRun service decouple p1
1 parent fe68c92 commit 95d6a26

File tree

9 files changed

+90
-58
lines changed

9 files changed

+90
-58
lines changed

src/components/Filters.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ const Filters: React.FunctionComponent<IProps> = ({
3535
const [testStatus, setTestStatus] = testStatusState;
3636

3737
const osList = testRuns
38-
.map((t) => t.testVariation.os)
38+
.map((t) => t.os)
3939
.filter((v, i, array) => v && array.indexOf(v) === i);
4040

4141
const browserList = testRuns
42-
.map((t) => t.testVariation.browser)
42+
.map((t) => t.browser)
4343
.filter((v, i, array) => v && array.indexOf(v) === i);
4444

4545
const viewportList = testRuns
46-
.map((t) => t.testVariation.viewport)
46+
.map((t) => t.viewport)
4747
.filter((v, i, array) => v && array.indexOf(v) === i);
4848

4949
const testStatusList = testRuns

src/components/TestDetailsModal.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
} from "@material-ui/core";
1313
import { TestRun } from "../types";
1414
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
15-
import { testsService } from "../services";
15+
import {
16+
testsService,
17+
testRunService,
18+
testVariationService,
19+
} from "../services";
1620
import DrawArea from "./DrawArea";
1721
import { TestStatus } from "../types/testStatus";
1822
import { useHistory, Prompt } from "react-router-dom";
@@ -42,11 +46,11 @@ const TestDetailsModal: React.FunctionComponent<{
4246
const [selectedRectId, setSelectedRectId] = React.useState<string>();
4347

4448
const [ignoreAreas, setIgnoreAreas] = React.useState<IgnoreArea[]>(
45-
JSON.parse(testRun.testVariation.ignoreAreas)
49+
JSON.parse(testRun.ignoreAreas)
4650
);
4751

4852
React.useEffect(() => {
49-
setIgnoreAreas(JSON.parse(testRun.testVariation.ignoreAreas));
53+
setIgnoreAreas(JSON.parse(testRun.ignoreAreas));
5054
}, [testRun]);
5155

5256
const removeSelection = (event: KonvaEventObject<MouseEvent>) => {
@@ -72,7 +76,7 @@ const TestDetailsModal: React.FunctionComponent<{
7276
};
7377

7478
const isIgnoreAreasSaved = () => {
75-
return testRun.testVariation.ignoreAreas === JSON.stringify(ignoreAreas);
79+
return testRun.ignoreAreas === JSON.stringify(ignoreAreas);
7680
};
7781

7882
return (
@@ -85,7 +89,7 @@ const TestDetailsModal: React.FunctionComponent<{
8589
<Toolbar>
8690
<Grid container justify="space-between">
8791
<Grid item>
88-
<Typography variant="h6">{testRun.testVariation.name}</Typography>
92+
<Typography variant="h6">{testRun.name}</Typography>
8993
</Grid>
9094
{testRun.status === TestStatus.unresolved && (
9195
<Grid item>
@@ -135,30 +139,24 @@ const TestDetailsModal: React.FunctionComponent<{
135139
<Paper variant="outlined">
136140
<Grid container spacing={2}>
137141
<Grid item>
138-
<Typography>OS: {testRun.testVariation.os}</Typography>
142+
<Typography>OS: {testRun.os}</Typography>
139143
</Grid>
140144
<Grid item>
141-
<Typography>
142-
Browser: {testRun.testVariation.browser}
143-
</Typography>
145+
<Typography>Browser: {testRun.browser}</Typography>
144146
</Grid>
145147
<Grid item>
146-
<Typography>
147-
Viewport: {testRun.testVariation.viewport}
148-
</Typography>
148+
<Typography>Viewport: {testRun.viewport}</Typography>
149149
</Grid>
150150
<Grid item>
151-
<Typography>
152-
Diff: {testRun.diffPercent}%
153-
</Typography>
151+
<Typography>Diff: {testRun.diffPercent}%</Typography>
154152
</Grid>
155153
<Grid item>
156154
<Typography>
157155
Diff tollerance: {testRun.diffTollerancePercent}%
158156
</Typography>
159157
</Grid>
160158
<Grid item>
161-
<Typography display='inline'>Status: </Typography>
159+
<Typography display="inline">Status: </Typography>
162160
<TestStatusChip status={testRun.status} />
163161
</Grid>
164162
</Grid>
@@ -202,14 +200,16 @@ const TestDetailsModal: React.FunctionComponent<{
202200
<IconButton
203201
disabled={isIgnoreAreasSaved()}
204202
onClick={() => {
205-
testsService
206-
.setIgnoreAreas(testRun.testVariation.id, ignoreAreas)
207-
.then((testVariation) =>
208-
updateTestRun({
209-
...testRun,
210-
testVariation,
211-
})
212-
);
203+
// update in test run
204+
testRunService
205+
.setIgnoreAreas(testRun.id, ignoreAreas)
206+
.then((testRun) => updateTestRun(testRun));
207+
208+
// update in variation
209+
testVariationService.setIgnoreAreas(
210+
testRun.testVariationId,
211+
ignoreAreas
212+
);
213213
}}
214214
>
215215
<Save />
@@ -225,7 +225,7 @@ const TestDetailsModal: React.FunctionComponent<{
225225
<DrawArea
226226
width={stageWidth}
227227
height={stageHeigth}
228-
imageUrl={testRun.testVariation.baselineName}
228+
imageUrl={testRun.baselineName}
229229
ignoreAreas={[]}
230230
setIgnoreAreas={setIgnoreAreas}
231231
selectedRectId={selectedRectId}

src/components/TestRunList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ const TestRunList: React.FunctionComponent<{
6363
history.push(buildTestRunLocation(test));
6464
}}
6565
>
66-
<Typography>{test.testVariation.name}</Typography>
66+
<Typography>{test.name}</Typography>
6767
</TableCell>
6868
<TableCell>
69-
<Typography>{test.testVariation.os}</Typography>
69+
<Typography>{test.os}</Typography>
7070
</TableCell>
7171
<TableCell>
72-
<Typography>{test.testVariation.browser}</Typography>
72+
<Typography>{test.browser}</Typography>
7373
</TableCell>
7474
<TableCell>
75-
<Typography>{test.testVariation.viewport}</Typography>
75+
<Typography>{test.viewport}</Typography>
7676
</TableCell>
7777
<TableCell>
7878
<TestStatusChip status={test.status} />

src/pages/ProjectPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ const ProjectPage = () => {
9595
setFilteredTestRuns(
9696
testRuns.filter(
9797
(t) =>
98-
t.testVariation.name.includes(query) && // by query
99-
(os ? t.testVariation.os === os : true) && // by OS
100-
(viewport ? t.testVariation.viewport === viewport : true) && // by viewport
98+
t.name.includes(query) && // by query
99+
(os ? t.os === os : true) && // by OS
100+
(viewport ? t.viewport === viewport : true) && // by viewport
101101
(testStatus ? t.status === testStatus : true) && // by status
102-
(browser ? t.testVariation.browser === browser : true) // by browser
102+
(browser ? t.browser === browser : true) // by browser
103103
)
104104
);
105105
}, [query, os, browser, viewport, testStatus, testRuns]);

src/services/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from './projects.service'
33
export * from './builds.service'
44
export * from './tests.service'
55
export * from './static.service'
6-
export * from './testVariation.service'
6+
export * from './testVariation.service'
7+
export * from './testRun.service'

src/services/testRun.service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { TestRun } from "../types";
2+
import { handleResponse, authHeader } from "../_helpers/service.helpers";
3+
import { API_URL } from "../_config/api.config";
4+
import { IgnoreArea } from "../types/ignoreArea";
5+
6+
const ENDPOINT_URL = "/test-runs"
7+
8+
export const testRunService = {
9+
setIgnoreAreas
10+
};
11+
12+
function setIgnoreAreas(
13+
id: string,
14+
ignoreAreas: IgnoreArea[]
15+
): Promise<TestRun> {
16+
const requestOptions = {
17+
method: "PUT",
18+
headers: { "Content-Type": "application/json", ...authHeader() },
19+
body: JSON.stringify(ignoreAreas),
20+
};
21+
22+
return fetch(
23+
`${API_URL}${ENDPOINT_URL}/ignoreArea/${id}`,
24+
requestOptions
25+
).then(handleResponse);
26+
}

src/services/testVariation.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { TestVariation } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
4+
import { IgnoreArea } from "../types/ignoreArea";
45

56
export const testVariationService = {
67
get,
8+
setIgnoreAreas
79
};
810

911
function get(projectId: String): Promise<TestVariation[]> {
@@ -14,3 +16,19 @@ function get(projectId: String): Promise<TestVariation[]> {
1416

1517
return fetch(`${API_URL}/test-variations?projectId=${projectId}`, requestOptions).then(handleResponse);
1618
}
19+
20+
function setIgnoreAreas(
21+
variationId: string,
22+
ignoreAreas: IgnoreArea[]
23+
): Promise<TestVariation> {
24+
const requestOptions = {
25+
method: "PUT",
26+
headers: { "Content-Type": "application/json", ...authHeader() },
27+
body: JSON.stringify(ignoreAreas),
28+
};
29+
30+
return fetch(
31+
`${API_URL}/test-variations/ignoreArea/${variationId}`,
32+
requestOptions
33+
).then(handleResponse);
34+
}

src/services/tests.service.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { TestRun } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
4-
import { IgnoreArea } from "../types/ignoreArea";
5-
import { TestVariation } from "../types/testVariation";
64

75
export const testsService = {
86
get,
97
approve,
108
reject,
11-
setIgnoreAreas,
129
remove,
1310
};
1411

@@ -53,19 +50,3 @@ function remove(id: string): Promise<Number> {
5350

5451
return fetch(`${API_URL}/test/${id}`, requestOptions).then(handleResponse);
5552
}
56-
57-
function setIgnoreAreas(
58-
variationId: string,
59-
ignoreAreas: IgnoreArea[]
60-
): Promise<TestVariation> {
61-
const requestOptions = {
62-
method: "PUT",
63-
headers: { "Content-Type": "application/json", ...authHeader() },
64-
body: JSON.stringify(ignoreAreas),
65-
};
66-
67-
return fetch(
68-
`${API_URL}/test/ignoreArea/${variationId}`,
69-
requestOptions
70-
).then(handleResponse);
71-
}

src/types/testRun.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TestStatus } from "./testStatus";
2-
import { TestVariation } from "./testVariation";
32

43
export interface TestRun {
54
id: string;
@@ -9,5 +8,12 @@ export interface TestRun {
98
diffPercent: number;
109
diffTollerancePercent: number;
1110
status: TestStatus;
12-
testVariation: TestVariation;
11+
testVariationId: string;
12+
name: string;
13+
baselineName: string;
14+
os: string;
15+
browser: string;
16+
viewport: string;
17+
device: string;
18+
ignoreAreas: string;
1319
}

0 commit comments

Comments
 (0)