Skip to content

Commit 67cfe29

Browse files
Abderrahman FAWZY DEVAbderrahman FAWZY DEV
authored andcommitted
feat(apollo,look&feel): retour pr sur les stories et tests
1 parent d143f1d commit 67cfe29

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

apps/apollo-stories/src/components/Modal/ModalCore.stories.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ import type { Meta, StoryObj } from "@storybook/react";
1212
import { fn } from "@storybook/test";
1313
import { useRef } from "react";
1414

15-
const meta: Meta<
16-
React.ComponentType<
17-
React.ComponentProps<typeof ModalCoreComponent> & {
18-
body?: boolean;
19-
footer?: boolean;
20-
header?: boolean;
21-
}
22-
>
23-
> = {
15+
const meta: Meta<typeof ModalCoreComponent> = {
2416
title: "Components/Modal/ModalCore",
2517
component: ModalCoreComponent,
2618
parameters: {

apps/look-and-feel-stories/src/Modal/ModalCore.stories.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ import type { Meta, StoryObj } from "@storybook/react";
1212
import { fn } from "@storybook/test";
1313
import { useRef } from "react";
1414

15-
const meta: Meta<
16-
React.ComponentType<
17-
React.ComponentProps<typeof ModalCoreComponent> & {
18-
body?: boolean;
19-
footer?: boolean;
20-
header?: boolean;
21-
}
22-
>
23-
> = {
15+
const meta: Meta<typeof ModalCoreComponent> = {
2416
title: "Components/Modal/ModalCore",
2517
component: ModalCoreComponent,
2618
parameters: {
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from "@testing-library/react";
1+
import { render, screen } from "@testing-library/react";
22
import { describe, it, expect } from "vitest";
33
import { ModalCoreBody } from "../ModalCoreBody";
44
import type { HasScrollState } from "../../../utilities/hook/useHasScroll";
@@ -12,23 +12,21 @@ vi.mock("../../../utilities/hook/useHasScroll.ts", () => ({
1212

1313
describe("ModalCoreBody component", () => {
1414
it("renders children correctly", () => {
15-
const { getByText } = render(<ModalCoreBody>Test Content</ModalCoreBody>);
16-
expect(getByText("Test Content")).toBeInTheDocument();
15+
render(<ModalCoreBody>Test Content</ModalCoreBody>);
16+
expect(screen.getByText("Test Content")).toBeInTheDocument();
1717
});
1818

1919
it("applies custom className", () => {
20-
const { container } = render(
20+
render(
2121
<ModalCoreBody className="custom-class">Test Content</ModalCoreBody>,
2222
);
23-
expect(container.firstChild).toHaveClass(
23+
expect(screen.getByRole("main")).toHaveClass(
2424
"af-apollo-modal__body custom-class",
2525
);
2626
});
2727

2828
it("passes other props to the main element", () => {
29-
const { container } = render(
30-
<ModalCoreBody id="test-id">Test Content</ModalCoreBody>,
31-
);
32-
expect(container.firstChild).toHaveAttribute("id", "test-id");
29+
render(<ModalCoreBody id="test-id">Test Content</ModalCoreBody>);
30+
expect(screen.getByRole("main")).toHaveAttribute("id", "test-id");
3331
});
3432
});
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import { render, screen } from "@testing-library/react";
22
import { ModalCoreFooter } from "../ModalCoreFooterApollo";
33

4+
const getFooter = () => screen.getByRole("contentinfo");
5+
46
describe("ModalCoreFooter", () => {
57
it("should not render when no button props provided", () => {
68
const { container } = render(<ModalCoreFooter />);
9+
710
const footer = container.querySelector("footer");
811
expect(footer).not.toBeInTheDocument();
912
});
1013

1114
it("should render with default class", () => {
12-
const { container } = render(
13-
<ModalCoreFooter primaryButtonProps={{ children: "Primary" }} />,
14-
);
15-
const footer = container.querySelector("footer");
16-
expect(footer).toHaveClass("af-apollo-modal__footer");
15+
render(<ModalCoreFooter primaryButtonProps={{ children: "Primary" }} />);
16+
expect(getFooter()).toHaveClass("af-apollo-modal__footer");
1717
});
1818

1919
it("should render with additional class", () => {
20-
const { container } = render(
20+
render(
2121
<ModalCoreFooter
2222
className="custom-class"
2323
primaryButtonProps={{ children: "Primary" }}
2424
/>,
2525
);
26-
const footer = container.querySelector("footer");
27-
expect(footer).toHaveClass("af-apollo-modal__footer custom-class");
26+
expect(getFooter()).toHaveClass("af-apollo-modal__footer custom-class");
2827
});
2928

3029
it("should render with primary and secondary buttons", () => {
@@ -34,21 +33,20 @@ describe("ModalCoreFooter", () => {
3433
secondaryButtonProps={{ children: "Secondary" }}
3534
/>,
3635
);
36+
3737
const primaryButton = screen.getByRole("button", { name: "Primary" });
3838
const secondaryButton = screen.getByRole("button", { name: "Secondary" });
39-
4039
expect(primaryButton).toBeInTheDocument();
4140
expect(secondaryButton).toBeInTheDocument();
4241
});
4342

4443
it("should filter out falsy class names", () => {
45-
const { container } = render(
44+
render(
4645
<ModalCoreFooter
4746
className={undefined}
4847
primaryButtonProps={{ children: "Primary" }}
4948
/>,
5049
);
51-
const footer = container.querySelector("footer");
52-
expect(footer).toHaveClass("af-apollo-modal__footer");
50+
expect(getFooter()).toHaveClass("af-apollo-modal__footer");
5351
});
5452
});

0 commit comments

Comments
 (0)