Skip to content

Commit ef28d2c

Browse files
committed
feat(apollo,look&feel): ajout des tests pour Item File
1 parent 8957dfe commit ef28d2c

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

client/apollo/react/src/Form/ItemFile/ItemFileCommon.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
import classNames from "classnames";
1313
import { ItemMessage } from "../ItemMessage/ItemMessageCommon";
1414
import { Spinner } from "../../Spinner/SpinnerCommon";
15-
import { ClickIcon } from "../../ClickIcon/ClickIconCommon";
16-
import { Icon } from "../../Icon/IconCommon";
15+
import type { ClickIconProps } from "../../ClickIcon/ClickIconCommon";
16+
import type { IconProps } from "../../Icon/IconCommon";
1717

1818
export const itemFileStates = {
1919
success: "success",
@@ -31,9 +31,11 @@ export type ItemFileCommonProps = {
3131
errorMessage?: string;
3232
deleteIcon: string;
3333
ItemMessageComponent: ComponentType<ComponentProps<typeof ItemMessage>>;
34-
ItemIconComponent: ComponentType<ComponentProps<typeof Icon>>;
35-
ItemClickIconComponent: ComponentType<ComponentProps<typeof ClickIcon>>;
34+
ItemIconComponent: ComponentType<IconProps>;
35+
ItemClickIconComponent: ComponentType<ClickIconProps>;
3636
ItemSpinnerComponent: ComponentType<ComponentProps<typeof Spinner>>;
37+
deleteIconProps?: Partial<ClickIconProps>;
38+
visiibilityIconProps?: Partial<ClickIconProps>;
3739
} & ComponentPropsWithoutRef<"div">;
3840

3941
export const ItemFileCommon = ({
@@ -47,6 +49,8 @@ export const ItemFileCommon = ({
4749
ItemClickIconComponent,
4850
ItemIconComponent,
4951
ItemMessageComponent,
52+
deleteIconProps = {},
53+
visiibilityIconProps = {},
5054
}: ItemFileCommonProps) => {
5155
const idHelp = useId();
5256
const idMessage = useId();
@@ -89,11 +93,14 @@ export const ItemFileCommon = ({
8993
<div className="af-click-icon__content">
9094
{state === "success" ? (
9195
<>
92-
<ItemClickIconComponent src={visibilityIcon} />
93-
<ItemClickIconComponent src={deleteIcon} />
96+
<ItemClickIconComponent
97+
src={visibilityIcon}
98+
{...visiibilityIconProps}
99+
/>
100+
<ItemClickIconComponent src={deleteIcon} {...deleteIconProps} />
94101
</>
95102
) : (
96-
<ItemClickIconComponent src={deleteIcon} />
103+
<ItemClickIconComponent src={deleteIcon} {...deleteIconProps} />
97104
)}
98105
</div>
99106
{helper && (
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, expect } from "vitest";
2+
import { render, screen } from "@testing-library/react";
3+
import { axe } from "jest-axe";
4+
import { ItemFile, itemFileStates } from "../ItemFileLF";
5+
6+
describe("<ItemFile />", () => {
7+
test("should render component when loading", () => {
8+
render(
9+
<ItemFile
10+
title="IMG_879687880"
11+
subTitle="0.12"
12+
state={itemFileStates.loading}
13+
helper="helper"
14+
/>,
15+
);
16+
const itemFileTitle = screen.getByText("IMG_879687880");
17+
const itemFileSubTitle = screen.getByText("0.12");
18+
const itemTitleState = document.querySelector(
19+
'[aria-label="Chargement en cours"]',
20+
);
21+
22+
expect(itemFileTitle).toBeInTheDocument();
23+
expect(itemFileSubTitle).toBeInTheDocument();
24+
expect(itemTitleState).toBeInTheDocument();
25+
});
26+
27+
it("renders the component with error", () => {
28+
const { container } = render(
29+
<ItemFile
30+
title="IMG_879687880"
31+
subTitle="0.12"
32+
state={itemFileStates.error}
33+
errorMessage="Titre du message"
34+
helper="Helper"
35+
/>,
36+
);
37+
38+
expect(container.querySelector(".af-item-file")).toHaveClass(
39+
"af-item-file--error",
40+
);
41+
});
42+
43+
it("renders the component with success", () => {
44+
const { container } = render(
45+
<ItemFile
46+
title="IMG_879687880"
47+
subTitle="0.12"
48+
state={itemFileStates.success}
49+
helper="helper"
50+
/>,
51+
);
52+
53+
expect(container.querySelector("svg")).toHaveClass("af-icon__success");
54+
});
55+
56+
it("shouldn't have an accessibility violation", async () => {
57+
const { container } = render(
58+
<ItemFile
59+
state={itemFileStates.success}
60+
subTitle="0.12"
61+
title="IMG_879687880"
62+
helper="helper"
63+
deleteIconProps={{ "aria-label": "delete" }}
64+
visiibilityIconProps={{ "aria-label": "visibility" }}
65+
/>,
66+
);
67+
expect(await axe(container)).toHaveNoViolations();
68+
});
69+
});

0 commit comments

Comments
 (0)