it('should submit appState', () => { const fuelSavings = getFuelSavings(); const onSaveClick = jest.fn(); const wrapper = shallow(<FuelSavingsForm onSaveClick={onSaveClick} onChange={jest.fn()} fuelSavings={fuelSavings} />); expect(onSaveClick).not.toBeCalled(); wrapper.find('input[type="submit"]').simulate('click'); expect(onSaveClick).toBeCalled(); });
it('should call onChange when text input changes', () => { const onChange = jest.fn(); const wrapper = shallow(<FuelSavingsForm onSaveClick={jest.fn()} onChange={onChange} fuelSavings={getFuelSavings()} />); const changeEvent = { target: { name: 'newMpg', value: '20' } }; expect(onChange).not.toBeCalled(); wrapper.find(FuelSavingsTextInput).first().simulate('change', changeEvent); expect(onChange).toBeCalledWith(changeEvent); });
wrapper.simulate('change', changeEvent); expect(props.onChange).toBeCalledWith(changeEvent); });
it('should call onChange when timeframe changes', () => { const onChange = jest.fn(); const fuelSavings = getFuelSavings(); const wrapper = shallow(<FuelSavingsForm onSaveClick={jest.fn()} onChange={onChange} fuelSavings={fuelSavings} />); const changeEvent = { target: { name: 'timeframe', value: 'year' } }; expect(onChange).not.toBeCalled(); wrapper.find('select').simulate('change', changeEvent); expect(onChange).toBeCalledWith(changeEvent); });
it('should handle save button click', () => { const onSaveClick = jest.fn(); const wrapper = shallow(<FuelSavingsForm onSaveClick={onSaveClick} onChange={jest.fn()} fuelSavings={getFuelSavings()} />); expect(onSaveClick).not.toBeCalled(); wrapper.find('input[type="submit"]').simulate('click'); expect(onSaveClick).toBeCalled(); });
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('GroupTopOptions Component', () => { MockDataElement() it('should match snapshot', () => { const tree = create(<GroupTopOptions />).toJSON() expect(tree).toMatchSnapshot() }) it('should show options when icon is clicked', () => { const wraper = shallow(<GroupTopOptions />) wraper.find('.pro_more_horiz').simulate('click') expect(wraper.find('.pro_banner_options').exists()).toBe(true) }) })
describe('ChangePassword Component', () => { it('should match snapshot', () => { const tree = create( <Provider store={mockStore}> <ChangePassword /> </Provider> ).toJSON() expect(tree).toMatchSnapshot() }) it('should mock changePassword action when clicked on Primary btn', () => { const wrapper = shallow(<ChangePassword />) wrapper.find('PrimaryButton').simulate('click', { preventDefault() {} }) }) })
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('End Component', () => { it('should match snapshot', () => { const tree = create(<End />).toJSON() expect(tree).toMatchSnapshot() }) it('should scroll the page to top when clicked', () => { let wrapper = shallow(<End />) wrapper.find('span').simulate('click') expect(window.pageYOffset).toEqual(0) }) })
describe('CommentTypeImage Component', () => { const comp = ( <CommentTypeImage commentSrc="instagram_comment_1518972851259.jpg" /> ) it('should match snapshot', () => { const tree = create(comp).toJSON() expect(tree).toMatchSnapshot() }) it('should show <ImageTheatre/> when clicked on image', () => { const wrapper = shallow(comp) wrapper.find('.comments_img').simulate('click') expect(wrapper.find('ImageTheatre').exists()).toBe(true) }) })
describe('ConversationAddEmojis Component', () => { const props = { updateMssgValue: jest.fn(), } it('should match snapshot', () => { const tree = create(<ConversationAddEmojis {...props} />).toJSON() expect(tree).toMatchSnapshot() }) it('should match snapshot and show <Emojis/> when clicked on emojis icon', () => { const wrapper = shallow(<ConversationAddEmojis {...props} />) wrapper.find('.mssg_emoji_btn').simulate('click') expect(wrapper.find('Emojis').exists()).toBe(true) }) })
describe('BannerTopOptions Component', () => { it('should match snapshot', () => { const tree = create(<BannerTopOptions />).toJSON() expect(tree).toMatchSnapshot() }) it('should show options when icon is clicked', () => { const wraper = shallow(<BannerTopOptions />) wraper.find('.pro_more_horiz').simulate('click') expect(wraper.find('.pro_banner_options').exists()).toBe(true) }) })
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) }) })
describe('CreateGroup Component', () => { it('should match snapshot', () => { const tree = create(<CreateGroup />).toJSON() expect(tree).toMatchSnapshot() }) it('should show <CreateGroupModal/> when button is clicked', () => { const wrapper = shallow(<CreateGroup />) wrapper.find('SecondaryButton').simulate('click', { preventDefault() {}, }) expect(wrapper.find('CreateGroupModal').exists()).toBe(true) }) })