@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
97 lines (96 loc) • 3.6 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { renderHook } from "@crossed/test";
import { useLogic } from "../useLogic";
import { Title } from "../Title";
import { Footer } from "../Footer";
import { Body } from "../Body";
import { act } from "react";
describe("useLogic", () => {
test("extrait le titre des enfants", () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body")
]
})
);
expect(result.current.title).not.toBeNull();
expect(result.current.title.props.children).toBe(
"Titre du composant"
);
});
test("extrait le footer des enfants", () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body"),
/* @__PURE__ */ jsx(Footer, { children: "Footer du composant" }, "footer")
]
})
);
expect(result.current.footer).not.toBeNull();
expect(result.current.footer.props.children).toBe(
"Footer du composant"
);
});
test("extrait le body des enfants", () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body")
]
})
);
expect(result.current.body).not.toBeNull();
expect(result.current.body.props.children).toBe(
"Contenu du composant"
);
});
test("met \xE0 jour le paddingRight en fonction de la diff\xE9rence entre layoutShared et contentLayoutShared", async () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body"),
/* @__PURE__ */ jsx(Footer, { children: "Footer du composant" }, "footer")
]
})
);
result.current.onLayout({
nativeEvent: { layout: { width: 300 } }
});
await act(() => new Promise((resolve) => setTimeout(resolve, 100)));
expect(result.current.paddingRight).toBe(0);
});
test("g\xE8re l'affichage du footer lorsque stickyFooter est true", async () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body"),
/* @__PURE__ */ jsx(Footer, { children: "Footer du composant" }, "footer")
],
stickyFooter: true
})
);
await act(() => new Promise((resolve) => setTimeout(resolve, 100)));
expect(result.current.showFooter).toBe(true);
});
test("n'affiche pas le footer lorsque stickyFooter est false", () => {
const { result } = renderHook(
() => useLogic({
children: [
/* @__PURE__ */ jsx(Title, { children: "Titre du composant" }, "title"),
/* @__PURE__ */ jsx(Body, { children: "Contenu du composant" }, "body"),
/* @__PURE__ */ jsx(Footer, { children: "Footer du composant" }, "footer")
],
stickyFooter: false
})
);
expect(result.current.showFooter).toBe(false);
});
});
//# sourceMappingURL=useLogic.spec.js.map