describe('Header component', () => { const comp = <Header /> it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should show options when clicked', () => { const wrapper = mount(comp) expect(wrapper.find('HeaderOptions').exists()).toBeFalse() wrapper.find('.show_more').simulate('click') expect(wrapper.find('HeaderOptions').exists()).toBeTrue() }) })
describe('SideBar Component', () => { const comp = <SideBar uc={0} un={4} /> let dataElement beforeAll(() => (dataElement = MockDataElement())) afterAll(() => dataElement.remove()) it('should match snapshot and admin should be logged-out', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() const wrapper = mount(comp) expect(wrapper.find('.m_n_a_admin').exists()).toBe(true) }) it('should mock admin-logout action when clicked', () => { dataElement.setAttribute('data-isadmin', 'true') const wrapper = mount(comp) wrapper.find('.admin-logout').simulate('click', { preventDefault() {} }) }) })
expect(wrapper.find('Nothing').exists()).toBe(false) expect(wrapper.find('Gallery').exists()).toBe(true) expect(wrapper.find('Gallery').prop('photos').length).toBe(1) }) expect(imgTheatre.exists()).toBe(true) }) <PureGroupPhotos photos={[]} gd={Group.group_details} /> expect(wrapper.find('Nothing').exists()).toBe(true) expect(wrapper.find('Gallery').exists()).toBe(false) }) })
describe('ExplorePhotoGallery Component', () => { const comp = <PureExplorePhotoGallery photos={Explore.photos} /> // shallow snapshot it('should match snapshot', () => { const tree = shallow(comp) expect(tree).toMatchSnapshot() }) it('show show Gallery', () => { const wrapper = shallow(comp) expect(wrapper.find('Nothing').exists()).toBe(false) expect(wrapper.find('Gallery').exists()).toBe(true) expect(wrapper.find('Gallery').prop('photos').length).toBe(1) }) it('should show <ImageTheatre/> when clicked on a gallery photo', () => { const wrapper = mount(comp) wrapper.find('Gallery img').simulate('click') let imgTheatre = wrapper.find('ImageTheatre') expect(imgTheatre.exists()).toBe(true) }) it('should show <Nothing/> when photos.length == 0', () => { const wrapper = shallow(<PureExplorePhotoGallery photos={[]} />) expect(wrapper.find('Nothing').exists()).toBe(true) expect(wrapper.find('Gallery').exists()).toBe(false) }) })
describe('Upload-Avatar Component', () => { const comp = <UploadAvatar of="user" group={1} /> it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should simulate change event on file', () => { const wrapper = mount(comp) // change event const file = new Blob(['foo'], { type: 'text/plain', }) const mockedEvent = { target: { files: [file], }, } wrapper.find('input[type="file"]').simulate('change', mockedEvent) // preview-avatar comp should be present since fileAvatarChanged=true expect(wrapper.find('PreviewAvatar').exists()).toBe(true) }) })
expect(wrapper.find('Nothing').exists()).toBe(false) expect(wrapper.find('Gallery').exists()).toBe(true) expect(wrapper.find('Gallery').prop('photos').length).toBe(1) }) expect(imgTheatre.exists()).toBe(true) }) <PureUserPhotos photos={[]} ud={User.user_details} /> expect(wrapper.find('Nothing').exists()).toBe(true) expect(wrapper.find('Gallery').exists()).toBe(false) }) })
test('Shows widget details', () => { const widgets = [{name: 'red', id: 1}, {name: 'blue', id: 2}] const wrapper = mount(<App />) wrapper.setState({widgets}) expect(wrapper.find('.widget-details').exists()).toBeFalsy() wrapper.instance().showDetails(widgets[0]) wrapper.mount() expect(wrapper.find('.widget-details').exists()).toBeTruthy() })
it('matches position to state', () => { const [top, left] = [12, 34] , { target, wrapper } = setup({ top, left }) ; expect(target.exists()).toEqual(true); expect(getPosition(target)).toEqual({ top: top + 'px', left: left + 'px' }); wrapper.unmount(); });
describe('renders button text', () => { it('does not render buttonText when the buttonText prop is absent', () => { const wrapper = mount(<Button />); expect(wrapper.find('Text').exists()).toBe(false); }); it('renders button text when the buttonText prop is present', () => { const wrapper = mount(<Button buttonText="Hello" />); expect(wrapper.render().text()).toEqual(wrapper.props().buttonText); }); });
describe('renders icon', () => { it('does not render an icon when the icon prop is absent', () => { const wrapper = mount(<Button buttonText="Hello" />); expect(wrapper.find('Icon').exists()).toBe(false); }); it('renders an icon when the icon prop is present', () => { const wrapper = mount( <Button buttonText="Hello" icon={<i className="fa fa-heart" />} /> ); expect(wrapper.find('Icon').exists()).toBe(true); }); });