From c4663b121c40b5ff693450df76030d37f5992154 Mon Sep 17 00:00:00 2001 From: cikzh Date: Thu, 25 Jul 2024 15:24:15 +0200 Subject: [PATCH 1/4] Now using overrideOnce instead of a custom context provider --- .../PollingStationChoiceForm.test.tsx | 21 +++++++++++-------- frontend/lib/api-mocks/index.ts | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx index 5a65c60a2..118853ed9 100644 --- a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx +++ b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx @@ -2,12 +2,14 @@ import { userEvent } from "@testing-library/user-event"; import { describe, expect, test } from "vitest"; import { PollingStationChoiceForm } from "app/component/form/polling_station_choice/PollingStationChoiceForm.tsx"; -import { render, screen, within } from "app/test/unit"; +import { overrideOnce, render, screen, within } from "app/test/unit"; -import { PollingStationProvider, PollingStationsContext } from "@kiesraad/api"; +import { PollingStationProvider } from "@kiesraad/api"; +import { pollingStationMock } from "@kiesraad/api-mocks"; describe("Test PollingStationChoiceForm", () => { test("Form field entry", async () => { + overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -35,6 +37,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Selecting a valid polling station", async () => { + overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -50,6 +53,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Selecting a non-existing polling station", async () => { + overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -67,6 +71,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Polling station list", async () => { + overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -90,17 +95,15 @@ describe("Test PollingStationChoiceForm", () => { }); test("Polling station list no stations", async () => { + overrideOnce("get", "/api/polling_stations/1", 200, { + polling_stations: [], + }); const user = userEvent.setup(); render( - + - , + , ); const openPollingStationList = screen.getByTestId("openPollingStationList"); diff --git a/frontend/lib/api-mocks/index.ts b/frontend/lib/api-mocks/index.ts index ea3e8fdc4..28c6f8eef 100644 --- a/frontend/lib/api-mocks/index.ts +++ b/frontend/lib/api-mocks/index.ts @@ -7,6 +7,7 @@ import { PoliticalGroup, POLLING_STATION_DATA_ENTRY_REQUEST_BODY, POLLING_STATION_DATA_ENTRY_REQUEST_PARAMS, + PollingStationListResponse, VotersCounts, VotesCounts, } from "@kiesraad/api"; @@ -16,6 +17,7 @@ import { pollingStationMockData } from "./PollingStationMockData.ts"; export const electionMock = electionMockData as Required; export const politicalGroupMock = politicalGroupMockData as Required; +export const pollingStationMock = pollingStationMockData as Required; type ParamsToString = { [P in keyof T]: string; From 0b27d70a6b2da070a04bb7979ee6930b9eb6b28d Mon Sep 17 00:00:00 2001 From: cikzh Date: Fri, 26 Jul 2024 17:23:44 +0200 Subject: [PATCH 2/4] Fixed override URL --- .../polling_station_choice/PollingStationChoiceForm.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx index 118853ed9..d7613067a 100644 --- a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx +++ b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx @@ -95,7 +95,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Polling station list no stations", async () => { - overrideOnce("get", "/api/polling_stations/1", 200, { + overrideOnce("get", "/api/elections/1/polling_stations", 200, { polling_stations: [], }); const user = userEvent.setup(); From c0b9c5419b6dd23bbec7f9fc31ec88588ee479dd Mon Sep 17 00:00:00 2001 From: cikzh Date: Mon, 29 Jul 2024 09:13:40 +0200 Subject: [PATCH 3/4] Fixed overrideOnce URL's --- .../PollingStationChoiceForm.test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx index d7613067a..3ed4207bd 100644 --- a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx +++ b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx @@ -9,7 +9,7 @@ import { pollingStationMock } from "@kiesraad/api-mocks"; describe("Test PollingStationChoiceForm", () => { test("Form field entry", async () => { - overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); + overrideOnce("get", "/api/elections/1/polling_stations", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -37,7 +37,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Selecting a valid polling station", async () => { - overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); + overrideOnce("get", "/api/elections/1/polling_stations", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -53,7 +53,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Selecting a non-existing polling station", async () => { - overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); + overrideOnce("get", "/api/elections/1/polling_stations", 200, pollingStationMock); const user = userEvent.setup(); render( @@ -71,7 +71,7 @@ describe("Test PollingStationChoiceForm", () => { }); test("Polling station list", async () => { - overrideOnce("get", "/api/polling_stations/1", 200, pollingStationMock); + overrideOnce("get", "/api/elections/1/polling_stations", 200, pollingStationMock); const user = userEvent.setup(); render( From 5536c29cb3fa4b7aef860ec97e3d7e53486ce532 Mon Sep 17 00:00:00 2001 From: Joep <145749778+jschuurk-kr@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:03:47 +0200 Subject: [PATCH 4/4] adds PollingStationForm test for 404 response on /pollings_stations --- .../PollingStationChoiceForm.test.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx index 3ed4207bd..49e7e4ad4 100644 --- a/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx +++ b/frontend/app/component/form/polling_station_choice/PollingStationChoiceForm.test.tsx @@ -113,4 +113,24 @@ describe("Test PollingStationChoiceForm", () => { // Check if the error message is visible expect(screen.getByText("Geen stembureaus gevonden")).toBeVisible(); }); + + test("Polling station request returns 404", async () => { + overrideOnce("get", "/api/elections/1/polling_stations", 404, { + error: "Resource not found", + }); + const user = userEvent.setup(); + + render( + + + , + ); + + const openPollingStationList = screen.getByTestId("openPollingStationList"); + await user.click(openPollingStationList); + expect(screen.getByText("Kies het stembureau")).toBeVisible(); + + // Check if the error message is visible + expect(screen.getByText("Geen stembureaus gevonden")).toBeVisible(); + }); });