Skip to content

Commit 246185f

Browse files
author
Andrei Alexandru
committed
autocomplete tests
1 parent 7e726b8 commit 246185f

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react';
2+
3+
import Autocomplete from './Autocomplete.jsx';
4+
5+
test('className default is autocomplete', () => {
6+
const component = shallow(<Autocomplete/>);
7+
expect(component.hasClass('autocomplete')).toBe(true);
8+
});
9+
10+
test('className is test-autocomplete', () => {
11+
const component = shallow(<Autocomplete className="test-autocomplete"/>);
12+
expect(component.hasClass('test-autocomplete')).toBe(true);
13+
});
14+
15+
test('placeholder of input is updated from property', ()=> {
16+
const component = shallow(<Autocomplete placeholder="Search User" />);
17+
expect(component.find('input').prop('placeholder')).toEqual('Search User');
18+
});
19+
20+
test('click on Clear triggers handleSearch and handleBlur', () => {
21+
const searchChanged = (value) => {
22+
expect(value).toEqual('');
23+
},
24+
handleBlur = () => {},
25+
spy = jest.spyOn(Autocomplete.prototype, 'handleClear'),
26+
component = mount(<Autocomplete searchChanged={searchChanged} handleBlur={handleBlur} />);
27+
component.find('CustomButton').simulate('click');
28+
29+
expect(spy).toHaveBeenCalled();
30+
});
31+
32+
test('onChange triggers handleSearchChanged', () => {
33+
const searchChanged = (value) => {
34+
expect(value).toEqual('');
35+
},
36+
spy = jest.spyOn(Autocomplete.prototype, 'handleSearchChanged'),
37+
component = mount(<Autocomplete searchChanged={searchChanged} />);
38+
component.find('input').simulate('change',{});
39+
40+
expect(spy).toHaveBeenCalled();
41+
});
42+
43+
test('onBlur triggers handleBlur', done => {
44+
const searchChanged = () => {
45+
},
46+
handleBlur = () => {},
47+
spy = jest.spyOn(Autocomplete.prototype, 'handleBlur'),
48+
component = mount(<Autocomplete searchChanged={searchChanged} handleBlur={handleBlur}/>);
49+
component.find('input').simulate('blur', {});
50+
expect(spy).toHaveBeenCalled();
51+
done();
52+
})
53+
54+
test('if value and no items empty-items className is added', () => {
55+
const component = mount(<Autocomplete value="abc" />),
56+
input = component.find('input');
57+
expect(input.hasClass('empty-items')).toBe(true);
58+
})

views/src/components/Wishlist.test.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import renderer from 'react-test-renderer';
55
import WishList from './Wishlist.jsx';
66
import store from '../store/index';
77

8-
// import {wishlistAddProduct} from '../actions/index';
9-
108
test('Initiated Wishlist matches the snapshot', () => {
119
const component = renderer.create(
1210
<Provider store={store}>
@@ -24,15 +22,3 @@ test('wishlist className is wishlist-products', () => {
2422
</Provider>);
2523
expect(wrapper.find('.wishlist-products')).toHaveLength(1);
2624
});
27-
28-
// test('wishlistGetIds is called once', ()=> {
29-
// let wrapper = mount(
30-
// <WishList store={store} />);
31-
// const props = wrapper.instance().props;
32-
// // store = props.store;
33-
// props.store.subscribe(() => {
34-
// expect(props.store.getState()).user.wishlist.toHaveLength(1);
35-
// });
36-
//
37-
// props.store.dispatch(wishlistAddProduct('5b6830856882617d10f2a567'));
38-
// });

0 commit comments

Comments
 (0)