From 0954e0ef595aa62bc1dc18ef38582c5078573820 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Tue, 10 Dec 2024 16:37:02 +0100 Subject: [PATCH] chore: add test click flag row (#34) Signed-off-by: Thomas Poignant --- .../flags/flagRow.test.tsx | 35 +++++++++++++++++++ .../authenticatedRoutes/flags/flagRow.tsx | 6 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx b/client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx index b24af83..8a675cd 100644 --- a/client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx +++ b/client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx @@ -15,6 +15,7 @@ vi.mock("../../../api/goffApi.ts", () => ({ updateFeatureFlagStatusById: vi.fn(), deleteFeatureFlagById: vi.fn(), })); +const mockedUsedNavigate = vi.fn(); describe("flag row", () => { const handleDelete = vi.fn(); @@ -53,6 +54,40 @@ describe("flag row", () => { version: "0.0.1", }; }); + + describe("click flag details", () => { + it("should redirect to the flag details page by clicking on the row", async () => { + vi.mock("react-router-dom", async () => { + const actual = await vi.importActual("react-router-dom"); + return { + ...actual, + useNavigate: () => mockedUsedNavigate, + }; + }); + + render( + + + + + +
+
, + ); + expect(screen.getByText(defaultFlag.name ?? "")).toBeVisible(); + await userEvent.click(screen.getByText(defaultFlag.name ?? ""), { + delay: 100, + }); + expect(mockedUsedNavigate).toHaveBeenCalledWith( + `/flags/${defaultFlag.id}`, + ); + }); + }); + describe("labels", () => { it("should display a labels (version, variations, type) of the flag", () => { render( diff --git a/client/src/routes/authenticatedRoutes/flags/flagRow.tsx b/client/src/routes/authenticatedRoutes/flags/flagRow.tsx index 0ed645d..aa3267c 100644 --- a/client/src/routes/authenticatedRoutes/flags/flagRow.tsx +++ b/client/src/routes/authenticatedRoutes/flags/flagRow.tsx @@ -119,7 +119,11 @@ export function FlagRow({
-