mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* fix(spinner): cater global spinner variant * feat(spinner): add spinner test cases * chore(changeset): add changeset
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import * as React from "react";
|
|
import {render} from "@testing-library/react";
|
|
import {HeroUIProvider} from "@heroui/system";
|
|
|
|
import {Spinner} from "../src";
|
|
|
|
describe("Spinner", () => {
|
|
it("should render correctly", () => {
|
|
const wrapper = render(<Spinner />);
|
|
|
|
expect(() => wrapper.unmount()).not.toThrow();
|
|
});
|
|
|
|
it("ref should be forwarded", () => {
|
|
const ref = React.createRef<HTMLElement>();
|
|
|
|
render(<Spinner ref={ref} />);
|
|
expect(ref.current).not.toBeNull();
|
|
});
|
|
|
|
it("should render with default aria-label", () => {
|
|
const {getByLabelText} = render(<Spinner />);
|
|
|
|
expect(getByLabelText("Loading")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should replace the default aria-label when a label is passed", () => {
|
|
const {getByLabelText} = render(<Spinner label="Custom label" />);
|
|
|
|
expect(getByLabelText("Custom label")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should replace the default aria-label when a children is passed", () => {
|
|
const {getByLabelText} = render(<Spinner>Custom label</Spinner>);
|
|
|
|
expect(getByLabelText("Custom label")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should replace the default aria-label if aria-label is passed", () => {
|
|
const {getByLabelText} = render(<Spinner aria-label="Custom label" />);
|
|
|
|
expect(getByLabelText("Custom label")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should use global spinner variant if variant is not defined", () => {
|
|
const {container} = render(
|
|
<HeroUIProvider spinnerVariant="gradient">
|
|
<Spinner aria-label="Custom label" />
|
|
</HeroUIProvider>,
|
|
);
|
|
|
|
expect(container.querySelector("[class*='gradient']")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should not use global spinner variant if variant is defined", () => {
|
|
const {container} = render(
|
|
<HeroUIProvider spinnerVariant="gradient">
|
|
<Spinner aria-label="Custom label" variant="default" />
|
|
</HeroUIProvider>,
|
|
);
|
|
|
|
expect(container.querySelector("[class*='gradient']")).not.toBeInTheDocument();
|
|
});
|
|
});
|