Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 03f4f04

Browse files
erezmusdiversemix
authored andcommitted
2298: move redirect to confirm button (#2305)
* 2298: moved redirect to survey on confirmation * refactored tests * removed isPublic from features as it cascades from default * copy config.features and restore them after each test
1 parent 546eb9c commit 03f4f04

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

config/unit-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ module.exports = {
6262
},
6363
},
6464
},
65+
features: {
66+
demographicSurvey: false,
67+
},
6568
}

packages/component-submission/client/pages/SubmissionWizard.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import styled from 'styled-components'
1010
import { th } from '@pubsweet/ui-toolkit'
1111
import { Formik, Form } from 'formik'
1212
import * as yup from 'yup'
13+
import config from 'config'
1314
import {
1415
ErrorPage,
1516
TrackedRoute,
@@ -107,7 +108,13 @@ export const SubmissionWizard = ({
107108
variables: { data: parseFormToOutputData(formValues) },
108109
}),
109110
)
110-
.then(() => history.push(`/thankyou/${match.params.id}`))
111+
.then(() =>
112+
history.push(
113+
config.features && config.features.demographicSurvey
114+
? `/survey/${match.params.id}`
115+
: `/thankyou/${match.params.id}`,
116+
),
117+
)
111118

112119
const navigateToStep = step => {
113120
setCurrentStep(step)

packages/component-submission/client/pages/SubmissionWizard.test.js

+55-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
/* eslint-disable import/first */
12
import { render, cleanup, fireEvent, configure } from '@testing-library/react'
23
import theme from '@elifesciences/elife-theme'
34
import React from 'react'
45
import 'jest-dom/extend-expect'
56
import flushPromises from 'flush-promises'
7+
import config from 'config'
68
import { ThemeProvider } from 'styled-components'
79
import { MemoryRouter } from 'react-router-dom'
810
import { MockedProvider } from 'react-apollo/test-utils'
@@ -31,16 +33,17 @@ const setupProvider = (historyLocation = []) => ({ children }) => (
3133
</ThemeProvider>
3234
)
3335

34-
const makeProps = (path, pushHistory = jest.fn()) => ({
36+
const makeProps = (path, pushHistory = jest.fn(), props) => ({
3537
data: { manuscript: { meta: {} } },
3638
match: { path: '/submit/id', url: '', params: { id: 'id' } },
3739
history: { location: { pathname: path }, push: pushHistory },
3840
updateManuscript: jest.fn(),
3941
submitManuscript: jest.fn(),
42+
...props,
4043
})
4144

42-
const renderWithPath = (path, pushHistory) =>
43-
render(<SubmissionWizard {...makeProps(path, pushHistory)} />, {
45+
const renderWithPath = (path, pushHistory, props = {}) =>
46+
render(<SubmissionWizard {...makeProps(path, pushHistory, props)} />, {
4447
wrapper: setupProvider([path]),
4548
})
4649

@@ -90,6 +93,55 @@ describe('SubmissionWizard', async () => {
9093
).toBeTruthy()
9194
})
9295

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+
93145
describe('step navigation', () => {
94146
// eslint-disable-next-line no-console
95147
const consoleError = console.error

packages/component-submission/client/pages/ThankYouPage.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ export class ThankYouPageComponent extends React.Component {
4848
submission.
4949
<BookmarkLink href="/">elifesciences.org/submissions</BookmarkLink>
5050
</Paragraph.Small>
51-
<ButtonLink
52-
data-test-id="finish"
53-
primary
54-
to={
55-
config.features && config.features.demographicSurvey
56-
? `/survey/${data.manuscript.id}`
57-
: '/'
58-
}
59-
>
51+
<ButtonLink data-test-id="finish" primary to="/">
6052
Finish
6153
</ButtonLink>
6254
</CenteredContent>

0 commit comments

Comments
 (0)