import React from "react"; import { render, screen } from "@sproutsocial/seeds-react-testing-library"; import { Progress } from "../"; describe("Progress", () => { it("should render with the progressbar role", () => { render(); expect(screen.getByRole("progressbar")).toBeInTheDocument(); }); it("should set aria-valuenow to the value", () => { render(); expect(screen.getByRole("progressbar")).toHaveAttribute( "aria-valuenow", "33" ); }); it("should set aria-valuemax to the max", () => { render(); expect(screen.getByRole("progressbar")).toHaveAttribute( "aria-valuemax", "200" ); }); it("should apply the correct transform for the indicator", () => { const { container } = render( ); const indicator = container.querySelector(".Progress > div"); expect(indicator).toHaveStyle("transform: translateX(-25%)"); }); it("should clamp percentage to 100 when value exceeds max", () => { const { container } = render( ); const indicator = container.querySelector(".Progress > div"); expect(indicator).toHaveStyle("transform: translateX(-0%)"); }); it("should handle 0 max gracefully", () => { render(); const progressbar = screen.getByRole("progressbar"); expect(progressbar).toBeInTheDocument(); }); it("should apply custom indicator styles", () => { const { container } = render( ); const indicator = container.querySelector(".Progress > div"); expect(indicator).toHaveStyle("background: linear-gradient(red, blue)"); }); it("should use custom getValueLabel", () => { render( `${value} of ${max} steps`} /> ); expect(screen.getByRole("progressbar")).toHaveAttribute( "aria-valuetext", "3 of 10 steps" ); }); it("should support aria-labelledby", () => { render( <> Upload progress ); expect(screen.getByRole("progressbar")).toHaveAttribute( "aria-labelledby", "progress-label" ); }); it("should set aria-label on the progressbar", () => { render(); expect(screen.getByRole("progressbar")).toHaveAttribute( "aria-label", "Credits remaining" ); }); it("should allow passing qa props", () => { render( ); expect( screen.getByRole("progressbar").closest("[data-qa-progress]") ).toBeTruthy(); }); it("should render the Tailwind (CSS-class) implementation by default", () => { const { container } = render( ); // The default (no styled-system props) path renders the CSS-class // implementation, which carries the seeds-progress class. expect(container.querySelector(".seeds-progress")).toBeInTheDocument(); expect( container.querySelector(".seeds-progress > .seeds-progress-indicator") ).toBeInTheDocument(); }); it("should render the styled-components implementation when styled-system props are passed", () => { const { container } = render( ); // styled-system props route to the styled-components path, which does not // emit the seeds-progress class. expect(container.querySelector(".seeds-progress")).not.toBeInTheDocument(); expect(container.querySelector(".Progress")).toBeInTheDocument(); }); it("should apply trackStyle to the track", () => { const { container } = render( ); const track = container.querySelector(".Progress"); expect(track).toHaveStyle("background-color: red"); }); });