2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount, shallow } from "enzyme";
|
|
|
|
import Checkbox from ".";
|
2019-09-06 10:55:09 +00:00
|
|
|
|
2019-11-27 07:29:07 +00:00
|
|
|
const baseProps = {
|
2020-10-16 13:16:01 +00:00
|
|
|
value: "test",
|
|
|
|
};
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
describe("<Checkbox />", () => {
|
|
|
|
it("renders without error", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} />);
|
2019-09-06 10:55:09 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts id", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} id="testId" />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("id")).toEqual("testId");
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts className", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} className="test" />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("className")).toEqual("test");
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts style", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} style={{ color: "red" }} />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.getDOMNode().style).toHaveProperty("color", "red");
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts isDisabled", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} isDisabled />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isDisabled")).toEqual(true);
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts isIndeterminate", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} isIndeterminate />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isIndeterminate")).toEqual(true);
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts isChecked", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} isChecked />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isChecked")).toEqual(true);
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("accepts isChecked and isDisabled", () => {
|
|
|
|
const wrapper = mount(<Checkbox {...baseProps} isChecked isDisabled />);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
expect(wrapper.prop("isChecked")).toEqual(true);
|
|
|
|
expect(wrapper.prop("isDisabled")).toEqual(true);
|
2019-11-27 07:29:07 +00:00
|
|
|
});
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
it("componentDidUpdate() props lifecycle test", () => {
|
2019-11-27 07:29:07 +00:00
|
|
|
const wrapper = shallow(<Checkbox {...baseProps} />);
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
instance.componentDidUpdate(
|
|
|
|
{
|
|
|
|
isChecked: true,
|
|
|
|
},
|
|
|
|
wrapper.state()
|
|
|
|
);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
|
|
|
expect(wrapper.props()).toBe(wrapper.props());
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
instance.componentDidUpdate(
|
|
|
|
{
|
|
|
|
isChecked: false,
|
|
|
|
},
|
|
|
|
wrapper.state()
|
|
|
|
);
|
2019-11-27 07:29:07 +00:00
|
|
|
|
|
|
|
expect(wrapper.props()).toBe(wrapper.props());
|
|
|
|
});
|
2019-09-06 10:55:09 +00:00
|
|
|
});
|