2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount, shallow } from "enzyme";
|
|
|
|
import SearchInput from ".";
|
|
|
|
import InputBlock from "../input-block";
|
2019-09-08 15:45:59 +00:00
|
|
|
|
2019-12-03 13:15:16 +00:00
|
|
|
const baseProps = {
|
|
|
|
isNeedFilter: true,
|
2020-10-16 13:16:01 +00:00
|
|
|
value: "",
|
2019-12-25 06:47:42 +00:00
|
|
|
getFilterData: () => [
|
2020-10-16 13:16:01 +00:00
|
|
|
{
|
|
|
|
key: "filter-example",
|
|
|
|
group: "filter-example",
|
|
|
|
label: "example group",
|
|
|
|
isHeader: true,
|
|
|
|
},
|
|
|
|
{ key: "filter-example-test", group: "filter-example", label: "Test" },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("<SearchInput />", () => {
|
|
|
|
it("renders without error", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} />);
|
2019-09-08 15:45:59 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("middle size prop", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="middle" />);
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("size")).toEqual("middle");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("big size prop", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="big" />);
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("size")).toEqual("big");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("huge size prop", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="huge" />);
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("size")).toEqual("huge");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts id", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} id="testId" />);
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("id")).toEqual("testId");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts className", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} className="test" />);
|
2019-12-03 13:15:16 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("className")).toEqual("test");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts style", () => {
|
2019-12-03 13:15:16 +00:00
|
|
|
const wrapper = mount(
|
2020-10-16 13:16:01 +00:00
|
|
|
<SearchInput {...baseProps} style={{ color: "red" }} />
|
2019-12-03 13:15:16 +00:00
|
|
|
);
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.getDOMNode().style).toHaveProperty("color", "red");
|
2019-12-03 13:15:16 +00:00
|
|
|
});
|
2021-03-02 08:25:11 +00:00
|
|
|
// TODO: Fix icons tests
|
|
|
|
/*it("call onClearSearch", () => {
|
2019-12-25 06:47:42 +00:00
|
|
|
const onClearSearch = jest.fn();
|
|
|
|
const onChange = jest.fn();
|
2020-10-16 13:16:01 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
<SearchInput
|
|
|
|
{...baseProps}
|
|
|
|
onClearSearch={onClearSearch}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 06:47:42 +00:00
|
|
|
const icon = wrapper.find(".append div");
|
2020-10-16 13:16:01 +00:00
|
|
|
icon.first().simulate("click");
|
2019-12-25 06:47:42 +00:00
|
|
|
expect(onClearSearch).toHaveBeenCalled();
|
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("not call onClearSearch", () => {
|
2019-12-25 09:28:54 +00:00
|
|
|
const onClearSearch = jest.fn();
|
|
|
|
const onChange = jest.fn();
|
2020-10-16 13:16:01 +00:00
|
|
|
const wrapper = mount(<SearchInput {...baseProps} onChange={onChange} />);
|
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const icon = wrapper.find(".append div");
|
2020-10-16 13:16:01 +00:00
|
|
|
icon.first().simulate("click");
|
2019-12-25 09:28:54 +00:00
|
|
|
expect(onClearSearch).not.toHaveBeenCalled();
|
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("componentDidUpdate() props lifecycle test", () => {
|
2019-12-25 06:47:42 +00:00
|
|
|
const wrapper = shallow(<SearchInput {...baseProps} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
instance.componentDidUpdate(
|
|
|
|
{
|
|
|
|
opened: true,
|
|
|
|
selectedOption: {
|
|
|
|
value: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wrapper.state()
|
|
|
|
);
|
2019-12-25 06:47:42 +00:00
|
|
|
|
|
|
|
expect(wrapper.props()).toBe(wrapper.props());
|
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("not call setSearchTimer", (done) => {
|
2019-12-25 09:28:54 +00:00
|
|
|
const onChange = jest.fn();
|
2020-10-16 13:16:01 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
<SearchInput {...baseProps} autoRefresh={false} onChange={onChange} />
|
|
|
|
);
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const input = wrapper.find("input");
|
|
|
|
input.first().simulate("change", { target: { value: "test" } });
|
2020-10-16 13:16:01 +00:00
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(onChange).not.toHaveBeenCalled();
|
2020-10-16 13:16:01 +00:00
|
|
|
done();
|
2019-12-25 09:28:54 +00:00
|
|
|
}, 1000);
|
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("call setSearchTimer", (done) => {
|
2019-12-25 06:47:42 +00:00
|
|
|
const onChange = jest.fn();
|
2020-10-16 13:16:01 +00:00
|
|
|
const wrapper = mount(<SearchInput {...baseProps} onChange={onChange} />);
|
2019-12-25 06:47:42 +00:00
|
|
|
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
instance.setSearchTimer("test");
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
2020-10-16 13:16:01 +00:00
|
|
|
done();
|
2019-12-25 06:47:42 +00:00
|
|
|
}, 1000);
|
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("test icon button size. base size prop", () => {
|
2019-12-25 09:28:54 +00:00
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="base" />);
|
2020-10-16 13:16:01 +00:00
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const inputBlock = wrapper.find(InputBlock);
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(inputBlock.prop("iconSize")).toEqual(12);
|
2019-12-25 09:28:54 +00:00
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("test icon button size. middle size prop", () => {
|
2019-12-25 09:28:54 +00:00
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="middle" />);
|
2020-10-16 13:16:01 +00:00
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const inputBlock = wrapper.find(InputBlock);
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(inputBlock.prop("iconSize")).toEqual(16);
|
2019-12-25 09:28:54 +00:00
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("test icon button size. big size prop", () => {
|
2019-12-25 09:28:54 +00:00
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="big" />);
|
2020-10-16 13:16:01 +00:00
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const inputBlock = wrapper.find(InputBlock);
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(inputBlock.prop("iconSize")).toEqual(19);
|
2019-12-25 09:28:54 +00:00
|
|
|
});
|
2020-10-16 13:16:01 +00:00
|
|
|
it("test icon button size. huge size prop", () => {
|
|
|
|
const wrapper = mount(<SearchInput {...baseProps} size="huge" />);
|
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find("input")
|
|
|
|
.first()
|
|
|
|
.simulate("change", { target: { value: "test" } });
|
|
|
|
|
2019-12-25 09:28:54 +00:00
|
|
|
const inputBlock = wrapper.find(InputBlock);
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(inputBlock.prop("iconSize")).toEqual(22);
|
2021-03-02 08:25:11 +00:00
|
|
|
});*/
|
2019-09-08 15:45:59 +00:00
|
|
|
});
|