|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { createStore, Provider } from "jotai"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { themeAtom } from "../../../atoms/app-ui"; |
| 5 | +import { ThemedIcon } from "."; |
| 6 | + |
| 7 | +describe("ThemedIcon", () => { |
| 8 | + it("renders the resolved icon with stable tone and surface classes", () => { |
| 9 | + const store = createStore(); |
| 10 | + store.set(themeAtom, "mint-dark"); |
| 11 | + |
| 12 | + render( |
| 13 | + <Provider store={store}> |
| 14 | + <ThemedIcon semantic="state.warning" size={16} /> |
| 15 | + </Provider> |
| 16 | + ); |
| 17 | + |
| 18 | + const icon = screen.getByTestId("themed-icon"); |
| 19 | + expect(icon).toHaveAttribute("data-icon-semantic", "state.warning"); |
| 20 | + expect(icon).toHaveClass( |
| 21 | + "themed-icon", |
| 22 | + "themed-icon--tone-warning", |
| 23 | + "themed-icon--surface-warning" |
| 24 | + ); |
| 25 | + expect(icon.querySelector("svg")).toBeInTheDocument(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("omits announcement for decorative icons", () => { |
| 29 | + const store = createStore(); |
| 30 | + store.set(themeAtom, "mint-dark"); |
| 31 | + |
| 32 | + render( |
| 33 | + <Provider store={store}> |
| 34 | + <ThemedIcon semantic="nav.settings" /> |
| 35 | + </Provider> |
| 36 | + ); |
| 37 | + |
| 38 | + expect(screen.getByTestId("themed-icon")).toHaveAttribute("aria-hidden", "true"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("reads the active theme and applies theme-specific presentation overrides", () => { |
| 42 | + const store = createStore(); |
| 43 | + store.set(themeAtom, "hc-dark"); |
| 44 | + |
| 45 | + render( |
| 46 | + <Provider store={store}> |
| 47 | + <ThemedIcon semantic="file.folder.closed" size={18} /> |
| 48 | + </Provider> |
| 49 | + ); |
| 50 | + |
| 51 | + const icon = screen.getByTestId("themed-icon"); |
| 52 | + const svg = icon.querySelector("svg"); |
| 53 | + |
| 54 | + expect(icon).toHaveClass("themed-icon--tone-warning", "themed-icon--surface-none"); |
| 55 | + expect(svg).toHaveAttribute("stroke-width", "2.25"); |
| 56 | + expect(svg).toHaveAttribute("width", "18"); |
| 57 | + expect(svg).toHaveAttribute("height", "18"); |
| 58 | + }); |
| 59 | + |
| 60 | + it("allows semantic icons to participate in accessibility when decorative is false", () => { |
| 61 | + const store = createStore(); |
| 62 | + store.set(themeAtom, "mint-dark"); |
| 63 | + |
| 64 | + render( |
| 65 | + <Provider store={store}> |
| 66 | + <ThemedIcon aria-label="Workspace warning" decorative={false} semantic="state.warning" /> |
| 67 | + </Provider> |
| 68 | + ); |
| 69 | + |
| 70 | + const icon = screen.getByLabelText("Workspace warning"); |
| 71 | + |
| 72 | + expect(icon).toHaveAttribute("role", "img"); |
| 73 | + expect(icon).not.toHaveAttribute("aria-hidden"); |
| 74 | + }); |
| 75 | +}); |
0 commit comments