|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { Sparkline } from "./Sparkline"; |
| 4 | + |
| 5 | +describe("Sparkline", () => { |
| 6 | + it("exposes an accessible name via role=img and aria-label", () => { |
| 7 | + render(<Sparkline data={[1, 2, 3, 4]} />); |
| 8 | + expect(screen.getByRole("img", { name: /trend chart: increasing/i })).toBeTruthy(); |
| 9 | + }); |
| 10 | + |
| 11 | + it("describes a decreasing trend", () => { |
| 12 | + render(<Sparkline data={[4, 3, 2, 1]} />); |
| 13 | + expect(screen.getByRole("img", { name: /trend chart: decreasing/i })).toBeTruthy(); |
| 14 | + }); |
| 15 | + |
| 16 | + it("describes a flat trend", () => { |
| 17 | + render(<Sparkline data={[2, 2, 2, 2]} />); |
| 18 | + expect(screen.getByRole("img", { name: /trend chart: flat/i })).toBeTruthy(); |
| 19 | + }); |
| 20 | + |
| 21 | + it("uses a custom label when provided", () => { |
| 22 | + render(<Sparkline data={[1, 2, 3]} label="TVL trend: increasing over 24 hours" />); |
| 23 | + expect( |
| 24 | + screen.getByRole("img", { name: "TVL trend: increasing over 24 hours" }), |
| 25 | + ).toBeTruthy(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("includes a <title> element for tooltip/SR support", () => { |
| 29 | + const { container } = render(<Sparkline data={[1, 2, 3]} />); |
| 30 | + expect(container.querySelector("title")?.textContent).toBe("Trend chart: increasing"); |
| 31 | + }); |
| 32 | +}); |
0 commit comments