Test FlightsMapStartPage dictionaries loading/error wiring

This commit is contained in:
2026-04-17 03:21:39 +03:00
parent cfc6e12dc9
commit 9a7fcba6ff
@@ -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 }) => <a {...props}>{children}</a>,
}));
vi.mock("@/i18n/provider.js", () => ({
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "ru" } }),
}));
vi.mock("@/ui/layout/PageTabs.js", () => ({
PageTabs: () => <div data-testid="page-tabs" />,
}));
vi.mock("./ClientOnly.js", () => ({
ClientOnly: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
vi.mock("./MapCanvas.js", () => ({
MapCanvas: () => <div data-testid="map-canvas" />,
}));
vi.mock("./FlightsMapFilter.js", () => ({
FlightsMapFilter: () => <div data-testid="flights-map-filter" />,
}));
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(<FlightsMapStartPage />);
expect(screen.getByTestId("map-loader")).toBeTruthy();
});
it("shows the error banner when dictionaries failed", () => {
dictState.loading = false;
dictState.error = new Error("dict boom");
render(<FlightsMapStartPage />);
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(<FlightsMapStartPage />);
expect(screen.queryByTestId("map-loader")).toBeNull();
});
});