-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: main
Are you sure you want to change the base?
Feature/714 add test slider component #806
Conversation
@@ -23,7 +23,12 @@ const SliderInput = ({ | |||
...sliderProps | |||
}: Props) => { | |||
const generatedId = useId(); | |||
const newId = useMemo(() => id ?? generatedId, [generatedId, id]); | |||
const newId = useMemo(() => { | |||
if (id && id !== "") { |
There was a problem hiding this comment.
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
if (id && id !== "") { | |
if (id) { |
let user: UserEvent; | ||
beforeEach(() => { | ||
user = userEvent.setup(); | ||
}); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ?
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"); | ||
}); |
There was a problem hiding this comment.
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 ?
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"); | ||
}); |
There was a problem hiding this comment.
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 ?
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"); | ||
}); |
There was a problem hiding this comment.
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 ?
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"); | ||
}); |
There was a problem hiding this comment.
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 ?
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(); | ||
}); |
There was a problem hiding this comment.
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é
Add test coverage for Slider Component :

From this issue :
#714