Skip to content

minor test coverage updates #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/Checkbox/__tests__/checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ describe("Test checkbox component", () => {
const tree = renderer.create(<Checkbox label={"labelText"} />).toJSON();
expect(tree).toMatchSnapshot();
});

it("get status returns null if prestate is true, required and not checked", () => {
const prestate = true;
const cb = mount(<Checkbox label={"labelText"} required />);
expect(cb.instance()._getStatus(prestate)).toBe(null);
});

it("get status returns null if prestate is true, not required", () => {
const prestate = true;
const cb = mount(<Checkbox label={"labelText"} />);
expect(cb.instance()._getStatus(prestate)).toBe(null);
});

it("get status returns error if prestate is false, required", () => {
const prestate = false;
const cb = mount(<Checkbox label={"labelText"} required />);
expect(cb.instance()._getStatus(prestate)).toBe("error");
});
});

describe("Test checkbox component - Default values", () => {
Expand Down Expand Up @@ -119,7 +137,7 @@ describe("Test checkbox component - Default values", () => {
expect(handleChange).toBeCalled();
});

it("Test checkbox component - Click event (custom onBeforeChange)", function() {
it("Test checkbox component - Click event (custom onBeforeChange returns false)", function() {
const comp = mount(
<Checkbox
onBeforeChange={function() {
Expand All @@ -132,6 +150,19 @@ describe("Test checkbox component - Default values", () => {
expect(comp.state().checked).toEqual(false);
});

it("Test checkbox component - Click event (custom onBeforeChange returns true)", function() {
const comp = mount(
<Checkbox
onBeforeChange={function() {
return true;
}}
/>
);
expect(comp.state().checked).toEqual(false);
comp.simulate("click");
expect(comp.state().checked).toEqual(true);
});

it("Test checkbox component - labelPosition left", function() {
const comp = mount(<Checkbox labelPosition="left" />);
expect(comp.find(".float_right").exists()).toBe(true);
Expand Down
22 changes: 22 additions & 0 deletions src/Dropdown/__tests__/dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,26 @@ describe("Test Dropdown component - setOptions() method", () => {
expect(event.persist).toBeCalled();
expect(event.preventDefault).toBeCalled();
});

it("_formValidate sets state & returns validationObject", () => {
const expectedValidationObject = {
status: null,
message: null
};
const dd = mount(
<Dropdown
name="dataDropdown"
id="dataDropdown"
options={[
{ text: "yes", value: "true" },
{ text: "no", value: "false" }
]}
/>
);
expect(dd.instance()._formValidate("true")).toEqual(
expectedValidationObject
);
expect(dd.state().status).toBe(expectedValidationObject.status);
expect(dd.state().message).toBe(expectedValidationObject.message);
});
});
13 changes: 13 additions & 0 deletions src/TextArea/__tests__/textArea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,17 @@ describe("Test Text component", () => {
"this field is required"
);
});

it("_formValidate sets state and returns validationObject", function() {
const expectedValidationObject = {
status: null,
message: null
};
const ta = mount(<TextArea id="myTextArea" />);
expect(ta.instance()._formValidate("foo")).toEqual(
expectedValidationObject
);
expect(ta.state().status).toBe(expectedValidationObject.status);
expect(ta.state().message).toBe(expectedValidationObject.message);
});
});
24 changes: 24 additions & 0 deletions src/TextField/__tests__/textField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ describe("Suite - events", () => {
expect(handleFocus).toBeCalled();
});

it("focus does not call onFocus if onFocus is not a function", () => {
const handleFocus = jest.fn();
const tf = mount(<TextField label="name" />);

tf.find("input").simulate("focus");
expect(handleFocus).not.toBeCalled();
});

it("click calls onClick if onClick is a function", () => {
const handleClick = jest.fn();
const tf = mount(<TextField label="name" onClick={handleClick} />);

tf.find("input").simulate("click");
expect(handleClick).toBeCalled();
});

it("click does not call onClick if onClick is not a function", () => {
const handleClick = jest.fn();
const tf = mount(<TextField label="name" />);

tf.find("input").simulate("click");
expect(handleClick).not.toBeCalled();
});

it("handle paste with no mask", () => {
const event = {
preventDefault: jest.fn(),
Expand Down