Skip to content

Commit 3db1192

Browse files
committed
set up mock data for custom check and write tests for empty and failed custom check listing
1 parent e8bcffa commit 3db1192

File tree

9 files changed

+61
-54
lines changed

9 files changed

+61
-54
lines changed

src/Frontend/src/components/customchecks/CustomCheckView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const store = useCustomChecksStore();
1111
<template>
1212
<div class="row box box-warning box-no-click">
1313
<div class="col-sm-12 no-side-padding">
14-
<div class="custom-check-row">
14+
<div class="custom-check-row" role="row" aria-label="custom-check-failed-row">
1515
<div class="custom-check-row-detail">
1616
<div class="row box-header">
1717
<div class="col-sm-12 no-side-padding">
18-
<p class="lead">{{ customCheck.failure_reason }}</p>
18+
<p class="lead" role="note" aria-label="custom-check-failed-reason">{{ customCheck.failure_reason }}</p>
1919
<div class="row">
2020
<div class="col-sm-12 no-side-padding">
2121
<p class="metadata">

src/Frontend/src/views/CustomChecksView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { pageNumber, failingCount, failedChecks } = storeToRefs(store);
1919
</div>
2020

2121
<section name="custom_checks">
22-
<NoData v-if="failingCount === 0" message="No failed custom checks" role="heading" aria-label="customcheck-message" />
22+
<NoData v-if="failingCount === 0" message="No failed custom checks" role="note" aria-label="customcheck-message" />
2323
<div v-else class="row">
2424
<div class="col-sm-12">
2525
<CustomCheckView v-for="item of failedChecks" :key="item.id" :custom-check="item" />

src/Frontend/test/mocks/browser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ 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.hasCustomChecksEmpty);
28+
await driver.setUp(precondition.hasCustomChecks);
29+
2930
await driver.setUp(
3031
precondition.monitoredEndpointsNamed([
3132
"Universe.Solarsystem.Mercury.Endpoint1",

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const customCheckItems: CustomCheck[] = [
77
category: "ServiceControl.Audit Health",
88
status: Status.Fail,
99
failure_reason: "I dont know the reason",
10-
reported_at: "2025-01-10T05:06:30.4074087Z",
10+
reported_at: "2025-01-12T05:06:30.4074087Z",
1111
originating_endpoint: {
1212
name: "Particular.ServiceControl.Audit",
1313
host_id: "ff605b55-6fbb-af56-5753-73c1ff73e601",
@@ -20,7 +20,7 @@ export const customCheckItems: CustomCheck[] = [
2020
category: "ServiceControl Health",
2121
status: Status.Fail,
2222
failure_reason: "I am unable to ingest error messages",
23-
reported_at: "2025-01-10T05:42:00.531067Z",
23+
reported_at: "2025-01-11T05:42:00.531067Z",
2424
originating_endpoint: {
2525
name: "Particular.ServiceControl",
2626
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -33,7 +33,7 @@ export const customCheckItems: CustomCheck[] = [
3333
category: "Storage space",
3434
status: Status.Pass,
3535
failure_reason: "",
36-
reported_at: "2025-01-10T05:52:03.8512021Z",
36+
reported_at: "2025-01-03T05:52:03.8512021Z",
3737
originating_endpoint: {
3838
name: "Particular.ServiceControl",
3939
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -46,7 +46,7 @@ export const customCheckItems: CustomCheck[] = [
4646
category: "Configuration",
4747
status: Status.Fail,
4848
failure_reason: "There is something wrong in Saga Audit configuration",
49-
reported_at: "2025-01-10T05:52:03.850927Z",
49+
reported_at: "2025-01-27T05:52:03.850927Z",
5050
originating_endpoint: {
5151
name: "Particular.ServiceControl",
5252
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -59,7 +59,7 @@ export const customCheckItems: CustomCheck[] = [
5959
category: "ServiceControl Health",
6060
status: Status.Pass,
6161
failure_reason: "",
62-
reported_at: "2025-01-10T05:52:05.8153025Z",
62+
reported_at: "2025-01-20T05:52:05.8153025Z",
6363
originating_endpoint: {
6464
name: "Particular.ServiceControl",
6565
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -72,7 +72,7 @@ export const customCheckItems: CustomCheck[] = [
7272
category: "ServiceControl Health",
7373
status: Status.Fail,
7474
failure_reason: "Unable to ingest messages",
75-
reported_at: "2025-01-10T05:52:29.398929Z",
75+
reported_at: "2025-01-08T05:52:29.398929Z",
7676
originating_endpoint: {
7777
name: "Particular.ServiceControl",
7878
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -85,7 +85,7 @@ export const customCheckItems: CustomCheck[] = [
8585
category: "ServiceControl Health",
8686
status: Status.Fail,
8787
failure_reason: "No idea whats going on here",
88-
reported_at: "2025-01-10T05:52:29.3984912Z",
88+
reported_at: "2025-01-07T05:52:29.3984912Z",
8989
originating_endpoint: {
9090
name: "Particular.ServiceControl",
9191
host_id: "9f822d11-b097-a4df-3db5-e069e5d356fe",
@@ -98,7 +98,7 @@ export const customCheckItems: CustomCheck[] = [
9898
category: "ServiceControl Health",
9999
status: Status.Pass,
100100
failure_reason: "",
101-
reported_at: "2025-01-10T05:52:31.4929675Z",
101+
reported_at: "2025-01-24T05:52:31.4929675Z",
102102
originating_endpoint: {
103103
name: "Particular.ServiceControl.Audit",
104104
host_id: "ff605b55-6fbb-af56-5753-73c1ff73e601",

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, hasCustomChecksFailing, hasCustomChecksPassing } from "./customChecks";
8+
export { hasCustomChecksEmpty, hasCustomChecks, hasCustomChecksPassing } 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/customChecksMessage.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { screen } from "@testing-library/vue";
2+
3+
export async function customChecksMessageElement() {
4+
const messageElement = await screen.findByRole("note", { name: "customcheck-message" });
5+
return messageElement;
6+
}
7+
export async function customChecksList() {
8+
const failedCustomChecksRows = await screen.findAllByRole("row", { name: "custom-check-failed-row" });
9+
return failedCustomChecksRows;
10+
}
11+
export async function customChecksFailedReasonList() {
12+
const failedCustomChecksReasons = await screen.findAllByRole("note", { name: "custom-check-failed-reason" });
13+
return failedCustomChecksReasons;
14+
}

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

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
import { test, describe } from "../../drivers/vitest/driver";
2+
import { expect } from "vitest";
3+
import * as precondition from "../../preconditions";
4+
import { customChecksFailedReasonList, customChecksList } from "./questions/failedCustomChecks";
5+
import { waitFor } from "@testing-library/vue";
6+
import { customCheckItems } from "../../mocks/custom-checks-template";
27

38
describe("FEATURE: Failing custom checks", () => {
49
describe("RULE: Custom checks are displayed", () => {
5-
test.todo("EXAMPLE: All custom checks are in a failed state and should be displayed in a list on the custom checks tab");
10+
test("EXAMPLE: All custom checks are in a failed state are displayed in a list on the custom checks tab", async ({ driver }) => {
11+
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();
16+
await driver.goTo("/custom-checks");
17+
// console.log("resp:" + expectedCount);
18+
await waitFor(async () => {
19+
// expect(await customChecksMessageElement()).not.toBeInTheDocument(); //no data message is not vsible
620

7-
/* SCENARIO
8-
Given there are custom checks
9-
And all custom checks are in a failed state
10-
When navigating to the custom checks tab
11-
Then a list of custom checks is shown
12-
*/
13-
14-
/* NOTES
15-
Failure reason (if given)
16-
Name (Check)
17-
Category
18-
Endpoint
19-
Host
20-
Last checked
21-
*/
22-
});
23-
describe("RULE: Only failed custom checks are displayed", () => {
24-
test.todo("EXAMPLE: Only failed custom checks should be displayed in the list on the custom checks tab");
25-
26-
/* SCENARIO
27-
Given there are two failed custom checks
28-
And one passing custom check
29-
When navigating to the custom checks tab
30-
Then the two failed custom checks are shown
31-
And the passing custom check is not shown
32-
*/
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) => {
26+
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
28+
});
29+
});
30+
});
3331
});
3432
describe("RULE: Failed custom checks should be shown in descending order of last checked", () => {
35-
test.todo("EXAMPLE: Three failed custom checks should be displayed in descending order of last checked on the custom checks tab");
33+
test.todo("EXAMPLE: Three failed custom checks is displayed in descending order of last checked on the custom checks tab");
3634

3735
/* SCENARIO
3836
Given there are three failed custom checks
@@ -42,7 +40,7 @@ describe("FEATURE: Failing custom checks", () => {
4240
*/
4341
});
4442
describe("RULE: Failed custom checks should have pagination", () => {
45-
test.todo("EXAMPLE: 51 failed custom checks should be paginated on the custom checks tab");
43+
test.todo("EXAMPLE: 51 failed custom checks is paginated on the custom checks tab");
4644

4745
/* SCENARIO
4846
Given there are 51 failed custom checks
@@ -53,15 +51,15 @@ describe("FEATURE: Failing custom checks", () => {
5351
And page 2 should be available to click on
5452
*/
5553

56-
test.todo("EXAMPLE: 49 failed custom checks should not be paginated on the custom checks tab");
54+
test.todo("EXAMPLE: 49 failed custom checks is not paginated on the custom checks tab");
5755
/* SCENARIO
5856
Given there are 49 failed custom checks
5957
When navigating to the custom checks tab
6058
Then the pagination controls should not be visible
6159
*/
6260
});
6361
describe("RULE: Custom checks should auto-refresh", () => {
64-
test.todo("EXAMPLE: When a custom check fails, the custom checks tab should auto-refresh with the new failed custom check");
62+
test.todo("EXAMPLE: When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check");
6563

6664
/* SCENARIO
6765
Given 2 passing custom checks
@@ -70,7 +68,7 @@ describe("FEATURE: Failing custom checks", () => {
7068
Then the failing custom check should be rendered
7169
*/
7270

73-
test.todo("EXAMPLE: A failing custom check that begins passing should be removed from the list on the custom checks tab");
71+
test.todo("EXAMPLE: A failing custom check that begins passing is auto-refreshed and removed from the list on the custom checks tab");
7472
/* SCENARIO
7573
Given 2 failing custom checks
7674
And the custom checks page is open

src/Frontend/test/specs/customchecks/viewing-no-data.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, describe } from "../../drivers/vitest/driver";
22
import { expect } from "vitest";
33
import * as precondition from "../../preconditions";
4-
import { customChecksMessage } from "./questions/customChecksMessage";
4+
import { customChecksMessageElement } from "./questions/failedCustomChecks";
55
import { waitFor } from "@testing-library/vue";
66

77
describe("FEATURE: No data", () => {
@@ -13,7 +13,7 @@ describe("FEATURE: No data", () => {
1313
await driver.goTo("/custom-checks");
1414

1515
await waitFor(async () => {
16-
expect(await customChecksMessage()).toBe("No failed custom checks");
16+
expect((await customChecksMessageElement()).textContent?.trim()).toBe("No failed custom checks");
1717
});
1818
});
1919
test("EXAMPLE: There are custom checks but none of them are failing", async ({ driver }) => {
@@ -23,7 +23,7 @@ describe("FEATURE: No data", () => {
2323
await driver.goTo("/custom-checks");
2424

2525
await waitFor(async () => {
26-
expect(await customChecksMessage()).toBe("No failed custom checks");
26+
expect((await customChecksMessageElement()).textContent?.trim()).toBe("No failed custom checks");
2727
});
2828
});
2929
});

0 commit comments

Comments
 (0)