diff --git a/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.test.tsx b/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.test.tsx new file mode 100644 index 00000000..be519282 --- /dev/null +++ b/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.test.tsx @@ -0,0 +1,52 @@ +// @vitest-environment jsdom +import { describe, it, expect, vi } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { OperatorLogo } from "./OperatorLogo.js"; +import type { ISimpleFlight } from "../../types.js"; + +vi.mock("@/i18n/provider.js", () => ({ + useTranslation: () => ({ t: (k: string) => k }), +})); + +function makeFlight(carrier: string): ISimpleFlight { + return { + id: "X", routeType: "Direct", flyingTime: "1h", status: "Scheduled", + flightId: { carrier, flightNumber: "0022", suffix: "", date: "20260417" }, + operatingBy: { carrier, flightNumber: "0022" }, + leg: {} as never, + } as ISimpleFlight; +} + +describe("OperatorLogo", () => { + it("renders with company-logo and company-logo--SU classes", () => { + render(); + const el = screen.getByTestId("operator-logo"); + expect(el.className).toContain("company-logo"); + expect(el.className).toContain("company-logo--SU"); + }); + + it("adds ru class when locale is ru", () => { + render(); + expect(screen.getByTestId("operator-logo").className).toContain("ru"); + }); + + it("adds large class when large=true", () => { + render(); + expect(screen.getByTestId("operator-logo").className).toContain("large"); + }); + + it("adds round class when round=true", () => { + render(); + expect(screen.getByTestId("operator-logo").className).toContain("round"); + }); + + it("renders caption when caption=true", () => { + render(); + expect(screen.getByText("SHARED.AVIACOMPANY")).toBeTruthy(); + }); + + it("does not render caption by default", () => { + render(); + expect(screen.queryByText("SHARED.AVIACOMPANY")).toBeNull(); + }); +}); diff --git a/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.tsx b/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.tsx new file mode 100644 index 00000000..5ecc94dd --- /dev/null +++ b/src/features/online-board/components/BoardDetailsHeader/OperatorLogo.tsx @@ -0,0 +1,44 @@ +import type { FC } from "react"; +import { useTranslation } from "@/i18n/provider.js"; +import type { ISimpleFlight } from "../../types.js"; +import "./OperatorLogo.scss"; + +export interface OperatorLogoProps { + flight: ISimpleFlight; + locale: string; + large?: boolean; + round?: boolean; + caption?: boolean; +} + +export const OperatorLogo: FC = ({ + flight, + locale, + large, + round, + caption, +}) => { + const { t } = useTranslation(); + const carrier = flight.operatingBy.carrier ?? flight.flightId.carrier; + + const classes = [ + "company-logo", + `company-logo--${carrier}`, + large ? "large" : "", + round ? "round" : "", + locale === "ru" ? "ru" : "", + ] + .filter(Boolean) + .join(" "); + + return ( + + {caption && {t("SHARED.AVIACOMPANY")}} + + + ); +};