Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { expect } from 'chai';
  3. import { shallow } from 'enzyme';
  4. import { spy, stub } from 'sinon';
  5.  
  6. import { practiceJobFixtures } from '../../../../../__tests__/fixtures';
  7. import { ConfirmationModal } from '../../../../../shared/confirmationModal';
  8. import { Button } from '../../../../../shared/button';
  9. import { EndStep } from '../endStep.component';
  10.  
  11. describe('<EndStep />', () => {
  12.   const defaultProps = {
  13.     job: practiceJobFixtures.unlistedJobListItems.first(),
  14.     publishJob: Function.prototype,
  15.     history: { push: Function.prototype },
  16.   };
  17.  
  18.   const component = (props) => (
  19.     <EndStep {...defaultProps} {...props} />
  20.   );
  21.  
  22.   const render = (props = {}) => shallow(component(props));
  23.  
  24.   it('should render correctly when job is in unlisted state', () => {
  25.     const wrapper = render();
  26.  
  27.     global.expect(wrapper).toMatchSnapshot();
  28.   });
  29.  
  30.   it('should not render when job is not in unlisted state', () => {
  31.     const props = {
  32.       job: practiceJobFixtures.draftJobListItems.first(),
  33.     };
  34.     const wrapper = shallow(component(props));
  35.  
  36.     global.expect(wrapper).toMatchSnapshot();
  37.   });
  38.  
  39.   it('should open confirmation popup when publish button is clicked', () => {
  40.     const publishJob = stub().resolves(true);
  41.     const props = {
  42.       publishJob,
  43.     };
  44.     const wrapper = shallow(component(props));
  45.     wrapper.setState({ redactionRecommended: false });
  46.     const publishButton = wrapper.find(Button).last();
  47.     publishButton.simulate('click');
  48.  
  49.     global.expect(wrapper.find(ConfirmationModal).dive()).toMatchSnapshot();
  50.   });
  51.  
  52.   it('should publish job when publish button is clicked and it is confirmed', async () => {
  53.     const publishJob = stub().resolves(true);
  54.     const props = {
  55.       publishJob,
  56.     };
  57.     const wrapper = shallow(component(props));
  58.     const publishButton = wrapper.find(Button).last();
  59.     publishButton.simulate('click');
  60.  
  61.     await wrapper.find(ConfirmationModal).props().onYesAction();
  62.  
  63.     expect(publishJob).to.have.been.called;
  64.   });
  65.  
  66.   it('should redirect to listed jobs after publishing job', async () => {
  67.     const history = { push: spy() };
  68.     const publishJob = stub().resolves();
  69.     const props = {
  70.       publishJob,
  71.       history,
  72.     };
  73.     const wrapper = shallow(component(props));
  74.     const publishButton = wrapper.find(Button).last();
  75.     publishButton.simulate('click');
  76.  
  77.     await wrapper.find(ConfirmationModal).props().onYesAction();
  78.  
  79.     expect(history.push).to.have.been.calledWith('/jobs/list/listed');
  80.   });
  81.  
  82.   it('should redirect to listed jobs after clicking list job later', async () => {
  83.     const history = { push: spy() };
  84.     const props = {
  85.       history,
  86.     };
  87.     const wrapper = shallow(component(props));
  88.     const publishLaterButton = wrapper.find(Button).first();
  89.     publishLaterButton.simulate('click');
  90.  
  91.     expect(history.push).to.have.been.calledWith('/jobs/list/unlisted');
  92.   });
  93. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement