Skip to content

Commit 898fda9

Browse files
committed
refactor code
1 parent a40a256 commit 898fda9

File tree

3 files changed

+63
-37
lines changed

3 files changed

+63
-37
lines changed

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import userEvent from "@testing-library/user-event";
88
describe("FEATURE: Dismiss custom checks", () => {
99
describe("RULE: Dismiss button should be visible", () => {
1010
test("EXAMPLE: Dismiss button is visible on each failing custom check", async ({ driver }) => {
11+
const failingCustomCheckCount = 4;
12+
const passingCustomCheckCount = 2;
13+
1114
await driver.setUp(precondition.serviceControlWithMonitoring);
12-
await driver.setUp(precondition.hasCustomChecks(3, 2));
15+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
1316

1417
await driver.goTo("/custom-checks");
1518

@@ -18,61 +21,65 @@ describe("FEATURE: Dismiss custom checks", () => {
1821
});
1922

2023
await waitFor(async () => {
21-
expect(await customChecksDismissButtonList()).toHaveLength(3); //count of dismiss button
24+
expect(await customChecksDismissButtonList()).toHaveLength(failingCustomCheckCount); //count of dismiss button
2225
});
2326
});
2427
});
28+
2529
describe("RULE: Dismissing a custom check should remove from the list", () => {
2630
test("EXAMPLE: The dismiss button removes the custom check from the list when clicked", async ({ driver }) => {
31+
const failingCustomCheckCount = 4;
32+
const passingCustomCheckCount = 2;
33+
2734
await driver.setUp(precondition.serviceControlWithMonitoring);
28-
await driver.setUp(precondition.hasCustomChecks(3, 2));
35+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
2936

3037
await driver.goTo("/custom-checks");
3138

3239
await waitFor(async () => {
3340
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
34-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
41+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
3542
});
3643

3744
let dismissButtonList = await customChecksDismissButtonList();
38-
expect(dismissButtonList).toHaveLength(3); //count of dismiss button matches the failed custom check count
45+
expect(dismissButtonList).toHaveLength(failingCustomCheckCount); //count of dismiss button matches the failed custom check count
3946

4047
//click the dismiss button
4148
await userEvent.click(dismissButtonList[0]);
4249

4350
//get the new dismiss button list
4451
dismissButtonList = await customChecksDismissButtonList();
45-
//count of dismss button is decreased by 1
46-
expect(dismissButtonList).toHaveLength(2);
52+
expect(dismissButtonList).toHaveLength(failingCustomCheckCount - 1); //count of dismss button is decreased by 1
4753
});
4854
});
4955
describe("RULE: Failing after a dismiss should cause the failed check to reappear", () => {
5056
test("EXAMPLE: Dismissed custom check should reappear in the list when it fails", async ({ driver }) => {
57+
const failingCustomCheckCount = 4;
58+
const passingCustomCheckCount = 0;
59+
5160
await driver.setUp(precondition.serviceControlWithMonitoring);
5261

53-
const customCheckItems = precondition.generateCustomChecksData(3, 0)();
62+
const customCheckItems = precondition.generateCustomChecksData(failingCustomCheckCount, passingCustomCheckCount)();
5463
await driver.setUp(precondition.getCustomChecks(customCheckItems));
5564
await driver.goTo("/custom-checks");
5665

5766
await waitFor(async () => {
5867
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
59-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
68+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
6069
});
6170

6271
const dismissButtonList = await customChecksDismissButtonList();
63-
expect(dismissButtonList).toHaveLength(3); //count of dismiss button
72+
expect(dismissButtonList).toHaveLength(failingCustomCheckCount); //count of dismiss button
6473

6574
//click dismiss button
6675
await userEvent.click(dismissButtonList[0]);
67-
expect(await customChecksDismissButtonList()).toHaveLength(2); //count of dismiss button
68-
expect(await customChecksFailedRowsList()).toHaveLength(2); //count of failed checks matches failing count set
76+
expect(await customChecksDismissButtonList()).toHaveLength(failingCustomCheckCount - 1); //count of dismiss button
77+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount - 1); //count of failed checks matches failing count set
6978

7079
//re-add the dismissed custom check Item
71-
7280
await driver.setUp(precondition.getCustomChecks(customCheckItems));
7381
await driver.goTo("/custom-checks");
74-
//custom list should be increased to 3
75-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
82+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
7683
});
7784
});
7885
});

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

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import { updateCustomCheckItemByStatus } from "../../preconditions/customChecks"
88
describe("FEATURE: Failing custom checks", () => {
99
describe("RULE: Failed custom checks should be displayed", () => {
1010
test("EXAMPLE: All custom checks are in a failed state are displayed in a list on the custom checks tab", async ({ driver }) => {
11+
const failingCustomCheckCount = 5;
12+
const passingCustomCheckCount = 3;
13+
1114
await driver.setUp(precondition.serviceControlWithMonitoring);
12-
await driver.setUp(precondition.hasCustomChecks(5, 3));
15+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
1316

1417
await driver.goTo("/custom-checks");
1518

@@ -18,62 +21,71 @@ describe("FEATURE: Failing custom checks", () => {
1821
});
1922
expect(customChecksMessageElement()).not.toBeInTheDocument(); //no data message is not vsible
2023
await waitFor(async () => {
21-
expect(await customChecksFailedRowsList()).toHaveLength(5); //count of failed checks matches failing count set
24+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
2225

2326
const failedReasonList = await customChecksFailedReasonList();
24-
expect(failedReasonList).toHaveLength(5); //count of failed reasons matches failing count set
27+
expect(failedReasonList).toHaveLength(failingCustomCheckCount); //count of failed reasons matches failing count set
2528

2629
failedReasonList.forEach((reason) => {
27-
const textContent = reason.textContent?.trim(); // Get the text and trim any surrounding whitespace
28-
expect(textContent).not.toBe(""); // Assert the failed reason text content is not empty
30+
const textContent = reason.textContent?.trim();
31+
expect(textContent).not.toBe(""); // the failed reason text content is not empty
2932
});
3033
});
3134
});
3235
});
3336

3437
describe("RULE: Failed custom checks should have pagination when failed checks count is greater than 10", () => {
3538
test("EXAMPLE: 11 failed custom checks is paginated on the custom checks tab", async ({ driver }) => {
39+
const failingCustomCheckCount = 11;
40+
const passingCustomCheckCount = 3;
41+
3642
await driver.setUp(precondition.serviceControlWithMonitoring);
37-
await driver.setUp(precondition.hasCustomChecks(11, 3));
43+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
3844

3945
await driver.goTo("/custom-checks");
4046

4147
await waitFor(async () => {
42-
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
48+
expect(await customChecksListElement()).toBeInTheDocument(); //failed list visible
4349
});
44-
expect(customChecksListPaginationElement()).toBeInTheDocument(); //pagination vsible
50+
expect(customChecksListPaginationElement()).toBeInTheDocument(); //pagination visible
4551
await waitFor(async () => {
46-
expect(await customChecksFailedRowsList()).toHaveLength(11); //count of failed checks matches failing count set
52+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
4753
});
4854
});
4955

5056
test("EXAMPLE: 9 failed custom checks is not paginated on the custom checks tab", async ({ driver }) => {
57+
const failingCustomCheckCount = 9;
58+
const passingCustomCheckCount = 3;
59+
5160
await driver.setUp(precondition.serviceControlWithMonitoring);
52-
await driver.setUp(precondition.hasCustomChecks(9, 3));
61+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
5362

5463
await driver.goTo("/custom-checks");
5564

5665
await waitFor(async () => {
5766
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
5867
});
59-
expect(customChecksListPaginationElement()).not.toBeInTheDocument(); //pagination vsible
68+
expect(customChecksListPaginationElement()).not.toBeInTheDocument(); //pagination not visible
6069
await waitFor(async () => {
61-
expect(await customChecksFailedRowsList()).toHaveLength(9); //count of failed checks matches failing count set
70+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
6271
});
6372
});
6473
});
6574
describe("RULE: Failed custom checks should be shown in descending order of last checked", () => {
6675
test("EXAMPLE:Three failed custom checks is displayed in descending order of last checked on the custom checks tab", async ({ driver }) => {
76+
const failingCustomCheckCount = 5;
77+
const passingCustomCheckCount = 3;
78+
6779
await driver.setUp(precondition.serviceControlWithMonitoring);
68-
await driver.setUp(precondition.hasCustomChecks(3, 3));
80+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
6981

7082
await driver.goTo("/custom-checks");
7183

7284
await waitFor(async () => {
7385
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
7486
});
7587
await waitFor(async () => {
76-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
88+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
7789
});
7890

7991
const timestamps = await customChecksReportedDateList(); // Ensure this is awaited correctly
@@ -86,8 +98,11 @@ describe("FEATURE: Failing custom checks", () => {
8698
});
8799
describe("RULE: Custom checks should auto-refresh", () => {
88100
test("EXAMPLE:When a custom check fails, the custom checks tab is auto-refreshed with the new failed custom check", async ({ driver }) => {
101+
const failingCustomCheckCount = 3;
102+
const passingCustomCheckCount = 2;
103+
89104
await driver.setUp(precondition.serviceControlWithMonitoring);
90-
const customCheckItems = precondition.generateCustomChecksData(3, 2)();
105+
const customCheckItems = precondition.generateCustomChecksData(failingCustomCheckCount, passingCustomCheckCount)();
91106
await driver.setUp(precondition.getCustomChecks(customCheckItems));
92107

93108
await driver.goTo("/custom-checks");
@@ -96,22 +111,24 @@ describe("FEATURE: Failing custom checks", () => {
96111
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
97112
});
98113
await waitFor(async () => {
99-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
114+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
100115
});
101116

102117
updateCustomCheckItemByStatus(customCheckItems, "Pass"); // Fail an existing item that is passing
103-
104118
await driver.setUp(precondition.getCustomChecks(customCheckItems));
105119

106120
await driver.goTo("/custom-checks");
107121
await waitFor(async () => {
108-
expect(await customChecksFailedRowsList()).toHaveLength(4); // Now it should be 4
122+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount + 1); // Now it should be increased by 1
109123
});
110124
});
111125

112126
test("EXAMPLE: A failing custom check that begins passing is auto-refreshed and removed from the list on the custom checks tab", async ({ driver }) => {
127+
const failingCustomCheckCount = 3;
128+
const passingCustomCheckCount = 2;
129+
113130
await driver.setUp(precondition.serviceControlWithMonitoring);
114-
const customCheckItems = precondition.generateCustomChecksData(3, 2)();
131+
const customCheckItems = precondition.generateCustomChecksData(failingCustomCheckCount, passingCustomCheckCount)();
115132
await driver.setUp(precondition.getCustomChecks(customCheckItems));
116133

117134
await driver.goTo("/custom-checks");
@@ -120,7 +137,7 @@ describe("FEATURE: Failing custom checks", () => {
120137
expect(await customChecksListElement()).toBeInTheDocument(); //failed list is visisble
121138
});
122139
await waitFor(async () => {
123-
expect(await customChecksFailedRowsList()).toHaveLength(3); //count of failed checks matches failing count set
140+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount); //count of failed checks matches failing count set
124141
});
125142

126143
updateCustomCheckItemByStatus(customCheckItems, "Fail"); // an existing item that is failing
@@ -129,7 +146,7 @@ describe("FEATURE: Failing custom checks", () => {
129146

130147
await driver.goTo("/custom-checks");
131148
await waitFor(async () => {
132-
expect(await customChecksFailedRowsList()).toHaveLength(2); // Now it should be 2
149+
expect(await customChecksFailedRowsList()).toHaveLength(failingCustomCheckCount - 1); // Now it should be decreased by 1
133150
});
134151
});
135152
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe("FEATURE: No data", () => {
1818
});
1919
test("EXAMPLE: There are custom checks but none of them are failing", async ({ driver }) => {
2020
await driver.setUp(precondition.serviceControlWithMonitoring);
21-
await driver.setUp(precondition.hasCustomChecks(0, 5));
21+
const failingCustomCheckCount = 0;
22+
const passingCustomCheckCount = 5;
23+
await driver.setUp(precondition.hasCustomChecks(failingCustomCheckCount, passingCustomCheckCount));
2224

2325
await driver.goTo("/custom-checks");
2426

0 commit comments

Comments
 (0)