Skip to content

Commit

Permalink
fix(webui): search crash on ' ' as a value #898 (#902)
Browse files Browse the repository at this point in the history
* fix(webui): search crash on ' ' as a value #898

* chore(test): add unit test cases for Home component

  - test case for handleSearchInput function
  • Loading branch information
ashishsurana authored and ayusharma committed Aug 12, 2018
1 parent 4112587 commit fd67698
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/webui/modules/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Home extends React.Component {

handleSearchInput(e) {
this.setState({
query: e.target.value
query: e.target.value.trim()
});
}

Expand Down
39 changes: 39 additions & 0 deletions test/unit/webui/modules/home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Home Component
*/

import React from 'react';
import { mount } from 'enzyme';
import Home from '../../../../src/webui/modules/home/index';

describe('<Home /> Component', () => {
let wrapper;

beforeEach(() => {
wrapper = mount(<Home />);
});

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());
});
});

0 comments on commit fd67698

Please sign in to comment.