@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
40 lines (39 loc) • 1.71 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import { render, fireEvent, screen } from "@crossed/test";
import { FocusScope } from "../FocusScope.web";
describe("FocusScope", () => {
test("rend l\u2019enfant pass\xE9 en prop", () => {
render(
/* @__PURE__ */ jsx(FocusScope, { children: /* @__PURE__ */ jsx("div", { "data-testid": "child", children: "Child" }) })
);
expect(screen.getByTestId("child")).toBeInTheDocument();
});
test("appelle onMountAutoFocus lors du montage", () => {
const onMountAutoFocus = jest.fn();
render(
/* @__PURE__ */ jsx(FocusScope, { onMountAutoFocus, children: /* @__PURE__ */ jsx("div", { children: "Child" }) })
);
expect(onMountAutoFocus).toHaveBeenCalled();
});
test("appelle onUnmountAutoFocus lors du d\xE9montage", () => {
const onUnmountAutoFocus = jest.fn();
const { unmount } = render(
/* @__PURE__ */ jsx(FocusScope, { onUnmountAutoFocus, children: /* @__PURE__ */ jsx("div", { children: "Child" }) })
);
unmount();
expect(onUnmountAutoFocus).toHaveBeenCalled();
});
test("pi\xE8ge le focus dans le conteneur si trapped est activ\xE9", () => {
render(
/* @__PURE__ */ jsx(FocusScope, { trapped: true, children: /* @__PURE__ */ jsxs("div", { "data-testid": "scope", children: [
/* @__PURE__ */ jsx("button", { "data-testid": "button1", children: "Button 1" }),
/* @__PURE__ */ jsx("button", { "data-testid": "button2", children: "Button 2" })
] }) })
);
const button1 = screen.getByTestId("button1");
button1.focus();
fireEvent.focusOut(button1);
expect(button1).toHaveFocus();
});
});
//# sourceMappingURL=FocusScope.spec.js.map