|
| 1 | +/* eslint-disable import/first */ |
1 | 2 | import { render, cleanup, fireEvent, configure } from '@testing-library/react'
|
2 | 3 | import theme from '@elifesciences/elife-theme'
|
3 | 4 | import React from 'react'
|
4 | 5 | import 'jest-dom/extend-expect'
|
5 | 6 | import flushPromises from 'flush-promises'
|
| 7 | +import config from 'config' |
6 | 8 | import { ThemeProvider } from 'styled-components'
|
7 | 9 | import { MemoryRouter } from 'react-router-dom'
|
8 | 10 | import { MockedProvider } from 'react-apollo/test-utils'
|
@@ -31,16 +33,17 @@ const setupProvider = (historyLocation = []) => ({ children }) => (
|
31 | 33 | </ThemeProvider>
|
32 | 34 | )
|
33 | 35 |
|
34 |
| -const makeProps = (path, pushHistory = jest.fn()) => ({ |
| 36 | +const makeProps = (path, pushHistory = jest.fn(), props) => ({ |
35 | 37 | data: { manuscript: { meta: {} } },
|
36 | 38 | match: { path: '/submit/id', url: '', params: { id: 'id' } },
|
37 | 39 | history: { location: { pathname: path }, push: pushHistory },
|
38 | 40 | updateManuscript: jest.fn(),
|
39 | 41 | submitManuscript: jest.fn(),
|
| 42 | + ...props, |
40 | 43 | })
|
41 | 44 |
|
42 |
| -const renderWithPath = (path, pushHistory) => |
43 |
| - render(<SubmissionWizard {...makeProps(path, pushHistory)} />, { |
| 45 | +const renderWithPath = (path, pushHistory, props = {}) => |
| 46 | + render(<SubmissionWizard {...makeProps(path, pushHistory, props)} />, { |
44 | 47 | wrapper: setupProvider([path]),
|
45 | 48 | })
|
46 | 49 |
|
@@ -90,6 +93,55 @@ describe('SubmissionWizard', async () => {
|
90 | 93 | ).toBeTruthy()
|
91 | 94 | })
|
92 | 95 |
|
| 96 | + describe('submit', () => { |
| 97 | + describe('survey feature flag', () => { |
| 98 | + const path = '/submit/id/disclosure' |
| 99 | + const submitManuscript = jest.fn() |
| 100 | + const pushHistory = jest.fn() |
| 101 | + const originalFeatures = { ...config.features } |
| 102 | + |
| 103 | + afterEach(() => { |
| 104 | + config.features = originalFeatures |
| 105 | + submitManuscript.mockReset() |
| 106 | + pushHistory.mockReset() |
| 107 | + }) |
| 108 | + |
| 109 | + it('should redirect to thank you if survey flag is off', async () => { |
| 110 | + config.features.demographicSurvey = false |
| 111 | + const { getByTestId, getByText } = renderWithPath(path, pushHistory, { |
| 112 | + submitManuscript, |
| 113 | + }) |
| 114 | + |
| 115 | + fireEvent.click(getByTestId('submit')) |
| 116 | + await flushPromises() |
| 117 | + |
| 118 | + fireEvent.click(getByText('Confirm')) |
| 119 | + await flushPromises() |
| 120 | + |
| 121 | + expect(submitManuscript).toHaveBeenCalledTimes(1) |
| 122 | + expect(pushHistory).toHaveBeenCalledTimes(1) |
| 123 | + expect(pushHistory).toHaveBeenCalledWith('/thankyou/id') |
| 124 | + }) |
| 125 | + |
| 126 | + it('should redirect to survey page if survey flag is on', async () => { |
| 127 | + config.features.demographicSurvey = true |
| 128 | + const { getByTestId, getByText } = renderWithPath(path, pushHistory, { |
| 129 | + submitManuscript, |
| 130 | + }) |
| 131 | + |
| 132 | + fireEvent.click(getByTestId('submit')) |
| 133 | + await flushPromises() |
| 134 | + |
| 135 | + fireEvent.click(getByText('Confirm')) |
| 136 | + await flushPromises() |
| 137 | + |
| 138 | + expect(submitManuscript).toHaveBeenCalledTimes(1) |
| 139 | + expect(pushHistory).toHaveBeenCalledTimes(1) |
| 140 | + expect(pushHistory).toHaveBeenCalledWith('/survey/id') |
| 141 | + }) |
| 142 | + }) |
| 143 | + }) |
| 144 | + |
93 | 145 | describe('step navigation', () => {
|
94 | 146 | // eslint-disable-next-line no-console
|
95 | 147 | const consoleError = console.error
|
|
0 commit comments