2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { mount } from "enzyme";
|
2016-11-09 14:26:15 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import Dropdown from "components/forms/fields/Dropdown";
|
|
|
|
|
import { fillInFormInput } from "test/helpers";
|
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", () => {
|
2016-11-09 14:26:15 +00:00
|
|
|
const component = mount(<Dropdown {...props} />);
|
2021-04-12 13:32:25 +00:00
|
|
|
const dropdownSelect = component.find("Select");
|
2016-11-09 14:26:15 +00:00
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(dropdownSelect).toBeTruthy();
|
2016-11-09 14:26:15 +00:00
|
|
|
});
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("selects a value from dropdown", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const onChangeSpy = jest.fn();
|
2016-12-21 17:25:54 +00:00
|
|
|
const component = mount(<Dropdown {...props} onChange={onChangeSpy} />);
|
2021-04-12 13:32:25 +00:00
|
|
|
const inputNode = component.find("input");
|
2016-12-21 17:25:54 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
fillInFormInput(inputNode, "users");
|
|
|
|
|
component.find(".Select-option").first().simulate("mousedown");
|
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
|
|
|
});
|