diff --git a/src/features/online-board/hooks/useFlightDetails.test.ts b/src/features/online-board/hooks/useFlightDetails.test.ts index 30cb6f03..002826a0 100644 --- a/src/features/online-board/hooks/useFlightDetails.test.ts +++ b/src/features/online-board/hooks/useFlightDetails.test.ts @@ -150,5 +150,29 @@ describe("useFlightDetails", () => { expect(result.current.flight).toBeNull(); expect(result.current.allFlights).toEqual([]); + expect(result.current.daysOfFlight).toEqual([]); + }); + + it("returns daysOfFlight from response", async () => { + const response: IBoardResponse = { + data: { + partners: [], + routes: [makeFlight("SU0022-20260416")], + daysOfFlight: ["20260415", "20260416", "20260417"], + }, + }; + mockClient.get.mockResolvedValue(response); + + const { result } = renderHook(() => + useFlightDetails({ flights: "SU0022", dates: "2026-04-16" }), + ); + + await waitFor(() => expect(result.current.loading).toBe(false)); + + expect(result.current.daysOfFlight).toEqual([ + "20260415", + "20260416", + "20260417", + ]); }); }); diff --git a/src/features/online-board/hooks/useFlightDetails.ts b/src/features/online-board/hooks/useFlightDetails.ts index 453ed156..a7f65687 100644 --- a/src/features/online-board/hooks/useFlightDetails.ts +++ b/src/features/online-board/hooks/useFlightDetails.ts @@ -18,6 +18,7 @@ import type { ApiError } from "@/shared/api/errors.js"; export interface UseFlightDetailsResult { flight: ISimpleFlight | null; allFlights: ISimpleFlight[]; + daysOfFlight: string[]; loading: boolean; error: ApiError | null; } @@ -31,6 +32,7 @@ export function useFlightDetails( ): UseFlightDetailsResult { const client = useApiClient(); const [allFlights, setAllFlights] = useState([]); + const [daysOfFlight, setDaysOfFlight] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -46,6 +48,7 @@ export function useFlightDetails( .then((response) => { if (!cancelled) { setAllFlights(response.data.routes); + setDaysOfFlight(response.data.daysOfFlight ?? []); setLoading(false); } }) @@ -64,6 +67,7 @@ export function useFlightDetails( return { flight: allFlights[0] ?? null, allFlights, + daysOfFlight, loading, error, };