Skip to content

Commit e8bcffa

Browse files
committed
add test for no custom check data scenario
1 parent 86737c9 commit e8bcffa

File tree

3 files changed

+29
-48
lines changed

3 files changed

+29
-48
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ export const customCheckItems: CustomCheck[] = [
106106
},
107107
},
108108
];
109+
110+
export const failedCustomCheckItems = customCheckItems.filter((check) => check.status === "Fail");
111+
export const passedCustomCheckItems = customCheckItems.filter((check) => check.status === "Pass");
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
import { SetupFactoryOptions } from "../driver";
2-
import { customCheckItems } from "../mocks/custom-checks-template";
2+
import { passedCustomCheckItems, customCheckItems } from "../mocks/custom-checks-template";
33

4-
const content = JSON.stringify([]);
5-
const failedCustomCheckItems = customCheckItems.filter((check) => check.status === "Fail");
6-
const passedCustomCheckItems = customCheckItems.filter((check) => check.status === "Pass");
4+
const emptyContent = JSON.stringify([]);
75

86
export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
97
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
108
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
11-
body: content,
9+
body: emptyContent,
1210
headers: {
1311
"Total-Count": "0", //count of failing custom checks
1412
},
1513
});
1614
};
1715

18-
export const hasCustomChecksFailing = ({ driver }: SetupFactoryOptions) => {
16+
export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => {
1917
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
2018
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
2119
const status = url.searchParams.get("status");
20+
let dataForCustomCheckItems = passedCustomCheckItems;
21+
2222
if (status === "fail") {
23-
return {
24-
body: failedCustomCheckItems,
25-
headers: { "Total-Count": failedCustomCheckItems.length.toString() },
26-
};
23+
dataForCustomCheckItems = dataForCustomCheckItems.filter((check) => check.status === "Fail");
2724
}
2825

2926
return {
30-
body: passedCustomCheckItems,
31-
headers: { "Total-Count": passedCustomCheckItems.length.toString() },
27+
body: dataForCustomCheckItems,
28+
headers: { "Total-Count": dataForCustomCheckItems.length.toString() },
3229
};
3330
});
3431
};
35-
export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => {
32+
export const hasCustomChecks = ({ driver }: SetupFactoryOptions) => {
3633
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
37-
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
38-
body: passedCustomCheckItems,
39-
headers: {
40-
"Total-Count": passedCustomCheckItems.length.toString(), //count of passing custom checks
41-
},
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+
};
4246
});
4347
};

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

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,26 @@ import { customChecksMessage } from "./questions/customChecksMessage";
55
import { waitFor } from "@testing-library/vue";
66

77
describe("FEATURE: No data", () => {
8-
describe("RULE: When there is no data to show a message should be displayed ", () => {
9-
/* SCENARIO
10-
Given there are no custom checks
11-
When navigating to the custom checks tab
12-
Then a message is shown "No failed custom checks"
13-
*/
8+
describe("RULE: When there is no data to show, a message should be displayed ", () => {
149
test("EXAMPLE: There are no failed or passing custom checks", async ({ driver }) => {
15-
//Arrange
1610
await driver.setUp(precondition.serviceControlWithMonitoring);
17-
// given that the custom check list is empty
1811
await driver.setUp(precondition.hasCustomChecksEmpty);
1912

20-
//Act - When navigating to the custom checks tab
2113
await driver.goTo("/custom-checks");
22-
//Expect
14+
2315
await waitFor(async () => {
2416
expect(await customChecksMessage()).toBe("No failed custom checks");
2517
});
2618
});
27-
/* SCENARIO
28-
Given there are custom checks
29-
And all custom checks are in a success state
30-
When navigating to the custom checks tab
31-
Then a message is shown "No failed custom checks"
32-
*/
3319
test("EXAMPLE: There are custom checks but none of them are failing", async ({ driver }) => {
34-
//Arrange
35-
// vi.useFakeTimers();
3620
await driver.setUp(precondition.serviceControlWithMonitoring);
37-
console.log("test started now;");
38-
// given that the custom check list is not empty and status of all checks are passing
3921
await driver.setUp(precondition.hasCustomChecksPassing);
4022

41-
//Act - When navigating to the custom checks tab
4223
await driver.goTo("/custom-checks");
43-
console.log("navigating to the custom checks tab");
44-
//vi.advanceTimersByTime(10000);
45-
//setTimeout(async () => {
46-
//Expect
47-
waitFor(async () => {
48-
console.log("expecting");
24+
25+
await waitFor(async () => {
4926
expect(await customChecksMessage()).toBe("No failed custom checks");
5027
});
51-
// }, 5500);
52-
53-
// vi.restoreAllMocks();
5428
});
5529
});
5630
});

0 commit comments

Comments
 (0)