@@ -5,7 +5,7 @@ import usersFixture from '../../fixtures/users'
55import { StaticRouter } from 'react-router'
66
77describe ( 'UsersList' , ( ) => {
8- let wrapper
8+ let wrapper , usersList , searchBox
99 const context = { }
1010 wrapper = mount (
1111 < StaticRouter context = { context } >
@@ -23,6 +23,8 @@ describe('UsersList', () => {
2323 />
2424 </ StaticRouter >
2525 )
26+ usersList = wrapper . find ( 'UsersList' )
27+ searchBox = wrapper . find ( 'Input' )
2628
2729 it ( 'should have a header Volunteers Directory' , ( ) => {
2830 expect ( wrapper . find ( 'Header' ) . text ( ) ) . toBe ( 'Volunteers Directory' )
@@ -41,7 +43,6 @@ describe('UsersList', () => {
4143 } )
4244
4345 it ( 'should normalize users for pagination' , ( ) => {
44- let usersList = wrapper . find ( 'UsersList' )
4546 let users = usersList . instance ( ) . state . users
4647
4748 expect ( Object . keys ( users ) . length ) . toEqual ( 3 )
@@ -54,7 +55,7 @@ describe('UsersList', () => {
5455 return item . text ( ) === '2'
5556 } )
5657 paginationLink2 . simulate ( 'click' )
57- let usersList = wrapper . find ( 'UsersList' )
58+
5859 expect ( usersList . instance ( ) . state . selectedPage ) . toEqual ( 2 )
5960 expect ( usersList . instance ( ) . state . lastPage ) . toBe ( false )
6061 expect ( usersList . instance ( ) . state . firstPage ) . toBe ( false )
@@ -65,7 +66,7 @@ describe('UsersList', () => {
6566 return item . text ( ) === '3'
6667 } )
6768 paginationLink2 . simulate ( 'click' )
68- let usersList = wrapper . find ( 'UsersList' )
69+
6970 expect ( usersList . instance ( ) . state . lastPage ) . toBe ( true )
7071 } )
7172
@@ -74,14 +75,11 @@ describe('UsersList', () => {
7475 return item . text ( ) === '1'
7576 } )
7677 paginationLink2 . simulate ( 'click' )
77- let usersList = wrapper . find ( 'UsersList' )
78+
7879 expect ( usersList . instance ( ) . state . firstPage ) . toBe ( true )
7980 } )
8081
8182 it ( 'should limit the users list after query is entered in search box' , ( ) => {
82- let usersList = wrapper . find ( 'UsersList' )
83- let searchBox = wrapper . find ( 'Input' )
84-
8583 expect ( usersList . instance ( ) . state . users [ 1 ] ) . toHaveLength ( 12 )
8684
8785 // For some reason `searchBox.simulate('change', ...)` was not
@@ -90,6 +88,21 @@ describe('UsersList', () => {
9088
9189 expect ( usersList . instance ( ) . state . users [ 1 ] ) . toHaveLength ( 1 )
9290 expect ( usersList . instance ( ) . state . users [ 1 ] [ 0 ] . first_name ) . toEqual ( 'Gordon' )
91+
92+ searchBox . props ( ) . onChange ( { target : { value : '' } } )
93+ } )
94+
95+ it ( 'should show no users if query in search box does not match any entry' , ( ) => {
96+ expect ( usersList . instance ( ) . state . users [ 1 ] ) . toHaveLength ( 12 )
97+
98+ searchBox . props ( ) . onChange ( { target : { value : 'blablabla' } } )
99+
100+ expect ( usersList . instance ( ) . state . users [ 1 ] ) . toBeUndefined ( )
101+
102+ let resultColumns = wrapper . find ( 'CardGroup' )
103+ expect ( resultColumns . text ( ) ) . toEqual ( 'No users found.' )
104+
105+ searchBox . props ( ) . onChange ( { target : { value : '' } } )
93106 } )
94107
95108 it ( "shouldn't render a Project component without users" , ( ) => {
0 commit comments