From 00d4bf4176b6a787a4f5ea0f722f7211e77de4c1 Mon Sep 17 00:00:00 2001 From: stuller Date: Thu, 27 Dec 2018 16:18:53 -0600 Subject: [PATCH] minor test coverage updates --- src/Checkbox/__tests__/checkbox.test.js | 33 ++++++++++++++++++++++- src/Dropdown/__tests__/dropdown.test.js | 22 +++++++++++++++ src/TextArea/__tests__/textArea.test.js | 13 +++++++++ src/TextField/__tests__/textField.test.js | 24 +++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/Checkbox/__tests__/checkbox.test.js b/src/Checkbox/__tests__/checkbox.test.js index 7a71b3c6..5871f5d7 100755 --- a/src/Checkbox/__tests__/checkbox.test.js +++ b/src/Checkbox/__tests__/checkbox.test.js @@ -30,6 +30,24 @@ describe("Test checkbox component", () => { const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); + + it("get status returns null if prestate is true, required and not checked", () => { + const prestate = true; + const cb = mount(); + expect(cb.instance()._getStatus(prestate)).toBe(null); + }); + + it("get status returns null if prestate is true, not required", () => { + const prestate = true; + const cb = mount(); + expect(cb.instance()._getStatus(prestate)).toBe(null); + }); + + it("get status returns error if prestate is false, required", () => { + const prestate = false; + const cb = mount(); + expect(cb.instance()._getStatus(prestate)).toBe("error"); + }); }); describe("Test checkbox component - Default values", () => { @@ -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( { expect(comp.state().checked).toEqual(false); }); + it("Test checkbox component - Click event (custom onBeforeChange returns true)", function() { + const comp = mount( + + ); + 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(); expect(comp.find(".float_right").exists()).toBe(true); diff --git a/src/Dropdown/__tests__/dropdown.test.js b/src/Dropdown/__tests__/dropdown.test.js index 619dcd4b..314b3e17 100755 --- a/src/Dropdown/__tests__/dropdown.test.js +++ b/src/Dropdown/__tests__/dropdown.test.js @@ -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( + + ); + expect(dd.instance()._formValidate("true")).toEqual( + expectedValidationObject + ); + expect(dd.state().status).toBe(expectedValidationObject.status); + expect(dd.state().message).toBe(expectedValidationObject.message); + }); }); diff --git a/src/TextArea/__tests__/textArea.test.js b/src/TextArea/__tests__/textArea.test.js index 6d19a625..b3345770 100755 --- a/src/TextArea/__tests__/textArea.test.js +++ b/src/TextArea/__tests__/textArea.test.js @@ -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(