|
| 1 | +/* eslint-disable no-unused-expressions, react/prop-types */ |
| 2 | +import { expect } from 'chai'; |
| 3 | + |
| 4 | +import React from 'react'; |
| 5 | +import { shallow } from 'enzyme'; |
| 6 | +import ProfileList from '../ProfileList'; |
| 7 | +import ProfileBox from '../../ProfileBox/ProfileBox'; |
| 8 | + |
| 9 | +describe('components/ProfileList', () => { |
| 10 | + describe('state/render', () => { |
| 11 | + describe('case props.results not hydrated with data', () => { |
| 12 | + it('should render default message if props.results=null', () => { |
| 13 | + const wrapper = shallow(<ProfileList results={null} />); |
| 14 | + expect(wrapper.type()).to.be.equal('p'); |
| 15 | + }); |
| 16 | + it('should render the error if props.results.error is set', () => { |
| 17 | + const wrapper = shallow(<ProfileList results={{error: 'Something went wrong'}} />); |
| 18 | + expect(wrapper.equals(<div>Something went wrong</div>)).to.be.true; |
| 19 | + }); |
| 20 | + it('should show "No results" if props.results.total_count=0', () => { |
| 21 | + const wrapper = shallow(<ProfileList results={{total_count: 0}} />); |
| 22 | + expect(wrapper.equals(<div>No results.</div>)).to.be.true; |
| 23 | + }); |
| 24 | + }); |
| 25 | + describe('case props.results hydrated with data', () => { |
| 26 | + it('header should show "Total result" in case props.results.total_count=1', () => { |
| 27 | + const wrapper = shallow(<ProfileList results={{total_count: 1, items: [{$avatar_url: 'someurl', id: 42, login: 'foo'}] }} />); |
| 28 | + expect(wrapper.find('.panel-heading').text()).to.equal('Total result : 1 / showing : 1'); |
| 29 | + }); |
| 30 | + it('header should show "Total results" in case props.results.total_count>1', () => { |
| 31 | + const wrapper = shallow(<ProfileList results={{total_count: 2, items: [{$avatar_url: 'someurl', id: 42, login: 'foo'}, {$avatar_url: 'someurl', id: 43, login: 'bar'}] }} />); |
| 32 | + expect(wrapper.find('.panel-heading').text()).to.equal('Total results : 2 / showing : 2'); |
| 33 | + }); |
| 34 | + it('should render correctly the ProfileBox in the list', () => { |
| 35 | + const wrapper = shallow(<ProfileList results={{total_count: 1, items: [{$avatar_url: 'someurl', id: 42, login: 'foo'}] }} />); |
| 36 | + expect(wrapper.find(ProfileBox).first().prop('user').id).to.equal(42); |
| 37 | + }); |
| 38 | + it('should render correctly multiple ProfileBox in the list', () => { |
| 39 | + const wrapper = shallow(<ProfileList results={{total_count: 1, items: [{$avatar_url: 'someurl', id: 42, login: 'foo'}, {$avatar_url: 'someurl', id: 43, login: 'bar'}] }} />); |
| 40 | + expect(wrapper.find(ProfileBox).length).to.equal(2); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | +}); |
0 commit comments