UNPKG

@crossed/primitive

Version:

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

55 lines (54 loc) 1.93 kB
import { jsx, jsxs } from "react/jsx-runtime"; import "@testing-library/jest-dom"; import { render, userEvent, screen } from "@crossed/test"; import { createModal, Modal, ModalContent, ModalOverlay, ModalTitle, ModalTrigger, ModalPortal, ModalBody } from "../"; import { Text } from "react-native"; import { PortalProvider } from "@gorhom/portal"; describe("createModal", () => { test("return from createModal", async () => { const modal = createModal(); expect(Object.keys(modal)).toEqual([ "modalContext", "Modal", "ModalContent", "ModalOverlay", "ModalTitle", "ModalTrigger", "ModalPortal", "ModalBody" ]); }); test("open/close component", async () => { const {} = render( /* @__PURE__ */ jsx(PortalProvider, { children: /* @__PURE__ */ jsxs(Modal, { children: [ /* @__PURE__ */ jsx(ModalTrigger, { testID: "trigger", children: /* @__PURE__ */ jsx(Text, { children: "toto" }) }), /* @__PURE__ */ jsxs(ModalPortal, { children: [ /* @__PURE__ */ jsx(ModalOverlay, { testID: "overlay" }), /* @__PURE__ */ jsxs(ModalContent, { testID: "content", children: [ /* @__PURE__ */ jsx(ModalTitle, { children: "toto" }), /* @__PURE__ */ jsx(ModalTrigger, { testID: "close", children: /* @__PURE__ */ jsx(Text, { children: "close" }) }), /* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsx(Text, { children: "toto" }) }) ] }) ] }) ] }) }) ); const open = async () => { await userEvent.click(screen.getByTestId("trigger")); }; expect(() => screen.getByTestId("content")).toThrow(); await open(); expect(screen.getByTestId("content")).toBeVisible(); await userEvent.click(screen.getByTestId("close")); expect(() => screen.getByTestId("content")).toThrow(); }); }); //# sourceMappingURL=Modal.spec.js.map