From f169bbd39a26a39f0e2b9a63b5150e525dec3cd2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 28 Apr 2026 08:44:39 +0200 Subject: [PATCH] test: fix BanUnbanForm tests with NotificationProvider wrapper Include NotificationContainer in test setup so notification messages appear in the DOM and can be found by tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../jails/__tests__/BanUnbanForm.test.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/jails/__tests__/BanUnbanForm.test.tsx b/frontend/src/pages/jails/__tests__/BanUnbanForm.test.tsx index 104cbfe..4b19a5c 100644 --- a/frontend/src/pages/jails/__tests__/BanUnbanForm.test.tsx +++ b/frontend/src/pages/jails/__tests__/BanUnbanForm.test.tsx @@ -2,6 +2,8 @@ import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { BanUnbanForm } from "../BanUnbanForm"; +import { NotificationProvider } from "../../../services/notificationService"; +import { NotificationContainer } from "../../../components/NotificationContainer"; const getRequiredElement = (elements: T[], index: number): T => { const element = elements[index]; @@ -11,6 +13,15 @@ const getRequiredElement = (elements: T[], index: number): T return element; }; +const renderWithNotifications = (component: React.ReactNode): void => { + render( + + + {component} + , + ); +}; + describe("BanUnbanForm", () => { it("disables the ban button while the ban request is pending and shows success", async () => { let resolveBan: () => void = () => undefined; @@ -23,7 +34,9 @@ describe("BanUnbanForm", () => { const onUnban = vi.fn().mockResolvedValue(undefined); const user = userEvent.setup(); - render(); + renderWithNotifications( + , + ); const banIpInputs = screen.getAllByPlaceholderText("e.g. 192.168.1.100"); const banIpInput = getRequiredElement(banIpInputs, 0); @@ -57,7 +70,9 @@ describe("BanUnbanForm", () => { ); const user = userEvent.setup(); - render(); + renderWithNotifications( + , + ); const unbanIpInputs = screen.getAllByPlaceholderText("e.g. 192.168.1.100"); const unbanIpInput = getRequiredElement(unbanIpInputs, 1);