From fd6769850ad0e06d5cac604979aee96f7165d6e2 Mon Sep 17 00:00:00 2001 From: Ashish Surana Date: Mon, 13 Aug 2018 01:55:47 +0530 Subject: [PATCH] fix(webui): search crash on ' ' as a value #898 (#902) * fix(webui): search crash on ' ' as a value #898 * chore(test): add unit test cases for Home component - test case for handleSearchInput function --- src/webui/modules/home/index.js | 2 +- test/unit/webui/modules/home.spec.js | 39 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/unit/webui/modules/home.spec.js diff --git a/src/webui/modules/home/index.js b/src/webui/modules/home/index.js index 8a916fa103be..edc86850aada 100644 --- a/src/webui/modules/home/index.js +++ b/src/webui/modules/home/index.js @@ -89,7 +89,7 @@ export default class Home extends React.Component { handleSearchInput(e) { this.setState({ - query: e.target.value + query: e.target.value.trim() }); } diff --git a/test/unit/webui/modules/home.spec.js b/test/unit/webui/modules/home.spec.js new file mode 100644 index 000000000000..2f28133bc46e --- /dev/null +++ b/test/unit/webui/modules/home.spec.js @@ -0,0 +1,39 @@ +/** + * Home Component + */ + +import React from 'react'; +import { mount } from 'enzyme'; +import Home from '../../../../src/webui/modules/home/index'; + +describe(' Component', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(); + }); + + it('handleSearchInput - should match the search query', () => { + const { handleSearchInput } = wrapper.instance(); + const result = 'test query string one'; + const input = { + target: { + value: result + } + }; + handleSearchInput(input); + expect(wrapper.state('query')).toBe(result); + }); + + it('handleSearchInput - should match the trimmed search query', () => { + const { handleSearchInput } = wrapper.instance(); + const result = ' '; + const input = { + target: { + value: result + } + }; + handleSearchInput(input); + expect(wrapper.state('query')).toBe(result.trim()); + }); +});