|
| 1 | +import { describe, it, expect, afterEach } from "vitest"; |
| 2 | +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; |
| 3 | +import { CapabilityStatus } from "../capability-status.tsx"; |
| 4 | +import { TooltipProvider } from "../tooltip.tsx"; |
| 5 | + |
| 6 | +function renderWithTooltip(ui: React.ReactElement) { |
| 7 | + return render(<TooltipProvider delayDuration={0}>{ui}</TooltipProvider>); |
| 8 | +} |
| 9 | + |
| 10 | +afterEach(() => { |
| 11 | + cleanup(); |
| 12 | +}); |
| 13 | + |
| 14 | +describe("CapabilityStatus", () => { |
| 15 | + it("renders a green indicator and the available text when available", () => { |
| 16 | + const { container } = renderWithTooltip( |
| 17 | + <CapabilityStatus |
| 18 | + available |
| 19 | + label="HEIC image decoding" |
| 20 | + availableText="Available" |
| 21 | + unavailableText="Not available" |
| 22 | + />, |
| 23 | + ); |
| 24 | + |
| 25 | + expect(screen.getByText("HEIC image decoding")).toBeInTheDocument(); |
| 26 | + expect(screen.getByText("Available")).toBeInTheDocument(); |
| 27 | + |
| 28 | + const icon = container.querySelector("svg.lucide-circle-check"); |
| 29 | + expect(icon).toBeInTheDocument(); |
| 30 | + expect(icon?.getAttribute("class")).toContain("text-oe-green"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("renders a red warning indicator and the unavailable text when not available", () => { |
| 34 | + const { container } = renderWithTooltip( |
| 35 | + <CapabilityStatus |
| 36 | + available={false} |
| 37 | + label="HEIC image decoding" |
| 38 | + availableText="Available" |
| 39 | + unavailableText="Not available" |
| 40 | + hint="HEIC uploads will be rejected with 415 — check Dockerfile" |
| 41 | + />, |
| 42 | + ); |
| 43 | + |
| 44 | + expect(screen.getByText("Not available")).toBeInTheDocument(); |
| 45 | + |
| 46 | + const icon = container.querySelector("svg.lucide-triangle-alert"); |
| 47 | + expect(icon).toBeInTheDocument(); |
| 48 | + expect(icon?.getAttribute("class")).toContain("text-oe-red"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("exposes the hint as a tooltip when a hint is provided", async () => { |
| 52 | + renderWithTooltip( |
| 53 | + <CapabilityStatus |
| 54 | + available={false} |
| 55 | + label="HEIC image decoding" |
| 56 | + availableText="Available" |
| 57 | + unavailableText="Not available" |
| 58 | + hint="HEIC uploads will be rejected with 415 — check Dockerfile" |
| 59 | + />, |
| 60 | + ); |
| 61 | + |
| 62 | + const trigger = screen.getByRole("note"); |
| 63 | + fireEvent.focus(trigger); |
| 64 | + |
| 65 | + const tooltip = await screen.findByRole("tooltip"); |
| 66 | + expect(tooltip).toHaveTextContent("HEIC uploads will be rejected with 415 — check Dockerfile"); |
| 67 | + }); |
| 68 | + |
| 69 | + it("renders without a tooltip trigger and does not error when no hint is provided", () => { |
| 70 | + renderWithTooltip( |
| 71 | + <CapabilityStatus |
| 72 | + available |
| 73 | + label="HEIC image decoding" |
| 74 | + availableText="Available" |
| 75 | + unavailableText="Not available" |
| 76 | + />, |
| 77 | + ); |
| 78 | + |
| 79 | + expect(screen.queryByRole("note")).not.toBeInTheDocument(); |
| 80 | + expect(screen.getByText("HEIC image decoding")).toBeInTheDocument(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments