From d7caa6a135463a71de66023fd27213af9ea0fbe1 Mon Sep 17 00:00:00 2001 From: Warwick Schroeder Date: Thu, 26 Nov 2026 09:10:41 +0800 Subject: [PATCH] fix: toast notifications for muting and unmuting endpoint instances in the heartbeats component and tests --- .../heartbeats/EndpointInstances.vue | 5 +-- .../heartbeats/configuring-heartbeats.spec.ts | 35 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Frontend/src/components/heartbeats/EndpointInstances.vue b/src/Frontend/src/components/heartbeats/EndpointInstances.vue index 421b64af1a..a0d8f8ad1e 100644 --- a/src/Frontend/src/components/heartbeats/EndpointInstances.vue +++ b/src/Frontend/src/components/heartbeats/EndpointInstances.vue @@ -79,7 +79,7 @@ async function proceedWarningDialog() { await store.toggleEndpointMonitor( filteredValidInstances.value.filter((instance) => (dialogWarningOperation.value === Operation.Unmute && !instance.monitor_heartbeat) || (dialogWarningOperation.value === Operation.Mute && instance.monitor_heartbeat)) ); - useShowToast(TYPE.SUCCESS, `All endpoint instances ${dialogWarningOperation.value}`, "", false, { timeout: 1000 }); + useShowToast(TYPE.SUCCESS, `All endpoint instances ${dialogWarningOperation.value === Operation.Mute ? "muted" : "unmuted"}`, "", false, { timeout: 1000 }); } catch { useShowToast(TYPE.ERROR, "Save failed", "", false, { timeout: 3000 }); } @@ -105,9 +105,10 @@ async function deleteAllInstances() { } async function toggleAlerts(instance: EndpointsView) { + const muting = instance.monitor_heartbeat; try { await store.toggleEndpointMonitor([instance]); - useShowToast(TYPE.SUCCESS, `Endpoint instance ${!instance.monitor_heartbeat ? "muted" : "unmuted"}`, "", false, { timeout: 1000 }); + useShowToast(TYPE.SUCCESS, `Endpoint instance ${muting ? "muted" : "unmuted"}`, "", false, { timeout: 1000 }); } catch { useShowToast(TYPE.ERROR, "Save failed", "", false, { timeout: 3000 }); } diff --git a/src/Frontend/test/specs/heartbeats/configuring-heartbeats.spec.ts b/src/Frontend/test/specs/heartbeats/configuring-heartbeats.spec.ts index d82b41e82e..788b430d04 100644 --- a/src/Frontend/test/specs/heartbeats/configuring-heartbeats.spec.ts +++ b/src/Frontend/test/specs/heartbeats/configuring-heartbeats.spec.ts @@ -13,8 +13,10 @@ import { getHeartbeatFilterValue } from "./questions/getHeartbeatFilterValue"; import { getListedEndpointNames } from "./questions/getListedEndpointNames"; import { getColumnSortDirection } from "./questions/getColumnSortDirection"; import { sortEndpointsBy } from "./actions/sortEndpointsBy"; -import { waitFor } from "@testing-library/vue"; +import { screen, waitFor } from "@testing-library/vue"; +import UserEvent from "@testing-library/user-event"; import { EndpointStatus } from "@/resources/Heartbeat"; +import { isNotificationVisible } from "../configuration/questions/notifications"; vi.mock("@vueuse/core", async (importOriginal) => { const originalModule = await importOriginal(); @@ -139,6 +141,37 @@ describe("FEATURE: Heartbeats configuration", () => { expect(healthyEndpoint).toBeTruthy(); expect(healthyEndpoint?.instancesMuted).toBe(0); }); + + test("EXAMPLE: Muting and then unmuting an instance shows a toast that matches each action", async ({ driver }) => { + await driver.setUp(precondition.serviceControlWithMonitoring); + await driver.setUp(precondition.HasHealthyAndUnHealthyEndpoints(1, 1)); + await driver.goTo("heartbeats/instances/TestEndpoint_1"); + + await toggleHeartbeatMonitoring("TestEndpoint_1"); + + await waitFor(() => expect(isNotificationVisible(/^endpoint instance muted$/i)).toBe(true)); + expect(isNotificationVisible(/^endpoint instance unmuted$/i)).toBe(false); + + await toggleHeartbeatMonitoring("TestEndpoint_1"); + + await waitFor(() => expect(isNotificationVisible(/^endpoint instance unmuted$/i)).toBe(true)); + }); + + test("EXAMPLE: Muting and then unmuting all instances shows a toast that says muted and then unmuted", async ({ driver }) => { + await driver.setUp(precondition.serviceControlWithMonitoring); + await driver.setUp(precondition.HasHealthyAndUnHealthyEndpoints(1, 1)); + await driver.goTo("heartbeats/instances/TestEndpoint_1"); + + await UserEvent.click(await screen.findByRole("button", { name: /Mute Alerts on All/ })); + await UserEvent.click(await screen.findByRole("button", { name: "Yes" })); + + await waitFor(() => expect(isNotificationVisible(/^all endpoint instances muted$/i)).toBe(true)); + + await UserEvent.click(await screen.findByRole("button", { name: /Unmute Alerts on All/ })); + await UserEvent.click(await screen.findByRole("button", { name: "Yes" })); + + await waitFor(() => expect(isNotificationVisible(/^all endpoint instances unmuted$/i)).toBe(true)); + }); }); describe("RULE: Sorting by of the name of an endpoint should be possible in all displays", () => {