Clean unused helpers after details-page simplification

- ScheduleDetailsPage: drop shiftYmd helper and selectedYmd local —
  both were left over from the removed day-sibling search path.
- ScheduleFlightBody.test: drop fireEvent import + FUTURE_340D /
  FUTURE_1H / YESTERDAY / todayUtc constants; they belonged to the
  Buy/Status button tests that moved to the summary-header layer.
- flight-details + error-handling integration tests: mock
  useCityName / useStationDisplayName so OnlineBoardDetailsPage can
  render without an ApiClientProvider wrapping — the station lookup
  hooks now transitively depend on useApiClient via the cached
  useDictionaries fetcher introduced in 7deb46a.
This commit is contained in:
2026-04-23 18:07:31 +03:00
parent 7deb46aeae
commit 5d18544a46
4 changed files with 18 additions and 36 deletions
@@ -57,16 +57,6 @@ function formatApiDate(yyyymmdd: string): string {
return `${yyyymmdd.slice(0, 4)}-${yyyymmdd.slice(4, 6)}-${yyyymmdd.slice(6, 8)}T00:00:00`;
}
/** Shift a yyyyMMdd date by `days` (negative for backwards). */
function shiftYmd(yyyymmdd: string, days: number): string {
if (yyyymmdd.length !== 8) return yyyymmdd;
const d = new Date(
`${yyyymmdd.slice(0, 4)}-${yyyymmdd.slice(4, 6)}-${yyyymmdd.slice(6, 8)}T00:00:00`,
);
d.setDate(d.getDate() + days);
const pad = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}`;
}
/**
@@ -113,13 +103,6 @@ export const ScheduleDetailsPage: FC<ScheduleDetailsPageProps> = ({
return raw ? parseDetailsRequestParam(raw) : null;
}, [searchParams]);
// TZ §4.1.16.2 — re-issue the parent schedule-route search so the
// left-side mini-list shows the available flight options for the
// selected day plus its neighbours. MUST be called unconditionally
// before any early returns to keep React's hook order stable.
//
const selectedYmd = flightIds[0]?.date ?? "";
// Angular's `schedule-flights-mini-list` only shows a multi-day
// accordion when `schedule.length > 1`; for a connecting itinerary
// it renders a single card — the currently-open flight, with the
@@ -12,7 +12,7 @@
*/
import { describe, it, expect, vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import type { ISimpleFlight, IFlightLeg } from "@/features/online-board/types.js";
// ── i18n stub ─────────────────────────────────────────────────────────────────
@@ -161,25 +161,9 @@ function makeConnectingFlight(depUtc: string): ISimpleFlight {
// ── Buy-gate helpers ──────────────────────────────────────────────────────────
/** 10 days from now — buy should be visible */
/** 10 days from now — used by the structure tests below to exercise a
* future-dated flight against the leg-body renderer. */
const FUTURE_10D = new Date(Date.now() + 10 * 24 * 3600 * 1000).toISOString();
/** 340 days from now — buy should be hidden (> 330 days) */
const FUTURE_340D = new Date(Date.now() + 340 * 24 * 3600 * 1000).toISOString();
/** 1 hour from now — buy should be hidden (< 2h threshold) */
const FUTURE_1H = new Date(Date.now() + 1 * 3600 * 1000).toISOString();
/** Yesterday — buy should be hidden (past) */
const YESTERDAY = new Date(Date.now() - 24 * 3600 * 1000).toISOString();
/** Today (same calendar day) — status button should be visible */
/** Return an ISO string that is guaranteed to be within today's UTC date.
* Always use UTC noon (12:00) to avoid any local-to-UTC shift pushing us
* into yesterday or tomorrow. */
function todayUtc(): string {
const now = new Date();
// Force UTC noon of today — well within the UTC calendar day
return new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 12, 0, 0),
).toISOString();
}
// ── Tests ─────────────────────────────────────────────────────────────────────
@@ -92,6 +92,13 @@ vi.mock("@/shared/hooks/useAppSettings.js", () => ({
}),
}));
// OnlineBoardDetailsPage resolves station codes via useStationDisplayName,
// which internally hits useApiClient — no ApiClientProvider in this tree.
vi.mock("@/shared/hooks/useDictionaries.js", () => ({
useCityName: (code: string) => code,
useStationDisplayName: (code: string) => code,
}));
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
@@ -71,6 +71,14 @@ vi.mock("@/shared/hooks/useAppSettings.js", () => ({
}),
}));
// OnlineBoardDetailsPage resolves station codes via useStationDisplayName,
// which internally hits useApiClient. There's no ApiClientProvider in
// this test tree, so stub the name-lookup hooks to echo the code.
vi.mock("@/shared/hooks/useDictionaries.js", () => ({
useCityName: (code: string) => code,
useStationDisplayName: (code: string) => code,
}));
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------