Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { expect } from 'chai';
- import { shallow } from 'enzyme';
- import { spy, stub } from 'sinon';
- import { practiceJobFixtures } from '../../../../../__tests__/fixtures';
- import { ConfirmationModal } from '../../../../../shared/confirmationModal';
- import { Button } from '../../../../../shared/button';
- import { EndStep } from '../endStep.component';
- describe('<EndStep />', () => {
- const defaultProps = {
- job: practiceJobFixtures.unlistedJobListItems.first(),
- publishJob: Function.prototype,
- history: { push: Function.prototype },
- };
- const component = (props) => (
- <EndStep {...defaultProps} {...props} />
- );
- const render = (props = {}) => shallow(component(props));
- it('should render correctly when job is in unlisted state', () => {
- const wrapper = render();
- global.expect(wrapper).toMatchSnapshot();
- });
- it('should not render when job is not in unlisted state', () => {
- const props = {
- job: practiceJobFixtures.draftJobListItems.first(),
- };
- const wrapper = shallow(component(props));
- global.expect(wrapper).toMatchSnapshot();
- });
- it('should open confirmation popup when publish button is clicked', () => {
- const publishJob = stub().resolves(true);
- const props = {
- publishJob,
- };
- const wrapper = shallow(component(props));
- wrapper.setState({ redactionRecommended: false });
- const publishButton = wrapper.find(Button).last();
- publishButton.simulate('click');
- global.expect(wrapper.find(ConfirmationModal).dive()).toMatchSnapshot();
- });
- it('should publish job when publish button is clicked and it is confirmed', async () => {
- const publishJob = stub().resolves(true);
- const props = {
- publishJob,
- };
- const wrapper = shallow(component(props));
- const publishButton = wrapper.find(Button).last();
- publishButton.simulate('click');
- await wrapper.find(ConfirmationModal).props().onYesAction();
- expect(publishJob).to.have.been.called;
- });
- it('should redirect to listed jobs after publishing job', async () => {
- const history = { push: spy() };
- const publishJob = stub().resolves();
- const props = {
- publishJob,
- history,
- };
- const wrapper = shallow(component(props));
- const publishButton = wrapper.find(Button).last();
- publishButton.simulate('click');
- await wrapper.find(ConfirmationModal).props().onYesAction();
- expect(history.push).to.have.been.calledWith('/jobs/list/listed');
- });
- it('should redirect to listed jobs after clicking list job later', async () => {
- const history = { push: spy() };
- const props = {
- history,
- };
- const wrapper = shallow(component(props));
- const publishLaterButton = wrapper.find(Button).first();
- publishLaterButton.simulate('click');
- expect(history.push).to.have.been.calledWith('/jobs/list/unlisted');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement