Skip to content

Commit 6aeccdd

Browse files
committed
Add tests for the heartbeats filter box
1 parent 4e3b63a commit 6aeccdd

13 files changed

+251
-38
lines changed

src/Frontend/src/components/heartbeats/HealthyEndpoints.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { healthyEndpoints, filteredHealthyEndpoints } = storeToRefs(store);
1313
<div class="row">
1414
<ResultsCount :displayed="filteredHealthyEndpoints.length" :total="healthyEndpoints.length" />
1515
</div>
16-
<section name="healthy_endpoints">
16+
<section name="healthy_endpoints" aria-label="Healthy Endpoints">
1717
<no-data v-if="healthyEndpoints.length === 0" message="No healthy endpoints"></no-data>
1818
<div v-if="healthyEndpoints.length > 0" class="row">
1919
<div class="col-sm-12 no-side-padding">

src/Frontend/src/components/heartbeats/HeartbeatsList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function endpointHealth(endpoint: LogicalEndpoint) {
103103
<LastHeartbeat :date="endpoint.heartbeat_information?.last_report_at" tooltip-target="endpoint" />
104104
</div>
105105
<div v-if="columns.includes(ColumnNames.Tracked)" role="cell" aria-label="tracked-instances" class="col-1 centre">
106-
<tippy v-if="endpoint.track_instances" content="Instances are being tracked" :delay="[1000, 0]">
107-
<i class="fa fa-check text-success"></i>
106+
<tippy v-if="endpoint.track_instances" id="tracked-instance-desc" content="Instances are being tracked" :delay="[1000, 0]">
107+
<i class="fa fa-check text-success" aria-title="Instances are being tracked"></i>
108108
</tippy>
109109
</div>
110110
<div v-if="columns.includes(ColumnNames.TrackToggle)" role="cell" aria-label="tracked-instances" class="col-2 centre">
@@ -117,7 +117,7 @@ function endpointHealth(endpoint: LogicalEndpoint) {
117117
<tippy content="All instances have alerts muted" :delay="[300, 0]">
118118
<i class="fa fa-bell-slash text-danger" />
119119
</tippy>
120-
<span class="instances-muted">{{ endpoint.muted_count }}</span>
120+
<span class="instances-muted" aria-label="Muted instance count">{{ endpoint.muted_count }}</span>
121121
</template>
122122
<template v-else-if="endpoint.muted_count > 0">
123123
<tippy :content="`${endpoint.muted_count} instance(s) have alerts muted`" :delay="[300, 0]">

src/Frontend/src/components/heartbeats/UnhealthyEndpoints.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { unhealthyEndpoints, filteredUnhealthyEndpoints } = storeToRefs(store);
1313
<div class="row">
1414
<ResultsCount :displayed="filteredUnhealthyEndpoints.length" :total="unhealthyEndpoints.length" />
1515
</div>
16-
<section name="unhealthy_endpoints">
16+
<section name="unhealthy_endpoints" aria-label="Unhealthy Endpoints">
1717
<no-data v-if="unhealthyEndpoints.length === 0" message="No unhealthy endpoints"></no-data>
1818
<div v-else class="row">
1919
<div class="col-sm-12 no-side-padding">

src/Frontend/test/mocks/heartbeat-endpoint-template.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { EndpointStatus } from "@/resources/Heartbeat";
33

44
export const healthyEndpointTemplate = <EndpointsView>{
55
is_sending_heartbeats: true,
6-
id: "",
7-
name: `HealthyEndpoint`,
6+
id: "HealthyEndpoint",
7+
name: "HealthyEndpoint",
88
monitor_heartbeat: true,
99
host_display_name: "HealhtyEndpoint.Hostname",
1010
heartbeat_information: { reported_status: EndpointStatus.Alive, last_report_at: new Date().toISOString() },
1111
};
1212

1313
export const unHealthyEndpointTemplate = <EndpointsView>{
1414
is_sending_heartbeats: true,
15-
id: "",
15+
id: "UnHealthyEndpoint",
1616
name: `UnHealthyEndpoint`,
1717
monitor_heartbeat: true,
1818
host_display_name: "UnHealhtyEndpoint.Hostname",

src/Frontend/test/preconditions/hasHeartbeatEndpoints.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ interface ChangeTracking {
88
track_instances: boolean;
99
}
1010

11+
interface MonitorHeartbeat {
12+
monitor_heartbeat: boolean;
13+
}
14+
1115
export const hasHeartbeatsEndpoints = (endpoints: EndpointsView[]) => {
1216
const endpointSettingsList: EndpointSettings[] = [
1317
{
@@ -16,10 +20,12 @@ export const hasHeartbeatsEndpoints = (endpoints: EndpointsView[]) => {
1620
},
1721
];
1822

23+
const endpointsList = [...endpoints];
24+
1925
return ({ driver }: SetupFactoryOptions) => {
2026
driver.mockEndpointDynamic(`${window.defaultConfig.service_control_url}endpoints`, "get", () => {
2127
return Promise.resolve({
22-
body: endpoints,
28+
body: endpointsList,
2329
});
2430
});
2531

@@ -29,8 +35,18 @@ export const hasHeartbeatsEndpoints = (endpoints: EndpointsView[]) => {
2935
});
3036
});
3137

32-
endpoints.forEach((e) => {
33-
driver.mockEndpointDynamic(`${window.defaultConfig.service_control_url}endpointssettings/${e.name}`, "patch", async (url: URL, params: PathParams, request: StrictRequest<DefaultBodyType>) => {
38+
endpointsList.forEach((e) => {
39+
driver.mockEndpointDynamic(`${window.defaultConfig.service_control_url}endpoints/${e.id}`, "patch", async (_url: URL, _params: PathParams, request: StrictRequest<DefaultBodyType>) => {
40+
const requestBody = <MonitorHeartbeat>await request.json();
41+
42+
e.monitor_heartbeat = requestBody.monitor_heartbeat;
43+
44+
return Promise.resolve(<MockEndpointDynamicOptions>{
45+
status: 200,
46+
});
47+
});
48+
49+
driver.mockEndpointDynamic(`${window.defaultConfig.service_control_url}endpointssettings/${e.id}`, "patch", async (url: URL, params: PathParams, request: StrictRequest<DefaultBodyType>) => {
3450
const requestBody = <ChangeTracking>await request.json();
3551

3652
let endpointSettings = endpointSettingsList.find((setting) => setting.name === e.name);
@@ -59,6 +75,7 @@ export const hasUnhealthyHeartbeatsEndpoints = (numberOfUnhealthyEndpoints: numb
5975
for (let i = 0; i < numberOfUnhealthyEndpoints; i++) {
6076
unhealthyEndpoints.push(<EndpointsView>{
6177
...unHealthyEndpointTemplate,
78+
id: `${endpointNamePrefix}_${i}`,
6279
name: `${endpointNamePrefix}_${i}`,
6380
});
6481
}
@@ -78,6 +95,7 @@ export const hasHealthyHeartbeatsEndpoints = (numberOfHealthyEndpoints: number,
7895
for (let i = 0; i < numberOfHealthyEndpoints; i++) {
7996
healthyEndpoints.push(<EndpointsView>{
8097
...healthyEndpointTemplate,
98+
id: `${endpointNamePrefix}_${i}`,
8199
name: `${endpointNamePrefix}_${i}`,
82100
});
83101
}
@@ -96,12 +114,24 @@ export const hasAnUnhealthyUnMonitoredEndpoint = () => {
96114
return hasHeartbeatsEndpoints([
97115
<EndpointsView>{
98116
...unHealthyEndpointTemplate,
117+
id: `Unhealthy_UnmonitoredEndpoint`,
99118
name: `Unhealthy_UnmonitoredEndpoint`,
100119
monitor_heartbeat: false,
101120
},
102121
]);
103122
};
104123

124+
export const hasAHealthyButUnMonitoredEndpoint = () => {
125+
return hasHeartbeatsEndpoints([
126+
<EndpointsView>{
127+
...healthyEndpointTemplate,
128+
id: `Healthy_UnmonitoredEndpoint`,
129+
name: `Healthy_UnmonitoredEndpoint`,
130+
monitor_heartbeat: false,
131+
},
132+
]);
133+
};
134+
105135
export const HasHealthyAndUnHealthyNamedEndpoints = (numberOfHealthyEndpoints: number, numberOfUnhealthyEndpoints: number, endpointNamePrefix: string) => {
106136
const endpoints: EndpointsView[] = [];
107137

@@ -116,6 +146,7 @@ export const HasHealthyAndUnHealthyNamedEndpoints = (numberOfHealthyEndpoints: n
116146
(count) =>
117147
endpoints.push(<EndpointsView>{
118148
...healthyEndpointTemplate,
149+
id: `${endpointNamePrefix}_${count}`,
119150
name: `${endpointNamePrefix}_${count}`,
120151
}),
121152
numberOfHealthyEndpoints
@@ -125,6 +156,7 @@ export const HasHealthyAndUnHealthyNamedEndpoints = (numberOfHealthyEndpoints: n
125156
(count) =>
126157
endpoints.push(<EndpointsView>{
127158
...unHealthyEndpointTemplate,
159+
id: `${endpointNamePrefix}_${numberOfHealthyEndpoints + count}`,
128160
name: `${endpointNamePrefix}_${numberOfHealthyEndpoints + count}`,
129161
}),
130162
numberOfUnhealthyEndpoints

src/Frontend/test/specs/heartbeats/actions/navigateToHeartbeatsConfiguration.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { screen } from "@testing-library/vue";
2+
3+
export async function navigateToHeartbeatsConfiguration() {
4+
const configurationTab = await screen.findByRole("tab", { name: "Configuration" });
5+
configurationTab.click();
6+
7+
// Wait for the tab to switch
8+
await screen.findByRole("region", { name: "Endpoint Configuration" });
9+
}
10+
11+
export async function navigateToHealthyHeartbeats() {
12+
const healthyHeartbeatsTab = await screen.findByRole("tab", { name: /Healthy Endpoints \(\d+\)/i });
13+
healthyHeartbeatsTab.click();
14+
15+
// Wait for the tab to switch
16+
await screen.findByRole("region", { name: "Healthy Endpoints" });
17+
}
18+
19+
export async function navigateToUnHealthyHeartbeats() {
20+
const unhealthyHeartbeatsTab = await screen.findByRole("tab", { name: /Unhealthy Endpoints \(\d+\)/i });
21+
unhealthyHeartbeatsTab.click();
22+
23+
// Wait for the tab to switch
24+
await screen.findByRole("region", { name: "Unhealthy Endpoints" });
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { screen } from "@testing-library/vue";
2+
import UserEvent from "@testing-library/user-event";
3+
4+
export async function setHeartbeatFilter(filterText: string) {
5+
const filterBox = <HTMLInputElement>await screen.findByRole("searchbox", { name: "filter by name" });
6+
7+
if (filterText.length > 0) {
8+
await UserEvent.type(filterBox, filterText);
9+
} else {
10+
await UserEvent.clear(filterBox);
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { screen, within } from "@testing-library/vue";
2+
3+
export async function toggleHeartbeatMonitoring(instanceName: string) {
4+
const endpointRow = await screen.findByRole("row", { name: instanceName });
5+
6+
(<HTMLInputElement>within(endpointRow).getByRole("checkbox", { hidden: true })).click();
7+
}

0 commit comments

Comments
 (0)