Skip to content

Commit cbd0969

Browse files
committed
testRun related notifications handled
1 parent 6d46f8d commit cbd0969

File tree

5 files changed

+82
-31
lines changed

5 files changed

+82
-31
lines changed

src/components/TestDetailsModal.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { routes } from "../constants";
4040
import { useTestRunDispatch, updateTestRun, selectTestRun } from "../contexts";
4141
import { DrawArea } from "./DrawArea";
4242
import { CommentsPopper } from "./CommentsPopper";
43+
import { useSnackbar } from "notistack";
4344

4445
const useStyles = makeStyles((theme) => ({
4546
imageContainer: {
@@ -57,6 +58,7 @@ const TestDetailsModal: React.FunctionComponent<{
5758
}> = ({ testRun }) => {
5859
const classes = useStyles();
5960
const history = useHistory();
61+
const { enqueueSnackbar } = useSnackbar();
6062
const testRunDispatch = useTestRunDispatch();
6163

6264
const stageWidth = (window.innerWidth / 2) * 0.9;
@@ -177,6 +179,16 @@ const TestDetailsModal: React.FunctionComponent<{
177179
.then((testRun) => {
178180
updateTestRun(testRunDispatch, testRun);
179181
})
182+
.then(() =>
183+
enqueueSnackbar("Approved", {
184+
variant: "success",
185+
})
186+
)
187+
.catch((err) =>
188+
enqueueSnackbar(err, {
189+
variant: "error",
190+
})
191+
)
180192
}
181193
>
182194
Approve
@@ -186,9 +198,21 @@ const TestDetailsModal: React.FunctionComponent<{
186198
<Button
187199
color="secondary"
188200
onClick={() =>
189-
testRunService.reject(testRun.id).then((testRun) => {
190-
updateTestRun(testRunDispatch, testRun);
191-
})
201+
testRunService
202+
.reject(testRun.id)
203+
.then((testRun) => {
204+
updateTestRun(testRunDispatch, testRun);
205+
})
206+
.then(() =>
207+
enqueueSnackbar("Rejected", {
208+
variant: "success",
209+
})
210+
)
211+
.catch((err) =>
212+
enqueueSnackbar(err, {
213+
variant: "error",
214+
})
215+
)
192216
}
193217
>
194218
Reject
@@ -285,6 +309,26 @@ const TestDetailsModal: React.FunctionComponent<{
285309
.then((testRun) =>
286310
updateTestRun(testRunDispatch, testRun)
287311
)
312+
.then(() =>
313+
enqueueSnackbar("Diff recalculated", {
314+
variant: "success",
315+
})
316+
)
317+
.catch((err) =>
318+
enqueueSnackbar(err, {
319+
variant: "error",
320+
})
321+
)
322+
)
323+
.then(() =>
324+
enqueueSnackbar("Ignore areas are updated", {
325+
variant: "success",
326+
})
327+
)
328+
.catch((err) =>
329+
enqueueSnackbar(err, {
330+
variant: "error",
331+
})
288332
);
289333

290334
// update in variation

src/components/TestRunList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import {
2525
} from "../contexts";
2626
import { Skeleton } from "@material-ui/lab";
2727
import { SkeletonList } from "./SkeletonList";
28+
import { useSnackbar } from "notistack";
2829

2930
const TestRunList: React.FunctionComponent<{
3031
items: TestRun[];
3132
}> = ({ items }) => {
33+
const { enqueueSnackbar } = useSnackbar();
3234
const { selectedTestRunId, loading } = useTestRunState();
3335
const testRunDispatch = useTestRunDispatch();
3436
const history = useHistory();
@@ -134,7 +136,17 @@ const TestRunList: React.FunctionComponent<{
134136
</MenuItem>
135137
<MenuItem
136138
onClick={() => {
137-
deleteTestRun(testRunDispatch, selectedTestRun.id);
139+
deleteTestRun(testRunDispatch, selectedTestRun.id)
140+
.then((testRun) => {
141+
enqueueSnackbar(`Removed`, {
142+
variant: "success",
143+
});
144+
})
145+
.catch((err) =>
146+
enqueueSnackbar(err, {
147+
variant: "error",
148+
})
149+
);
138150
handleClose();
139151
}}
140152
>

src/contexts/testRun.context.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,18 @@ function useTestRunDispatch() {
165165
async function getTestRunList(dispatch: Dispatch, buildId: string) {
166166
dispatch({ type: "request" });
167167

168-
testRunService
169-
.getList(buildId)
170-
.then((items) => {
171-
dispatch({ type: "get", payload: items });
172-
})
173-
.catch((error) => {
174-
console.log(error.toString());
175-
});
168+
return testRunService.getList(buildId).then((items) => {
169+
dispatch({ type: "get", payload: items });
170+
});
176171
}
177172

178173
async function deleteTestRun(dispatch: Dispatch, id: string) {
179-
testRunService
180-
.remove(id)
181-
.then((isDeleted) => {
182-
if (isDeleted) {
183-
dispatch({ type: "delete", payload: id });
184-
}
185-
})
186-
.catch((error) => {
187-
console.log(error.toString());
188-
});
174+
dispatch({ type: "request" });
175+
176+
return testRunService.remove(id).then((testRun) => {
177+
dispatch({ type: "delete", payload: id });
178+
return testRun;
179+
});
189180
}
190181

191182
async function selectTestRun(dispatch: Dispatch, id: string | undefined) {

src/pages/ProjectPage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ const ProjectPage = () => {
9999

100100
useEffect(() => {
101101
if (selectedBuildId) {
102-
getTestRunList(testRunDispatch, selectedBuildId);
102+
getTestRunList(testRunDispatch, selectedBuildId).catch((err) =>
103+
enqueueSnackbar(err, {
104+
variant: "error",
105+
})
106+
);
103107
}
104-
}, [selectedBuildId, testRunDispatch]);
108+
}, [selectedBuildId, testRunDispatch, enqueueSnackbar]);
105109

106110
useEffect(() => {
107111
const queryParams = getQueryParams(location.search);

src/services/testRun.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const testRunService = {
1515
setComment,
1616
};
1717

18-
function getList(buildId: string): Promise<TestRun[]> {
18+
async function getList(buildId: string): Promise<TestRun[]> {
1919
const requestOptions = {
2020
method: "GET",
2121
headers: authHeader(),
@@ -27,7 +27,7 @@ function getList(buildId: string): Promise<TestRun[]> {
2727
).then(handleResponse);
2828
}
2929

30-
function remove(id: string): Promise<Number> {
30+
async function remove(id: string): Promise<TestRun> {
3131
const requestOptions = {
3232
method: "DELETE",
3333
headers: authHeader(),
@@ -38,7 +38,7 @@ function remove(id: string): Promise<Number> {
3838
);
3939
}
4040

41-
function recalculateDiff(id: string): Promise<TestRun> {
41+
async function recalculateDiff(id: string): Promise<TestRun> {
4242
const requestOptions = {
4343
method: "GET",
4444
headers: authHeader(),
@@ -50,7 +50,7 @@ function recalculateDiff(id: string): Promise<TestRun> {
5050
).then(handleResponse);
5151
}
5252

53-
function approve(id: string, merge: boolean): Promise<TestRun> {
53+
async function approve(id: string, merge: boolean): Promise<TestRun> {
5454
const requestOptions = {
5555
method: "GET",
5656
headers: authHeader(),
@@ -62,7 +62,7 @@ function approve(id: string, merge: boolean): Promise<TestRun> {
6262
).then(handleResponse);
6363
}
6464

65-
function reject(id: string): Promise<TestRun> {
65+
async function reject(id: string): Promise<TestRun> {
6666
const requestOptions = {
6767
method: "GET",
6868
headers: authHeader(),
@@ -73,7 +73,7 @@ function reject(id: string): Promise<TestRun> {
7373
);
7474
}
7575

76-
function setIgnoreAreas(
76+
async function setIgnoreAreas(
7777
id: string,
7878
ignoreAreas: IgnoreArea[]
7979
): Promise<TestRun> {
@@ -89,7 +89,7 @@ function setIgnoreAreas(
8989
).then(handleResponse);
9090
}
9191

92-
function setComment(id: string, comment: string): Promise<TestRun> {
92+
async function setComment(id: string, comment: string): Promise<TestRun> {
9393
const requestOptions = {
9494
method: "PUT",
9595
headers: { "Content-Type": "application/json", ...authHeader() },

0 commit comments

Comments
 (0)