@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
82 lines (81 loc) • 4.62 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_test = require("@crossed/test");
var import_Button = require("../Button");
describe("Button", () => {
it("renders correctly with default props", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { children: "Click Me" }));
const button = import_test.screen.getByRole("button");
expect(button).toBeTruthy();
expect(button).not.toHaveAttribute("aria-disabled");
});
it("renders children correctly", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { children: "Click Me" }));
const button = import_test.screen.getByRole("button");
expect(button).toHaveTextContent("Click Me");
});
it("disables the button when `disabled` is true", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { disabled: true, children: "Click Me" }));
const button = import_test.screen.getByRole("button");
expect(button).toHaveAttribute("aria-disabled", "true");
expect(button).toBeDisabled();
});
it("renders the loading indicator when `loading` is true", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { loading: true, children: "Click Me" }));
const loadingIndicator = import_test.screen.getByRole("progressbar");
expect(loadingIndicator).toBeTruthy();
expect(import_test.screen.getByRole("button")).toHaveTextContent("Click Me");
});
it("applies the correct styles for primary variant", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { variant: "primary", children: "Primary" }));
expect(import_test.screen.getByRole("button")).toMatchSnapshot();
});
it("applies the correct styles for secondary variant", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { variant: "secondary", children: "Secondary" }));
expect(import_test.screen.getByRole("button")).toMatchSnapshot();
});
it("applies the correct styles for lg size", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { size: "lg", children: "Large Button" }));
expect(import_test.screen.getByRole("button")).toMatchSnapshot();
});
it("applies the correct styles for sm size", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { size: "sm", children: "Small Button" }));
expect(import_test.screen.getByRole("button")).toMatchSnapshot();
});
it("supports forwarding refs", () => {
const ref = import_react.default.createRef();
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { ref, children: "Click Me" }));
expect(ref.current).toBeTruthy();
});
it("handles dynamic states (hover and active)", () => {
(0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { children: "Dynamic Button" }));
const button = import_test.screen.getByRole("button");
import_test.fireEvent.mouseOver(button);
expect(button).not.toHaveAttribute("aria-disabled");
import_test.fireEvent.mouseDown(button);
expect(button).not.toHaveAttribute("aria-disabled");
});
});
//# sourceMappingURL=Button.spec.js.map