-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import userEvent, { UserEvent } from "@testing-library/user-event"; | ||
import { Slider } from "../Slider"; | ||
|
||
const options = [ | ||
{ label: "64", value: 64 }, | ||
{ label: "128", value: 128 }, | ||
{ label: "256", value: 256 }, | ||
{ label: "1024", value: 1024 }, | ||
{ label: "2048", value: 2048 }, | ||
{ label: "4096", value: 4096 }, | ||
]; | ||
|
||
const optionsWithoutLabel = [ | ||
{ value: 64 }, | ||
{ value: 128 }, | ||
{ value: 256 }, | ||
{ value: 1024 }, | ||
{ value: 2048 }, | ||
{ value: 4096 }, | ||
]; | ||
|
||
const sliderIsActive = (value: string) => { | ||
expect(screen.getByText(value)).toHaveClass( | ||
"rc-slider-mark-text rc-slider-mark-text-active", | ||
{ | ||
exact: true, | ||
}, | ||
); | ||
}; | ||
|
||
const sliderIsNotActive = (value: string) => { | ||
expect(screen.getByText(value)).toHaveClass("rc-slider-mark-text", { | ||
exact: true, | ||
}); | ||
}; | ||
|
||
describe("Slider", () => { | ||
let user: UserEvent; | ||
beforeEach(() => { | ||
user = userEvent.setup(); | ||
}); | ||
Comment on lines
+40
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 value 64 have active class", () => { | ||
let valueSlider: number = 64; | ||
// Act | ||
render( | ||
<Slider | ||
id="slider-id" | ||
name="slider-name" | ||
options={options} | ||
value={valueSlider} | ||
onChange={({ value }) => { | ||
valueSlider = value; | ||
}} | ||
/>, | ||
); | ||
|
||
// Assert | ||
sliderIsActive("64"); | ||
sliderIsNotActive("128"); | ||
sliderIsNotActive("256"); | ||
sliderIsNotActive("1024"); | ||
sliderIsNotActive("2048"); | ||
sliderIsNotActive("4096"); | ||
}); | ||
|
||
it("should have default value 128", () => { | ||
let valueSlider: number = 256; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. la value est 256 et non 128 ? |
||
// Act | ||
render( | ||
<Slider | ||
id="slider-id" | ||
name="slider-name" | ||
options={options} | ||
defaultValue={valueSlider} | ||
onChange={({ value }) => { | ||
valueSlider = value; | ||
}} | ||
/>, | ||
); | ||
|
||
// Assert | ||
sliderIsActive("64"); | ||
sliderIsActive("128"); | ||
sliderIsActive("256"); | ||
sliderIsNotActive("1024"); | ||
sliderIsNotActive("2048"); | ||
sliderIsNotActive("4096"); | ||
}); | ||
|
||
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"); | ||
}); | ||
Comment on lines
+93
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
}); | ||
Comment on lines
+116
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
}); | ||
Comment on lines
+141
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 aria label handle", async () => { | ||
// Act | ||
render( | ||
<Slider | ||
id="slider-id" | ||
name="slider-name" | ||
defaultValue={256} | ||
ariaLabelForHandle="aria-label-handle" | ||
options={options} | ||
onChange={() => console.log("some change")} | ||
/>, | ||
); | ||
|
||
// Assert | ||
const ariaLabelHandle = screen.getByLabelText("aria-label-handle"); | ||
expect(ariaLabelHandle).toBeInTheDocument(); | ||
}); | ||
|
||
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"); | ||
}); | ||
Comment on lines
+184
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
}); | ||
Comment on lines
+207
to
+227
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c'est un test d'accessibilité |
||
|
||
it("shouldn't have an accesibility violation <Slider />", async () => { | ||
// Act | ||
const { container } = render( | ||
<Slider | ||
id="slider-id" | ||
name="slider-name" | ||
ariaLabelForHandle="slider-label" | ||
options={optionsWithoutLabel} | ||
onChange={() => console.log("some change")} | ||
/>, | ||
); | ||
|
||
// 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.
En faisant simplement ça il va prendre en compte la valeur null, undefined et empty string