Add BoardingPanel component for flight details accordion
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// @vitest-environment jsdom
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { BoardingPanel } from "./BoardingPanel.js";
|
||||
import type { IFlightTransitionItem } from "../../types.js";
|
||||
|
||||
vi.mock("@/i18n/provider.js", () => ({
|
||||
useTranslation: () => ({ t: (k: string) => k }),
|
||||
}));
|
||||
|
||||
const baseItem: IFlightTransitionItem = {
|
||||
start: {
|
||||
dayChange: { value: 0, title: "" },
|
||||
local: "11:00",
|
||||
localTime: "11:00",
|
||||
tzOffset: 3,
|
||||
utc: "08:00",
|
||||
},
|
||||
end: {
|
||||
dayChange: { value: 0, title: "" },
|
||||
local: "11:30",
|
||||
localTime: "11:30",
|
||||
tzOffset: 3,
|
||||
utc: "08:30",
|
||||
},
|
||||
status: "Finished",
|
||||
isActual: true,
|
||||
};
|
||||
|
||||
describe("BoardingPanel", () => {
|
||||
it("renders start and end times", () => {
|
||||
render(<BoardingPanel item={baseItem} />);
|
||||
expect(screen.getByText("11:00")).toBeTruthy();
|
||||
expect(screen.getByText("11:30")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("renders status label", () => {
|
||||
render(<BoardingPanel item={baseItem} />);
|
||||
expect(screen.getByText("DETAILS.STATUS_FINISHED")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("has data-testid", () => {
|
||||
render(<BoardingPanel item={baseItem} />);
|
||||
expect(screen.getByTestId("boarding-panel")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { FC } from "react";
|
||||
import { useTranslation } from "@/i18n/provider.js";
|
||||
import type { IFlightTransitionItem, FlightTransitionStatus } from "../../types.js";
|
||||
import "./panels.scss";
|
||||
|
||||
const STATUS_KEYS: Record<FlightTransitionStatus, string> = {
|
||||
Finished: "DETAILS.STATUS_FINISHED",
|
||||
Expected: "DETAILS.STATUS_EXPECTED",
|
||||
InProgress: "DETAILS.STATUS_IN_PROGRESS",
|
||||
Specified: "DETAILS.STATUS_SPECIFIED",
|
||||
Scheduled: "DETAILS.STATUS_SCHEDULED",
|
||||
};
|
||||
|
||||
export interface BoardingPanelProps {
|
||||
item: IFlightTransitionItem;
|
||||
}
|
||||
|
||||
export const BoardingPanel: FC<BoardingPanelProps> = ({ item }) => {
|
||||
const { t } = useTranslation();
|
||||
const hasEnd = Boolean(item.end?.local);
|
||||
|
||||
return (
|
||||
<div className="details-panel" data-testid="boarding-panel">
|
||||
<div className="details-panel__row">
|
||||
<span className="details-panel__label">{t("DETAILS.STATUS")}</span>
|
||||
<span className="details-panel__status">{t(STATUS_KEYS[item.status])}</span>
|
||||
</div>
|
||||
<div className="details-panel__row">
|
||||
<span className="details-panel__label">{t("DETAILS.SCHEDULED")}</span>
|
||||
<span className="details-panel__value">{item.start.local}</span>
|
||||
</div>
|
||||
{hasEnd && (
|
||||
<div className="details-panel__row">
|
||||
<span className="details-panel__label">{t("DETAILS.ACTUAL")}</span>
|
||||
<span className="details-panel__value">{item.end.local}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user