2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
2022-09-12 15:10:10 +00:00
|
|
|
import { render, screen } from "@testing-library/react";
|
2022-12-14 18:56:56 +00:00
|
|
|
import { renderWithSetup } from "test/test-utils";
|
2016-11-09 14:26:15 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import Dropdown from "components/forms/fields/Dropdown";
|
2016-11-09 14:26:15 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("Dropdown - component", () => {
|
2016-11-09 14:26:15 +00:00
|
|
|
const options = [
|
2021-04-12 13:32:25 +00:00
|
|
|
{ text: "Users", value: "users" },
|
|
|
|
|
{ text: "Groups", value: "groups" },
|
2016-11-09 14:26:15 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const props = {
|
2021-04-12 13:32:25 +00:00
|
|
|
name: "my-select",
|
2016-11-09 14:26:15 +00:00
|
|
|
options,
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders the dropdown", () => {
|
2022-03-18 19:08:54 +00:00
|
|
|
render(<Dropdown {...props} />);
|
|
|
|
|
const dropdownSelect = screen.getByRole("combobox");
|
2016-11-09 14:26:15 +00:00
|
|
|
|
2022-03-18 19:08:54 +00:00
|
|
|
expect(dropdownSelect).toBeInTheDocument();
|
2016-11-09 14:26:15 +00:00
|
|
|
});
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2022-03-18 19:08:54 +00:00
|
|
|
it("selects a value from dropdown", async () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const onChangeSpy = jest.fn();
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
|
|
|
|
<Dropdown {...props} onChange={onChangeSpy} />
|
|
|
|
|
);
|
2022-03-18 19:08:54 +00:00
|
|
|
const inputNode = screen.getByRole("combobox");
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.type(inputNode, "users");
|
|
|
|
|
await user.click(screen.getByRole("option"));
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
expect(onChangeSpy).toHaveBeenCalledWith("users");
|
2016-12-21 17:25:54 +00:00
|
|
|
});
|
2016-11-09 14:26:15 +00:00
|
|
|
});
|