From 9a7fcba6ff0bc3ed40b2a07d33ee7b952a113fc4 Mon Sep 17 00:00:00 2001 From: gnezim Date: Fri, 17 Apr 2026 03:21:39 +0300 Subject: [PATCH] Test FlightsMapStartPage dictionaries loading/error wiring --- .../components/FlightsMapStartPage.test.tsx | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/features/flights-map/components/FlightsMapStartPage.test.tsx diff --git a/src/features/flights-map/components/FlightsMapStartPage.test.tsx b/src/features/flights-map/components/FlightsMapStartPage.test.tsx new file mode 100644 index 00000000..7715ce05 --- /dev/null +++ b/src/features/flights-map/components/FlightsMapStartPage.test.tsx @@ -0,0 +1,90 @@ +/** + * @vitest-environment jsdom + */ + +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { FlightsMapStartPage } from "./FlightsMapStartPage.js"; + +vi.mock("@modern-js/runtime/router", () => ({ + useParams: () => ({ lang: "ru" }), + Link: ({ children, ...props }: { children: React.ReactNode }) => {children}, +})); + +vi.mock("@/i18n/provider.js", () => ({ + useTranslation: () => ({ t: (key: string) => key, i18n: { language: "ru" } }), +})); + +vi.mock("@/ui/layout/PageTabs.js", () => ({ + PageTabs: () =>
, +})); + +vi.mock("./ClientOnly.js", () => ({ + ClientOnly: ({ children }: { children: React.ReactNode }) => <>{children}, +})); + +vi.mock("./MapCanvas.js", () => ({ + MapCanvas: () =>
, +})); + +vi.mock("./FlightsMapFilter.js", () => ({ + FlightsMapFilter: () =>
, +})); + +vi.mock("@/env/index.js", () => ({ + getEnv: () => ({ API_BASE_URL: "https://api.test" }), +})); + +vi.mock("../hooks/useFlightsMapSearch.js", () => ({ + useFlightsMapSearch: () => ({ routes: [], loading: false, error: null }), +})); + +vi.mock("../hooks/useFlightsMapCalendar.js", () => ({ + useFlightsMapCalendar: () => ({ availableDays: [] }), +})); + +const dictState = { + dictionaries: null as unknown, + loading: true, + error: null as Error | null, +}; +vi.mock("@/shared/dictionaries/index.js", () => ({ + useDictionaries: () => dictState, +})); + +describe("FlightsMapStartPage — dictionaries integration", () => { + beforeEach(() => { + dictState.dictionaries = null; + dictState.loading = true; + dictState.error = null; + }); + + it("shows the loader while dictionaries are loading", () => { + dictState.loading = true; + render(); + expect(screen.getByTestId("map-loader")).toBeTruthy(); + }); + + it("shows the error banner when dictionaries failed", () => { + dictState.loading = false; + dictState.error = new Error("dict boom"); + render(); + expect(screen.getByTestId("map-error")).toBeTruthy(); + }); + + it("does not show the loader once dictionaries resolve", () => { + dictState.loading = false; + dictState.dictionaries = { + regions: [], + countries: [], + cities: [], + airports: [], + cityByCode: new Map(), + airportByCode: new Map(), + ruCityCodes: new Set(), + otherCityCodes: new Set(), + }; + render(); + expect(screen.queryByTestId("map-loader")).toBeNull(); + }); +});