describe('SideBarBottom Component', () => { it('should match snapshot', () => { const tree = create(<SidebarBottom />).toJSON() expect(tree).toMatchSnapshot() }) it('should toggle options when clicked', () => { const wrapper = shallow(<SidebarBottom />) wrapper.find('.toggle-sb-options').simulate('click') expect(wrapper.state().showOptions).toBe(true) expect(wrapper.find('SidebarOptions').exists()).toBe(true) }) })
describe('Recommend Component', () => { const comp = <Recommend username="ghalib" /> it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should toggle RecommendUsers modal when clicked on the button', () => { const wrapper = shallow(comp) wrapper.find('SecondaryButton').simulate('click', { preventDefault() {} }) expect(wrapper.state().recommend).toBe(true) expect(wrapper.find('Connect(RecommendUsers)').exists()).toBe(true) }) })
describe('Avatars Component', () => { const mockFn = jest.fn() const comp = <Avatars back={mockFn} of="user" group={1} /> mockAxiosRequest('get-avatars', avatarsMockArray) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should call componentDidMount and get avatars', async () => { const wrapper = shallow(comp) await wrapper.instance().componentDidMount() expect(wrapper.state().avatars).toBeArrayOfSize(4) expect(wrapper.state().avatars).toIncludeAnyMembers([avatars[0]]) }) it('should simulate click event for closing the modal', () => { const wrapper = shallow(comp) wrapper.find('.pro_ava_close').simulate('click') }) })
expect(wrapper.state().search.users).toBeArrayOfSize(1) expect(wrapper.state().search.users[0]).toEqual(searchData.users[0]) expect(wrapper.state().search.groups).toBeArrayOfSize(0) expect(wrapper.state().search.hashtags).toBeArrayOfSize(0) expect(wrapper.state().search.users).toBeArrayOfSize(0) expect(wrapper.state().search.groups).toBeArrayOfSize(0) expect(wrapper.state().search.hashtags).toBeArrayOfSize(1) expect(wrapper.state().search.hashtags[0]).toEqual(searchData.hashtags[1]) expect(wrapper.state().search.users).toBeArrayOfSize(0) expect(wrapper.state().search.groups).toBeArrayOfSize(0) expect(wrapper.state().search.hashtags).toBeArrayOfSize(0) }) })
describe('PostBottom Component', () => { const postDetails = { comments_count: 2, post_id: 44, when: 'feed', user: 7, comments: [], } it('should match snapshot', () => { const tree = create( <Provider store={mockStore}> <PostBottom postDetails={postDetails} /> </Provider> ).toJSON() expect(tree).toMatchSnapshot() }) it('should increments comments count', () => { const wrapper = shallow(<PurePostBottom postDetails={postDetails} />) expect(wrapper.state().comments_count).toBe(2) wrapper.instance().incrementComments() expect(wrapper.state().comments_count).toBe(3) }) })
const wrapper = shallow(<AddEmojis {...props} />) expect(wrapper.state().showEmojis).toBeFalse() expect(wrapper.find('Emojis').exists()).toBeFalse()
describe('PostTags Component', () => { const props = { post_id: 11, tags_count: 1, } it('should match snapshot', () => { const tree = create(<PostTags {...props} />).toJSON() expect(tree).toMatchSnapshot() }) it('should match snapshot with null when tags_count == 0', () => { const tree = create(<PostTags post_id={11} tags_count={0} />).toJSON() expect(tree).toMatchSnapshot() }) it('should show <Tags/> when showTags == true', () => { const wrapper = shallow(<PostTags {...props} />) wrapper.setState({ showTags: true }) expect(wrapper.find('Connect(Tags)').exists()).toBe(true) }) it('should decrement tags_count', () => { const wrapper = shallow(<PostTags {...props} />) expect(wrapper.state().tags_count).toBe(1) wrapper.instance().decrementTags() expect(wrapper.state().tags_count).toBe(0) }) })
const wrapper = shallow(comp) await wrapper.instance().componentDidMount() expect(wrapper.state().data).toBeArray() expect(wrapper.state().data[0]).toContainKeys([ 'follow_to', 'follow_to_username', expect(wrapper.state().followings).toBeArrayOfSize(1) expect(wrapper.state().followings[0]).toContainEntries([ ['follow_to', 8], ['follow_to_username', 'coldplay'], expect(wrapper.state().followings).toBeArrayOfSize(1) expect(wrapper.state().followings[0]).toContainEntries([ ['follow_to', 7], ['follow_to_username', 'ghalib'], expect(wrapper.state().followings).toBeArrayOfSize(0) }) })
expect(wrapper.state()).toContainEntries([ ['likes_count', 1], ['shares_count', 1], wrapper.instance().incrementWhat('likes_count') wrapper.instance().incrementWhat('shares_count') expect(wrapper.state()).toContainEntries([ ['likes_count', 2], ['shares_count', 2], expect(wrapper.state()).toContainEntries([ ['likes_count', 1], ['shares_count', 1], wrapper.instance().decrementWhat('likes_count') wrapper.instance().decrementWhat('shares_count') expect(wrapper.state()).toContainEntries([ ['likes_count', 0], ['shares_count', 0],
describe('OnlineUsersButton Component', () => { it('should match snapshot', () => { const tree = create(<OnlineUsersButton />).toJSON() expect(tree).toMatchSnapshot() }) it('should show <OnlineUsers/> when clicked on PrimaryButton', () => { const wrapper = shallow(<OnlineUsersButton />) wrapper.find('PrimaryButton').simulate('click', { preventDefault() {}, }) expect(wrapper.state('showOnlineUsers')).toBe(true) expect(wrapper.find('Connect(OnlineUsers)').exists()).toBe(true) }) })
it('should set initial drag state on mousedown', () => { const wrapper = shallow( <DragGroup offsetX={0} offsetY={0}> <div /> </DragGroup> ); wrapper.find('.drag-target').simulate('mousedown', {clientX: 5, clientY: 6}); expect(wrapper.state('isDragging')).to.equal(true); expect(wrapper.state('origin')).to.deep.equal({x: 5, y: 6}); });
it('should set initial drag state on mousedown', () => { const wrapper = shallow( <DragGroup offsetX={0} offsetY={0}> <div /> </DragGroup> ); wrapper.find('.drag-target').simulate('mousedown', {clientX: 5, clientY: 6}); expect(wrapper.state('isDragging')).to.equal(true); expect(wrapper.state('origin')).to.deep.equal({x: 5, y: 6}); });