Skip to content

Commit

Permalink
rework selectWithCheckbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Apr 15, 2024
1 parent 9ef733b commit 4d92650
Showing 1 changed file with 20 additions and 72 deletions.
92 changes: 20 additions & 72 deletions src/ui/SelectWithCheckbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { WrappedRender } from "../WrappedRender";
import { SelectWithCheckbox } from "./SelectWithCheckbox";
import userEvent from "@testing-library/user-event";

describe("SelectWithCheckbox component", () => {
it("should render select without search field ", () => {
const interviewersMock = [
{
label: "john Doe",
value: "1",
},
{ label: "james Doe", value: "2" },
{ label: "Jean Dupont", value: "3" },
];
const label = "interviewer";
const interviewersMock = [
{
label: "John Doe",
value: "1",
},
{ label: "Paul Dupont", value: "2" },
];
const label = "interviewer";

const toggleSearchFilterMock = vi.fn();

const toggleSearchFilterMock = vi.fn();
describe("SelectWithCheckbox component", () => {
const render = (canSearch: boolean) =>
WrappedRender(
<SelectWithCheckbox
label={label}
Expand All @@ -31,51 +31,27 @@ describe("SelectWithCheckbox component", () => {
priority: [],
all: [],
}}
canSearch={canSearch}
/>,
);

it("should render select without search field ", () => {
render(false);

const select = screen.getByText(label);

expect(select).toBeInTheDocument();

fireEvent.click(select);

expect(screen.getByText("john Doe")).toBeInTheDocument();
expect(screen.getByText("james Doe")).toBeInTheDocument();
expect(screen.getByText("John Doe")).toBeInTheDocument();
expect(screen.getByText("Paul Dupont")).toBeInTheDocument();
// verify if search field label is not in the document
expect(screen.queryByText("Recherche")).not.toBeInTheDocument();
});

it("should render select with search field and filtered", async () => {
const interviewersMock = [
{
label: "John Doe",
value: "1",
},
{ label: "Paul Dupont", value: "2" },
];
const label = "interviewer";

const toggleSearchFilterMock = vi.fn();
WrappedRender(
<SelectWithCheckbox
label={label}
name={"interviewer"}
options={interviewersMock}
toggleSearchFilter={toggleSearchFilterMock}
filters={{
campaigns: [],
ssech: [],
interviewer: [],
states: [],
closingCause: [],
priority: [],
all: [],
}}
canSearch={true}
/>,
);

render(true);
fireEvent.click(screen.getByText(label));

expect(screen.getByText("John Doe")).toBeInTheDocument();
Expand All @@ -88,35 +64,7 @@ describe("SelectWithCheckbox component", () => {
});

it("should correctly call toggleSearchFilter", () => {
const interviewersMock = [
{
label: "John Doe",
value: "1",
},
{ label: "Paul Dupont", value: "2" },
];
const label = "interviewer";

const toggleSearchFilterMock = vi.fn();
WrappedRender(
<SelectWithCheckbox
label={label}
name={"interviewer"}
options={interviewersMock}
toggleSearchFilter={toggleSearchFilterMock}
filters={{
campaigns: [],
ssech: [],
interviewer: [],
states: [],
closingCause: [],
priority: [],
all: [],
}}
canSearch={true}
/>,
);

render(true);
fireEvent.click(screen.getByText(label));
expect(screen.getByText("John Doe")).toBeInTheDocument();
expect(screen.getByText("Paul Dupont")).toBeInTheDocument();
Expand Down

0 comments on commit 4d92650

Please sign in to comment.