| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { renderToStaticMarkup } from "react-dom/server"; |
| 3 | |
| 4 | import { |
| 5 | resolveEnvironmentIdentificationPillLabel, |
| 6 | resolveSidebarStageBackdropVariant, |
| 7 | StageBackdropArt, |
| 8 | } from "./SidebarStageBackdrop"; |
| 9 | |
| 10 | describe("SidebarStageBackdrop", () => { |
| 11 | it("resolves stage artwork only when enabled", () => { |
| 12 | expect(resolveSidebarStageBackdropVariant("Dev")).toBe("dev"); |
| 13 | expect(resolveSidebarStageBackdropVariant("Nightly")).toBe("nightly"); |
| 14 | expect(resolveSidebarStageBackdropVariant("Dev", false)).toBeNull(); |
| 15 | expect(resolveSidebarStageBackdropVariant("Alpha")).toBeNull(); |
| 16 | }); |
| 17 | |
| 18 | it("resolves supported environment pill labels", () => { |
| 19 | expect(resolveEnvironmentIdentificationPillLabel("Dev")).toBe("Dev"); |
| 20 | expect(resolveEnvironmentIdentificationPillLabel("nightly")).toBe("Nightly"); |
| 21 | expect(resolveEnvironmentIdentificationPillLabel("Latest")).toBeNull(); |
| 22 | expect(resolveEnvironmentIdentificationPillLabel("Alpha")).toBeNull(); |
| 23 | }); |
| 24 | |
| 25 | it.each(["nightly", "dev"] as const)( |
| 26 | "uses unique SVG definition ids when %s artwork is rendered more than once", |
| 27 | (variant) => { |
| 28 | const markup = renderToStaticMarkup( |
| 29 | <> |
| 30 | <StageBackdropArt variant={variant} /> |
| 31 | <StageBackdropArt variant={variant} /> |
| 32 | </>, |
| 33 | ); |
| 34 | const ids = Array.from(markup.matchAll(/\sid="([^"]+)"/g), (match) => match[1]); |
| 35 | |
| 36 | expect(ids.length).toBeGreaterThan(0); |
| 37 | expect(new Set(ids).size).toBe(ids.length); |
| 38 | }, |
| 39 | ); |
| 40 | }); |