describe('AddToFavourites Component', () => { const comp = <AddToFavourites user={7} username="ghalib" /> it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should mock add-to-favs action when clicked', () => { const wrapper = mount(comp) wrapper.find('SecondaryButton').simulate('click', { preventDefault() {} }) }) })
describe('RefreshExplores Component', () => { const comp = ( <Provider store={mockStore}> <RefreshExplores url="/explore" /> </Provider> ) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should mock refresh action when clicked', () => { const wrapper = mount(comp) wrapper.find('a.exp_refresh').simulate('click', { preventDefault() {} }) }) })
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() {} }) }) })
describe('Admin-Login Component', () => { let dataElement = MockDataElement() const comp = ( <Provider store={mockStore}> <AdminLogin location={{ search: '/' }} /> </Provider> ) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should mock admin-login submit action', () => { const wrapper = mount(comp) wrapper.find('form').simulate('submit', { preventDefault() {} }) }) it('should redirect to /is-admin route when user is admin', () => { dataElement.setAttribute('data-isadmin', 'true') const wrapper = shallow(<AdminLogin location={{ search: '/' }} />) expect(wrapper.find('Redirect').exists()).toBe(true) }) })
const wrapper = mount(comp) wrapper.find('Gallery img').simulate('click')
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('Unfollow Component', () => { const props = { user: 7, unfollowed() {}, } it('should match snapshot', () => { const tree = create(<Unfollow {...props} store={mockStore} />).toJSON() expect(tree).toMatchSnapshot() }) it('should mock unfollow action when clicked', () => { const wrapper = mount(<Unfollow {...props} store={mockStore} />) wrapper.find('PrimaryButton').simulate('click') }) })
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('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) }) })
const wrapper = mount(comp) wrapper.find('Gallery img').simulate('click')
describe('AdvancedUnfollow Component', () => { const props = { user: 7, unfollowed() {}, } it('should match snapshot', () => { const tree = create( <AdvancedUnfollow {...props} store={mockStore} /> ).toJSON() expect(tree).toMatchSnapshot() }) it('should mock unfollow action when clicked', () => { const wrapper = mount(<AdvancedUnfollow {...props} store={mockStore} />) wrapper.find('PrimaryButton').simulate('click') }) })
describe('Follow Component', () => { const props = { userDetails: { user: 7, username: 'ghalib', firstname: 'Mirza', surname: 'Ghalib', }, followed() {}, } it('should match snapshot', () => { const tree = create(<Follow {...props} store={mockStore} />).toJSON() expect(tree).toMatchSnapshot() }) it('should mock follow action when clicked', () => { const wrapper = mount(<Follow {...props} store={mockStore} />) wrapper.find('PrimaryButton').simulate('click') }) })
describe('AdvancedFollow Component', () => { const props = { userDetails: { user: 7, username: 'ghalib', firstname: 'Mirza', surname: 'Ghalib', }, followed() {}, } it('should match snapshot', () => { const tree = create( <AdvancedFollow {...props} store={mockStore} /> ).toJSON() expect(tree).toMatchSnapshot() }) it('should mock follow action when clicked', () => { const wrapper = mount(<AdvancedFollow {...props} store={mockStore} />) wrapper.find('PrimaryButton').simulate('click') }) })