@sitecore/sc-contenthub-blok
Version:
A UI library for [Sitecore Content Hub](https://doc.sitecore.com/ch/).
49 lines • 2.79 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
require("@testing-library/jest-dom");
const react_1 = require("@testing-library/react");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const BlokButton_1 = require("./BlokButton");
describe("BlokButton", () => {
test("renders with default props", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", children: "Click me" }));
const button = react_1.screen.getByTestId("test-button");
expect(button).toBeInTheDocument();
expect(button).toHaveTextContent("Click me");
});
test("renders with loading state", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", isLoading: true, children: "Click me" }));
const button = react_1.screen.getByTestId("test-button");
expect(button).toBeDisabled();
expect(button).toContainElement(react_1.screen.getByRole("progressbar"));
});
test("renders with custom color scheme and variant", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", colorScheme: "primary", variant: "solid", children: "Click me" }));
const button = react_1.screen.getByTestId("test-button");
expect(button).toHaveClass("MuiButton-containedPrimary");
});
test("handles click events", async () => {
const user = user_event_1.default.setup();
const handleClick = jest.fn();
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", onClick: handleClick, children: "Click me" }));
const button = react_1.screen.getByTestId("test-button");
await user.click(button);
expect(handleClick).toHaveBeenCalledTimes(1);
});
test("renders with href and target", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", href: "https://example.com", target: "_blank", children: "Click me" }));
const button = react_1.screen.getByRole("link");
expect(button).toHaveAttribute("href", "https://example.com");
expect(button).toHaveAttribute("target", "_blank");
});
test("renders with count", () => {
(0, react_1.render)((0, jsx_runtime_1.jsx)(BlokButton_1.BlokButton, { id: "test-button", count: 5, children: "Click me" }));
const count = react_1.screen.getByText("5");
expect(count).toBeInTheDocument();
});
});
//# sourceMappingURL=BlokButton.spec.js.map