Expose daysOfFlight from useFlightDetails for day-tabs navigation
This commit is contained in:
@@ -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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<ISimpleFlight[]>([]);
|
||||
const [daysOfFlight, setDaysOfFlight] = useState<string[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<ApiError | null>(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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user