Skip to content

Commit 4f93b1b

Browse files
committed
Add unit tests for search box
1 parent aad04ce commit 4f93b1b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/tests/containers/UserList.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ describe('UsersList', () => {
3636
expect(wrapper.find('PaginationLinks')).toHaveLength(1)
3737
})
3838

39+
it('should have an Input search bar component', () => {
40+
expect(wrapper.find('Input')).toHaveLength(1)
41+
})
42+
43+
it('should normalize users for pagination', () => {
44+
let usersList = wrapper.find('UsersList')
45+
let users = usersList.instance().state.users
46+
47+
expect(Object.keys(users).length).toEqual(3)
48+
expect(users[1]).toHaveLength(12)
49+
expect(users[3]).toHaveLength(2)
50+
})
51+
3952
it('should call handlePageSelect when a pagination link is clicked', () => {
4053
let paginationLink2 = wrapper.find('span').filterWhere(item => {
4154
return item.text() === '2'
@@ -65,6 +78,20 @@ describe('UsersList', () => {
6578
expect(usersList.instance().state.firstPage).toBe(true)
6679
})
6780

81+
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+
85+
expect(usersList.instance().state.users[1]).toHaveLength(12)
86+
87+
// For some reason `searchBox.simulate('change', ...)` was not
88+
// triggering the event.
89+
searchBox.props().onChange({ target: { value: 'gordon' } })
90+
91+
expect(usersList.instance().state.users[1]).toHaveLength(1)
92+
expect(usersList.instance().state.users[1][0].first_name).toEqual('Gordon')
93+
})
94+
6895
it("shouldn't render a Project component without users", () => {
6996
const wrapper = mount(
7097
<StaticRouter context={context}>

0 commit comments

Comments
 (0)