1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00

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
This commit is contained in:
Ashish Surana 2018-08-13 01:55:47 +05:30 committed by Ayush Sharma
parent 4112587d72
commit fd6769850a
2 changed files with 40 additions and 1 deletions

@ -89,7 +89,7 @@ export default class Home extends React.Component {
handleSearchInput(e) {
this.setState({
query: e.target.value
query: e.target.value.trim()
});
}

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