mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-21 07:29:37 +01:00
* 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:
parent
4112587d72
commit
fd6769850a
@ -89,7 +89,7 @@ export default class Home extends React.Component {
|
|||||||
|
|
||||||
handleSearchInput(e) {
|
handleSearchInput(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
query: e.target.value
|
query: e.target.value.trim()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
test/unit/webui/modules/home.spec.js
Normal file
39
test/unit/webui/modules/home.spec.js
Normal file
@ -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());
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user