Skip to content

Commit b0171ce

Browse files
committed
add no data and failing cutom checks
1 parent 3db1192 commit b0171ce

File tree

8 files changed

+144
-191
lines changed

8 files changed

+144
-191
lines changed

src/Frontend/src/views/CustomChecksView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ const { pageNumber, failingCount, failedChecks } = storeToRefs(store);
2020

2121
<section name="custom_checks">
2222
<NoData v-if="failingCount === 0" message="No failed custom checks" role="note" aria-label="customcheck-message" />
23-
<div v-else class="row">
23+
<div v-else class="row" role="table" aria-label="custom-check-list">
2424
<div class="col-sm-12">
2525
<CustomCheckView v-for="item of failedChecks" :key="item.id" :custom-check="item" />
2626
<div class="row">
27-
<PaginationStrip :items-per-page="10" :total-count="failingCount" v-model="pageNumber" />
27+
<PaginationStrip :items-per-page="10" :total-count="failingCount" v-model="pageNumber" role="row" aria-label="custom-check-pagination" />
2828
</div>
2929
</div>
3030
</div>

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);
28+
await driver.setUp(precondition.hasCustomChecks(49, 2));
2929

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

src/Frontend/test/mocks/custom-checks-template.ts

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
import CustomCheck from "@/resources/CustomCheck";
12
import { SetupFactoryOptions } from "../driver";
2-
import { passedCustomCheckItems, customCheckItems } from "../mocks/custom-checks-template";
3-
43
const emptyContent = JSON.stringify([]);
54

65
export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
@@ -13,35 +12,75 @@ export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
1312
});
1413
};
1514

16-
export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => {
17-
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
18-
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
19-
const status = url.searchParams.get("status");
20-
let dataForCustomCheckItems = passedCustomCheckItems;
21-
22-
if (status === "fail") {
23-
dataForCustomCheckItems = dataForCustomCheckItems.filter((check) => check.status === "Fail");
24-
}
25-
26-
return {
27-
body: dataForCustomCheckItems,
28-
headers: { "Total-Count": dataForCustomCheckItems.length.toString() },
29-
};
30-
});
15+
const generateGuid = () => {
16+
return crypto.randomUUID();
3117
};
32-
export const hasCustomChecks = ({ driver }: SetupFactoryOptions) => {
33-
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
34-
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
35-
const status = url.searchParams.get("status");
36-
let dataForCustomCheckItems = customCheckItems;
37-
38-
if (status === "fail") {
39-
dataForCustomCheckItems = dataForCustomCheckItems.filter((check) => check.status === "Fail");
40-
}
41-
42-
return {
43-
body: dataForCustomCheckItems,
44-
headers: { "Total-Count": dataForCustomCheckItems.length.toString() },
45-
};
46-
});
18+
const customCheckTemplate = <CustomCheck>{
19+
id: "CustomChecks/6131fa95-9414-1898-9c83-c5b18587945b",
20+
custom_check_id: "Audit Message Ingestion",
21+
category: "ServiceControl.Audit Health",
22+
status: "Pass",
23+
failure_reason: "I don't know the reason",
24+
reported_at: "2025-01-10T05:06:30.4074087Z",
25+
originating_endpoint: {
26+
name: "Particular.ServiceControl.Audit",
27+
host_id: "ff605b55-6fbb-af56-5753-73c1ff73e601",
28+
host: "ABC",
29+
},
4730
};
31+
32+
export const hasCustomChecks =
33+
(failingCount: number, passingCount: number) =>
34+
({ driver }: SetupFactoryOptions) => {
35+
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
36+
37+
// Calculate total count
38+
const totalCount = failingCount + passingCount;
39+
40+
// Create checks (both failing and passing)
41+
const customChecks = Array.from({ length: totalCount }).map((_, index) => {
42+
// Generate the date based on the index
43+
const date = new Date();
44+
date.setDate(date.getDate() - index); // Subtract `index` days from the current date
45+
const reportedAt = date.toISOString(); // Convert to ISO string format
46+
47+
// Determine status and failure reason
48+
const status = index < failingCount ? "Fail" : "Pass";
49+
const failureReason = status === "Fail" ? `configured to fail on endpoint ${index}` : "";
50+
51+
// Generate a new GUID for the ID and host_id
52+
const newGuid = generateGuid();
53+
const originatingEndpointName = `endpoint ${index}`;
54+
const originatingHost = `ABC ${index}`;
55+
56+
return {
57+
...customCheckTemplate,
58+
id: `customcheck/${newGuid}`, // New GUID for ID
59+
status, // Fail or Pass based on index
60+
failure_reason: failureReason, // Failure reason or empty for passing
61+
reported_at: reportedAt, // Autogenerated reported_at based on index
62+
originating_endpoint: {
63+
name: originatingEndpointName, // Endpoint name based on index
64+
host_id: newGuid, // New GUID for host_id
65+
host: originatingHost, // Host name based on index
66+
},
67+
};
68+
});
69+
70+
const failedCustomChecks = customChecks.filter((check) => check.status === "Fail");
71+
72+
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
73+
const status = url.searchParams.get("status");
74+
if (status === "fail") {
75+
return {
76+
body: failedCustomChecks,
77+
headers: { "Total-Count": failedCustomChecks.length.toString() },
78+
};
79+
}
80+
81+
return {
82+
body: customChecks,
83+
headers: { "Total-Count": customChecks.length.toString() },
84+
};
85+
});
86+
};

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, hasCustomChecksPassing } from "./customChecks";
8+
export { hasCustomChecksEmpty, hasCustomChecks } from "./customChecks";
99
export { hasNoDisconnectedEndpoints } from "../preconditions/hasNoDisconnectedEndpoints";
1010
export { hasNoMonitoredEndpoints, hasMonitoredEndpointsList, monitoredEndpointsNamed } from "../preconditions/hasMonitoredEndpoints";
1111
export { hasEventLogItems } from "../preconditions/hasEventLogItems";
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { screen } from "@testing-library/vue";
22

3-
export async function customChecksMessageElement() {
4-
const messageElement = await screen.findByRole("note", { name: "customcheck-message" });
5-
return messageElement;
3+
export function customChecksMessage() {
4+
const customCheckNoDataMessage = screen.queryByRole("note", { name: "customcheck-message" });
5+
return customCheckNoDataMessage?.textContent?.trim();
66
}
7-
export async function customChecksList() {
7+
export function customChecksMessageElement() {
8+
const customCheckNoDataElement = screen.queryByRole("note", { name: "customcheck-message" });
9+
return customCheckNoDataElement;
10+
}
11+
export function customChecksListElement() {
12+
const customChecksListElement = screen.queryByRole("table", { name: "custom-check-list" });
13+
return customChecksListElement;
14+
}
15+
export async function customChecksFailedRowsList() {
816
const failedCustomChecksRows = await screen.findAllByRole("row", { name: "custom-check-failed-row" });
917
return failedCustomChecksRows;
1018
}
1119
export async function customChecksFailedReasonList() {
1220
const failedCustomChecksReasons = await screen.findAllByRole("note", { name: "custom-check-failed-reason" });
1321
return failedCustomChecksReasons;
1422
}
23+
export function customChecksListPaginationElement() {
24+
const customChecksListPaginationElement = screen.queryByRole("row", { name: "custom-check-pagination" });
25+
return customChecksListPaginationElement;
26+
}

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

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,66 @@
11
import { test, describe } from "../../drivers/vitest/driver";
22
import { expect } from "vitest";
33
import * as precondition from "../../preconditions";
4-
import { customChecksFailedReasonList, customChecksList } from "./questions/failedCustomChecks";
4+
import { customChecksFailedRowsList, customChecksListElement, customChecksMessageElement, customChecksFailedReasonList, customChecksListPaginationElement } from "./questions/failedCustomChecks";
55
import { waitFor } from "@testing-library/vue";
6-
import { customCheckItems } from "../../mocks/custom-checks-template";
76

87
describe("FEATURE: Failing custom checks", () => {
9-
describe("RULE: Custom checks are displayed", () => {
8+
describe("RULE: Failed custom checks should be displayed", () => {
109
test("EXAMPLE: All custom checks are in a failed state are displayed in a list on the custom checks tab", async ({ driver }) => {
1110
await driver.setUp(precondition.serviceControlWithMonitoring);
12-
await driver.setUp(precondition.hasCustomChecks);
13-
// const response = precondition.hasCustomChecks;
14-
// const expectedCount = response.headers["Total-Count"];
15-
const expectedCount = customCheckItems.filter((check) => check.status === "Fail").length.toString();
11+
await driver.setUp(precondition.hasCustomChecks(5, 3));
12+
1613
await driver.goTo("/custom-checks");
17-
// console.log("resp:" + expectedCount);
14+
1815
await waitFor(async () => {
19-
// expect(await customChecksMessageElement()).not.toBeInTheDocument(); //no data message is not vsible
16+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
17+
});
18+
expect(customChecksMessageElement()).not.toBeInTheDocument(); //no data message is not vsible
19+
await waitFor(async () => {
20+
expect(await customChecksFailedRowsList()).toHaveLength(5); //count of failed checks matches failing count set
21+
22+
const failedReasonList = await customChecksFailedReasonList();
23+
expect(failedReasonList).toHaveLength(5); //count of failed reasons matches failing count set
2024

21-
expect(await customChecksList()).toHaveLength(Number(expectedCount)); //count of failed checks matches the response received
22-
const failedCustomChecksReasonsList = await customChecksFailedReasonList();
23-
expect(failedCustomChecksReasonsList).toHaveLength(Number(expectedCount)); //count of failed reasons matches the response received
24-
// Ensure that each reason has non-empty text
25-
failedCustomChecksReasonsList.forEach((reason) => {
25+
failedReasonList.forEach((reason) => {
2626
const textContent = reason.textContent?.trim(); // Get the text and trim any surrounding whitespace
27-
expect(textContent).not.toBe(""); // Assert the text content is not empty
27+
expect(textContent).not.toBe(""); // Assert the failed reason text content is not empty
2828
});
2929
});
3030
});
3131
});
32+
33+
describe("RULE: Failed custom checks should have pagination when failed checks count is greater than 50", () => {
34+
test("EXAMPLE: 51 failed custom checks is paginated on the custom checks tab", async ({ driver }) => {
35+
await driver.setUp(precondition.serviceControlWithMonitoring);
36+
await driver.setUp(precondition.hasCustomChecks(51, 3));
37+
38+
await driver.goTo("/custom-checks");
39+
40+
await waitFor(async () => {
41+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
42+
});
43+
expect(customChecksListPaginationElement()).toBeInTheDocument(); //pagination vsible
44+
await waitFor(async () => {
45+
expect(await customChecksFailedRowsList()).toHaveLength(51); //count of failed checks matches failing count set
46+
});
47+
});
48+
49+
test("EXAMPLE: 49 failed custom checks is not paginated on the custom checks tab", async ({ driver }) => {
50+
await driver.setUp(precondition.serviceControlWithMonitoring);
51+
await driver.setUp(precondition.hasCustomChecks(49, 3));
52+
53+
await driver.goTo("/custom-checks");
54+
55+
await waitFor(async () => {
56+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
57+
});
58+
expect(customChecksListPaginationElement()).not.toBeInTheDocument(); //pagination vsible
59+
await waitFor(async () => {
60+
expect(await customChecksFailedRowsList()).toHaveLength(49); //count of failed checks matches failing count set
61+
});
62+
});
63+
});
3264
describe("RULE: Failed custom checks should be shown in descending order of last checked", () => {
3365
test.todo("EXAMPLE: Three failed custom checks is displayed in descending order of last checked on the custom checks tab");
3466

@@ -39,25 +71,6 @@ describe("FEATURE: Failing custom checks", () => {
3971
Then the custom checks are shown in descending order of last checked
4072
*/
4173
});
42-
describe("RULE: Failed custom checks should have pagination", () => {
43-
test.todo("EXAMPLE: 51 failed custom checks is paginated on the custom checks tab");
44-
45-
/* SCENARIO
46-
Given there are 51 failed custom checks
47-
When navigating to the custom checks tab
48-
Then the pagination controls should be visible
49-
And the page number should be 1
50-
And only the first 50 custom checks should be rendered
51-
And page 2 should be available to click on
52-
*/
53-
54-
test.todo("EXAMPLE: 49 failed custom checks is not paginated on the custom checks tab");
55-
/* SCENARIO
56-
Given there are 49 failed custom checks
57-
When navigating to the custom checks tab
58-
Then the pagination controls should not be visible
59-
*/
60-
});
6174
describe("RULE: Custom checks should auto-refresh", () => {
6275
test.todo("EXAMPLE: When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check");
6376

0 commit comments

Comments
 (0)