Skip to content

Commit d52e25c

Browse files
committed
test for dismissing a custom check
1 parent 7bd0627 commit d52e25c

File tree

6 files changed

+56
-20
lines changed

6 files changed

+56
-20
lines changed

src/Frontend/test/mocks/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const driver = makeDriver();
2525
(async () => {
2626
await driver.setUp(precondition.serviceControlWithMonitoring);
2727
//override the default mocked endpoints with a custom list
28-
await driver.setUp(precondition.hasCustomChecks(49, 2));
28+
await driver.setUp(precondition.hasCustomChecks(3, 2));
2929

3030
await driver.setUp(
3131
precondition.monitoredEndpointsNamed([

src/Frontend/test/preconditions/customChecks.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const generateGuid = () => {
1616
return crypto.randomUUID();
1717
};
1818
const customCheckTemplate = <CustomCheck>{
19-
id: "CustomChecks/6131fa95-9414-1898-9c83-c5b18587945b",
19+
id: "customchecks/6131fa95-9414-1898-9c83-c5b18587945b",
2020
custom_check_id: "SampleCustomeCheck",
2121
category: "SomeCategory",
2222
status: "Pass",
@@ -57,7 +57,7 @@ export const hasCustomChecks =
5757

5858
return {
5959
...customCheckTemplate,
60-
id: `customcheck/${newGuid}`, // New GUID for ID
60+
id: `customchecks/${newGuid}`, // New GUID for ID
6161
category: customCategory,
6262
custom_check_id: customeCheckId,
6363
status, // Fail or Pass based on index
@@ -113,7 +113,7 @@ export const setCustomChecksData = (failingCount: number, passingCount: number)
113113

114114
return {
115115
...customCheckTemplate,
116-
id: `customcheck/${newGuid}`, // New GUID for ID
116+
id: `customchecks/${newGuid}`, // New GUID for ID
117117
category: customCategory,
118118
custom_check_id: customeCheckId,
119119
status, // Fail or Pass based on index
@@ -152,11 +152,11 @@ export const getCustomChecks =
152152
});
153153
};
154154

155-
export const updateCustomCheckItem = (data: CustomCheck[], status: string) => {
155+
export const updateCustomCheckItem = (data: CustomCheck[], statusToUpdate: string) => {
156156
const itemToUpdate = data.find((item) => item.status === status);
157157

158158
if (itemToUpdate) {
159-
if (status === "Pass") {
159+
if (statusToUpdate === "Pass") {
160160
itemToUpdate.status = Status.Fail;
161161
itemToUpdate.failure_reason = "Some reason I dont know";
162162
} else {

src/Frontend/test/preconditions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { hasServiceControlMonitoringInstanceUrl } from "../preconditions/hasServ
55
export { hasUpToDateServiceControl } from "../preconditions/hasUpToDateServiceControl";
66
export { hasUpToDateServicePulse } from "../preconditions/hasUpToDateServicePulse";
77
export { errorsDefaultHandler } from "../preconditions/hasNoErrors";
8-
export { hasCustomChecksEmpty, hasCustomChecks, setCustomChecksData, getCustomChecks,updateCustomCheckItem } from "./customChecks";
8+
export { hasCustomChecksEmpty, hasCustomChecks, setCustomChecksData, getCustomChecks, updateCustomCheckItem } from "./customChecks";
99
export { hasNoDisconnectedEndpoints } from "../preconditions/hasNoDisconnectedEndpoints";
1010
export { hasNoMonitoredEndpoints, hasMonitoredEndpointsList, monitoredEndpointsNamed } from "../preconditions/hasMonitoredEndpoints";
1111
export { hasEventLogItems } from "../preconditions/hasEventLogItems";

src/Frontend/test/specs/customchecks/dismissing-custom-checks.spec.ts

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
import { test, describe } from "../../drivers/vitest/driver";
2+
import { expect } from "vitest";
3+
import * as precondition from "../../preconditions";
4+
import { customChecksListElement, customChecksDismissButtonList } from "./questions/failedCustomChecks";
5+
import { waitFor } from "@testing-library/vue";
6+
import userEvent from "@testing-library/user-event";
27

38
describe("FEATURE: Dismiss custom checks", () => {
49
describe("RULE: Dismiss button should be visible", () => {
5-
test.todo("EXAMPLE: Dismiss button should be visible on each failing custom check");
10+
test("EXAMPLE: Dismiss button is visible on each failing custom check", async ({ driver }) => {
11+
await driver.setUp(precondition.serviceControlWithMonitoring);
12+
await driver.setUp(precondition.hasCustomChecks(9, 3));
613

7-
/* SCENARIO
8-
Given 2 failing custom checks
9-
And the custom checks page is open
10-
Then each should render a dismiss button
11-
*/
14+
await driver.goTo("/custom-checks");
15+
16+
await waitFor(async () => {
17+
expect(await customChecksListElement()).toBeInTheDocument();
18+
});
19+
20+
await waitFor(async () => {
21+
expect(await customChecksDismissButtonList()).toHaveLength(9); //count of dismiss button
22+
});
23+
});
1224
});
1325
describe("RULE: Dismissing a custom check should remove from the list", () => {
14-
test.todo("EXAMPLE: The dismiss button should remove the custom check from the list when clicked");
26+
test("EXAMPLE: The dismiss button removes the custom check from the list when clicked", async ({ driver }) => {
27+
await driver.setUp(precondition.serviceControlWithMonitoring);
28+
await driver.setUp(precondition.hasCustomChecks(3, 2));
1529

16-
/* SCENARIO
17-
Given 2 failing custom checks
18-
When the dismiss button is clicked
19-
Then the dismissed custom check should be removed from the list
20-
*/
30+
await driver.goTo("/custom-checks");
31+
32+
await waitFor(async () => {
33+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
34+
});
35+
36+
//await waitFor(async () => {
37+
// const dismissButtonList = await customChecksDismissButtonList();
38+
// expect(dismissButtonList).toHaveLength(3); //count of dismiss button
39+
// const dismissButton = dismissButtonList[0];
40+
// await userEvent.click(dismissButton);
41+
// });
42+
//get one of the dismiss button
43+
// const dismissButton = await screen.getAllByRole("button", { name: /custom-check-dismiss/i })[0];
44+
45+
// Simulate user click event
46+
47+
//list count should decrease by one -
48+
//make sure that the id is notvisible on the page
49+
// await waitFor(async () => {
50+
// expect(await customChecksDismissButtonList()).toHaveLength(2); //count of dismiss button
51+
// });
52+
});
2153
});
2254
describe("RULE: Failing after a dismiss should cause the failed check to reappear", () => {
2355
test.todo("EXAMPLE: Dismissed custom check should reappear in the list when it fails");

src/Frontend/test/specs/customchecks/questions/failedCustomChecks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ export async function customChecksReportedDateList() {
4040

4141
return timeStamps;
4242
}
43+
export async function customChecksDismissButtonList() {
44+
const dismissButtonList = await screen.findAllByRole("button", { name: "custom-check-dismiss" });
45+
return dismissButtonList;
46+
}

src/Frontend/test/specs/customchecks/viewing-failing-custom-checks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("FEATURE: Failing custom checks", () => {
123123
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
124124
});
125125

126-
updateCustomCheckItem(customCheckItems, "Fail"); // Pass an existing item that is failing
126+
updateCustomCheckItem(customCheckItems, "Fail"); // an existing item that is failing
127127

128128
await driver.setUp(precondition.getCustomChecks(customCheckItems));
129129

0 commit comments

Comments
 (0)