Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/714 add test slider component #806

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Hakan-Orak
Copy link

Add test coverage for Slider Component :
image

From this issue :
#714

@@ -23,7 +23,12 @@ const SliderInput = ({
...sliderProps
}: Props) => {
const generatedId = useId();
const newId = useMemo(() => id ?? generatedId, [generatedId, id]);
const newId = useMemo(() => {
if (id && id !== "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En faisant simplement ça il va prendre en compte la valeur null, undefined et empty string

Suggested change
if (id && id !== "") {
if (id) {

Comment on lines +40 to +43
let user: UserEvent;
beforeEach(() => {
user = userEvent.setup();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le userEvent.setup n'est pas forcément nécessaire je pense

});

it("should have default value 128", () => {
let valueSlider: number = 256;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

la value est 256 et non 128 ?

Comment on lines +93 to +114
it("should have active class until 2048 value", async () => {
// Act
render(
<Slider
id="slider-id"
name="slider-name"
options={options}
onChange={() => console.log("some change")}
/>,
);

const selectValueSlider = screen.getByText("1024");
await user.click(selectValueSlider);

// Assert
sliderIsActive("64");
sliderIsActive("128");
sliderIsActive("256");
sliderIsActive("1024");
sliderIsNotActive("2048");
sliderIsNotActive("4096");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

donc par défaut c'est actif jusque 2048 sans avoir de value de définit ?

Comment on lines +116 to +139
it("should be disabled with classModifier", async () => {
// Act
render(
<Slider
id="slider-id"
name="slider-name"
value={256}
options={options}
onChange={() => console.log("some change")}
classModifier="disabled"
/>,
);

const selectValueSlider = screen.getByText("1024");
await user.click(selectValueSlider);

// Assert
sliderIsActive("64");
sliderIsActive("128");
sliderIsActive("256");
sliderIsNotActive("1024");
sliderIsNotActive("2048");
sliderIsNotActive("4096");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quand c'est disabled on est pas censé pouvoir bouger le curseur si ?

Comment on lines +141 to +164
it("should be disabled with props", async () => {
// Act
render(
<Slider
id="slider-id"
name="slider-name"
value={256}
options={options}
onChange={() => console.log("some change")}
disabled
/>,
);

const selectValueSlider = screen.getByText("1024");
await user.click(selectValueSlider);

// Assert
sliderIsActive("64");
sliderIsActive("128");
sliderIsActive("256");
sliderIsNotActive("1024");
sliderIsNotActive("2048");
sliderIsNotActive("4096");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quand c'est disabled on est pas censé pouvoir bouger le curseur si ?

Comment on lines +184 to +205
it("should have options without label", async () => {
// Act
render(
<Slider
id="slider-id"
name="slider-name"
options={optionsWithoutLabel}
onChange={() => console.log("some change")}
/>,
);

const selectValueSlider = screen.getByText("1024");
await user.click(selectValueSlider);

// Assert
sliderIsActive("64");
sliderIsActive("128");
sliderIsActive("256");
sliderIsActive("1024");
sliderIsNotActive("2048");
sliderIsNotActive("4096");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça ne teste rien de plus que d'autres tests au dessus non ?

Comment on lines +207 to +227
it("should have Slider with onChangeComplet", async () => {
// Act
const { container } = render(
<Slider
id="slider-id"
name="slider-name"
ariaLabelForHandle="slider-label"
options={optionsWithoutLabel}
onChangeComplete={(selectedValue: {
id: string;
name: string;
value: number;
}) => {
console.log(selectedValue);
}}
/>,
);

// Assert
expect(await axe(container)).toHaveNoViolations();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est un test d'accessibilité

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants