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