Skip to content

Commit 7bd0627

Browse files
committed
Added the following tests- When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check, A failing custom check that begins passing is auto-refreshed and removed from the list on the custom checks tab
1 parent 7309ac0 commit 7bd0627

File tree

4 files changed

+127
-20
lines changed

4 files changed

+127
-20
lines changed

src/Frontend/test/preconditions/customChecks.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import CustomCheck from "@/resources/CustomCheck";
1+
import CustomCheck, { Status } from "@/resources/CustomCheck";
22
import { SetupFactoryOptions } from "../driver";
33
const emptyContent = JSON.stringify([]);
44

@@ -88,3 +88,80 @@ export const hasCustomChecks =
8888
};
8989
});
9090
};
91+
92+
export const setCustomChecksData = (failingCount: number, passingCount: number) => () => {
93+
// Calculate total count
94+
const totalCount = failingCount + passingCount;
95+
96+
// Create checks (both failing and passing)
97+
const customChecks = Array.from({ length: totalCount }).map((_, index) => {
98+
// Generate the date based on the index
99+
const date = new Date();
100+
date.setDate(date.getDate() - index); // Subtract `index` days from the current date
101+
const reportedAt = date.toISOString(); // Convert to ISO string format
102+
103+
// Determine status and failure reason
104+
const status = index < failingCount ? Status.Fail : Status.Pass;
105+
const failureReason = status === Status.Fail ? `configured to fail on endpoint ${index}` : "";
106+
107+
// Generate a new GUID for the ID and host_id
108+
const newGuid = generateGuid();
109+
const originatingEndpointName = `endpoint ${index}`;
110+
const originatingHost = `ABC ${index}`;
111+
const customCategory = `Some Category ${index}`;
112+
const customeCheckId = `SampleCustomeCheck ${index}`;
113+
114+
return {
115+
...customCheckTemplate,
116+
id: `customcheck/${newGuid}`, // New GUID for ID
117+
category: customCategory,
118+
custom_check_id: customeCheckId,
119+
status, // Fail or Pass based on index
120+
failure_reason: failureReason, // Failure reason or empty for passing
121+
reported_at: reportedAt, // Autogenerated reported_at based on index
122+
originating_endpoint: {
123+
name: originatingEndpointName, // Endpoint name based on index
124+
host_id: newGuid, // New GUID for host_id
125+
host: originatingHost, // Host name based on index
126+
},
127+
};
128+
});
129+
return customChecks;
130+
};
131+
132+
export const getCustomChecks =
133+
(customChecks: CustomCheck[]) =>
134+
({ driver }: SetupFactoryOptions) => {
135+
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
136+
137+
const failedCustomChecks = customChecks.filter((check) => check.status === "Fail");
138+
139+
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
140+
const status = url.searchParams.get("status");
141+
if (status === "fail") {
142+
return {
143+
body: failedCustomChecks,
144+
headers: { "Total-Count": failedCustomChecks.length.toString() },
145+
};
146+
}
147+
148+
return {
149+
body: customChecks,
150+
headers: { "Total-Count": customChecks.length.toString() },
151+
};
152+
});
153+
};
154+
155+
export const updateCustomCheckItem = (data: CustomCheck[], status: string) => {
156+
const itemToUpdate = data.find((item) => item.status === status);
157+
158+
if (itemToUpdate) {
159+
if (status === "Pass") {
160+
itemToUpdate.status = Status.Fail;
161+
itemToUpdate.failure_reason = "Some reason I dont know";
162+
} else {
163+
itemToUpdate.status = Status.Pass;
164+
itemToUpdate.failure_reason = "";
165+
}
166+
}
167+
};

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 } 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/questions/failedCustomChecks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { screen } from "@testing-library/vue";
2-
import { Console } from "console";
32
import moment from "moment";
43

54
export function customChecksMessageElement() {

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

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from "vitest";
33
import * as precondition from "../../preconditions";
44
import { customChecksFailedRowsList, customChecksListElement, customChecksMessageElement, customChecksFailedReasonList, customChecksListPaginationElement, customChecksReportedDateList } from "./questions/failedCustomChecks";
55
import { waitFor } from "@testing-library/vue";
6+
import { updateCustomCheckItem } from "../../preconditions";
67

78
describe("FEATURE: Failing custom checks", () => {
89
describe("RULE: Failed custom checks should be displayed", () => {
@@ -71,7 +72,6 @@ describe("FEATURE: Failing custom checks", () => {
7172
await waitFor(async () => {
7273
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
7374
});
74-
expect(customChecksListPaginationElement()).not.toBeInTheDocument(); //pagination not vsible
7575
await waitFor(async () => {
7676
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
7777
});
@@ -85,21 +85,52 @@ describe("FEATURE: Failing custom checks", () => {
8585
});
8686
});
8787
describe("RULE: Custom checks should auto-refresh", () => {
88-
test.todo("EXAMPLE: When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check");
89-
90-
/* SCENARIO
91-
Given 2 passing custom checks
92-
And the custom checks page is open
93-
When the endpoint reports a failing custom check
94-
Then the failing custom check should be rendered
95-
*/
96-
97-
test.todo("EXAMPLE: A failing custom check that begins passing is auto-refreshed and removed from the list on the custom checks tab");
98-
/* SCENARIO
99-
Given 2 failing custom checks
100-
And the custom checks page is open
101-
When one of the custom checks passes
102-
Then the passing custom check should be removed from the list
103-
*/
88+
test("EXAMPLE:When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check", async ({ driver }) => {
89+
await driver.setUp(precondition.serviceControlWithMonitoring);
90+
const customCheckItems = precondition.setCustomChecksData(3, 2)();
91+
await driver.setUp(precondition.getCustomChecks(customCheckItems));
92+
93+
await driver.goTo("/custom-checks");
94+
95+
await waitFor(async () => {
96+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
97+
});
98+
await waitFor(async () => {
99+
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
100+
});
101+
102+
updateCustomCheckItem(customCheckItems, "Pass"); // Fail an existing item that is passing
103+
104+
await driver.setUp(precondition.getCustomChecks(customCheckItems));
105+
106+
await driver.goTo("/custom-checks");
107+
await waitFor(async () => {
108+
expect(await customChecksFailedRowsList()).toHaveLength(4); // Now it should be 4
109+
});
110+
});
111+
112+
test("EXAMPLE: A failing custom check that begins passing is auto-refreshed and removed from the list on the custom checks tab", async ({ driver }) => {
113+
await driver.setUp(precondition.serviceControlWithMonitoring);
114+
const customCheckItems = precondition.setCustomChecksData(3, 2)();
115+
await driver.setUp(precondition.getCustomChecks(customCheckItems));
116+
117+
await driver.goTo("/custom-checks");
118+
119+
await waitFor(async () => {
120+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
121+
});
122+
await waitFor(async () => {
123+
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
124+
});
125+
126+
updateCustomCheckItem(customCheckItems, "Fail"); // Pass an existing item that is failing
127+
128+
await driver.setUp(precondition.getCustomChecks(customCheckItems));
129+
130+
await driver.goTo("/custom-checks");
131+
await waitFor(async () => {
132+
expect(await customChecksFailedRowsList()).toHaveLength(2); // Now it should be 2
133+
});
134+
});
104135
});
105136
});

0 commit comments

Comments
 (0)