UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

48 lines (47 loc) 2.27 kB
var import_jsx_runtime = require("react/jsx-runtime"); var import_test = require("@crossed/test"); var import_CloseButton = require("../CloseButton"); var import_styled = require("@crossed/styled"); describe("CloseButton", () => { it("renders correctly with default props", () => { (0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CloseButton.CloseButton, {})); const button = import_test.screen.getByRole("button", { name: /close/i }); expect(button).toBeTruthy(); expect(button).toHaveAttribute("aria-label", "Close"); }); it("calls onPress when clicked", async () => { const onPressMock = jest.fn(); (0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CloseButton.CloseButton, { onPress: onPressMock })); const button = import_test.screen.getByRole("button", { name: /close/i }); await import_test.userEvent.click(button); expect(onPressMock).toHaveBeenCalledTimes(1); }); it("does not call onPress when disabled", async () => { const onPressMock = jest.fn(); (0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CloseButton.CloseButton, { onPress: onPressMock, disabled: true })); const button = import_test.screen.getByRole("button", { name: /close/i }); await import_test.userEvent.click(button, { pointerEventsCheck: 0 }); expect(onPressMock).not.toHaveBeenCalled(); expect(button).toBeDisabled(); }); it("applies custom props and styles", () => { (0, import_test.render)( /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_CloseButton.CloseButton, { testID: "close-button", style: (0, import_styled.inlineStyle)(() => ({ base: { opacity: 0.8 } })) } ) ); const button = import_test.screen.getByTestId("close-button"); expect(button).toBeTruthy(); }); it("renders the icon with the correct size", () => { (0, import_test.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CloseButton.CloseButton, {})); const icon = import_test.screen.getByLabelText("Close").children[0]; expect(icon).toHaveAttribute("width", "16"); expect(icon).toHaveAttribute("height", "16"); }); }); //# sourceMappingURL=CloseButton.spec.js.map