From f920951f581b37a56dbce0cb49b64c44772caf8b Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Wed, 2 Oct 2024 14:06:36 +0100 Subject: [PATCH] Require agreement to the Code of Conduct Refs #1973 --- integration/writing-feedback.spec.ts | 21 +++++-- src/Feedback/Evolve.ts | 20 ++++-- src/WriteFeedbackFlow/CheckPage/CheckPage.ts | 2 +- src/WriteFeedbackFlow/DecideNextPage.ts | 44 ++++++++++++- .../EnterFeedbackPage/EnterFeedbackForm.ts | 2 +- test/Feedback/Feedback.test.ts | 17 ++++- test/Feedback/Queries.test.ts | 25 ++++++++ test/WriteFeedbackFlow/DecideNextPage.test.ts | 62 ++++++++++++++++--- test/fc.ts | 10 ++- 9 files changed, 181 insertions(+), 22 deletions(-) diff --git a/integration/writing-feedback.spec.ts b/integration/writing-feedback.spec.ts index 677262487..e4a7c5448 100644 --- a/integration/writing-feedback.spec.ts +++ b/integration/writing-feedback.spec.ts @@ -1,6 +1,5 @@ import { Doi } from 'doi-ts' import { Orcid } from 'orcid-id-ts' -import path from 'path' import { URL } from 'url' import { type Record, RecordC, RecordsC } from 'zenodo-ts' import { areLoggedIn, canLogIn, canWriteFeedback, expect, test, willPublishFeedback } from './base.js' @@ -90,6 +89,8 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback).extend(willPu await (javaScriptEnabled ? page.keyboard.press('Control+b') : page.keyboard.type('')) await page.keyboard.type('.') await page.getByRole('button', { name: 'Save and continue' }).click() + await page.getByLabel('I’m following the Code of Conduct').check() + await page.getByRole('button', { name: 'Save and continue' }).click() await page.getByRole('button', { name: 'Publish feedback' }).click() await expect(page.getByRole('heading', { level: 1 })).toHaveText('We’re publishing your feedback') @@ -185,6 +186,8 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback)( await page.waitForLoadState() await page.getByLabel('Write your feedback').fill('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') await page.getByRole('button', { name: 'Save and continue' }).click() + await page.getByLabel('I’m following the Code of Conduct').check() + await page.getByRole('button', { name: 'Save and continue' }).click() await expect(page.getByRole('region', { name: 'Your feedback' })).toContainText( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', @@ -287,7 +290,7 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback)( await page.getByRole('button', { name: 'Continue' }).click() - await expect(page.getByRole('heading', { level: 1 })).toHaveText('Check your feedback') + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Code of Conduct') }, ) @@ -366,11 +369,17 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback)( await page.waitForLoadState() await page.getByLabel('Write your feedback').fill('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') await page.getByRole('button', { name: 'Save and continue' }).click() + await page.getByLabel('I’m following the Code of Conduct').check() + await page.getByRole('button', { name: 'Save and continue' }).click() await expect(page.getByRole('heading', { level: 1 })).toContainText('Check your feedback') await page.goBack() + await expect(page.getByLabel('I’m following the Code of Conduct')).toBeChecked() + + await page.goBack() + if (javaScriptEnabled) { await expect(page.getByLabel('Write your feedback')).toHaveText( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', @@ -462,11 +471,17 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback)( await page.waitForLoadState() await page.getByLabel('Write your feedback').fill('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') await page.getByRole('button', { name: 'Save and continue' }).click() + await page.getByLabel('I’m following the Code of Conduct').check() + await page.getByRole('button', { name: 'Save and continue' }).click() await expect(page.getByRole('heading', { level: 1 })).toContainText('Check your feedback') await page.getByRole('navigation').getByRole('link', { name: 'Back' }).click() + await expect(page.getByLabel('I’m following the Code of Conduct')).toBeChecked() + + await page.getByRole('navigation').getByRole('link', { name: 'Back' }).click() + if (javaScriptEnabled) { await expect(page.getByLabel('Write your feedback')).toHaveText( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', @@ -642,8 +657,6 @@ test.extend(canLogIn).extend(areLoggedIn).extend(canWriteFeedback)( await page.waitForLoadState() await page.getByLabel('Write your feedback').fill('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') await page.getByRole('button', { name: 'Save and continue' }).click() - await page.goto(`${path.dirname(page.url())}/code-of-conduct`) - await page.getByLabel('I’m following the Code of Conduct').uncheck() await page.getByRole('button', { name: 'Save and continue' }).click() diff --git a/src/Feedback/Evolve.ts b/src/Feedback/Evolve.ts index 4bd88d090..5b69849bd 100644 --- a/src/Feedback/Evolve.ts +++ b/src/Feedback/Evolve.ts @@ -20,10 +20,7 @@ const onFeedbackWasEntered = (event: Events.FeedbackWasEntered) => flow( Match.value, Match.tag('FeedbackNotStarted', identity), - Match.tag( - 'FeedbackInProgress', - state => new State.FeedbackReadyForPublishing({ ...state, feedback: event.feedback }), - ), + Match.tag('FeedbackInProgress', state => new State.FeedbackInProgress({ ...state, feedback: event.feedback })), Match.tag( 'FeedbackReadyForPublishing', state => new State.FeedbackReadyForPublishing({ ...state, feedback: event.feedback }), @@ -82,4 +79,19 @@ export const EvolveFeedback = (state: State.FeedbackState): ((event: Events.Feed Match.tag('FeedbackWasPublished', onFeedbackWasPublished), Match.exhaustive, Function.apply(state), + checkIsReadyForPublication, ) + +const checkIsReadyForPublication = (state: State.FeedbackState) => { + if (state._tag !== 'FeedbackInProgress') { + return state + } + + const { codeOfConductAgreed, feedback, ...rest } = state + + if (typeof feedback !== 'object' || codeOfConductAgreed !== true) { + return state + } + + return new State.FeedbackReadyForPublishing({ ...rest, feedback }) +} diff --git a/src/WriteFeedbackFlow/CheckPage/CheckPage.ts b/src/WriteFeedbackFlow/CheckPage/CheckPage.ts index eea53a9b6..7f91b248d 100644 --- a/src/WriteFeedbackFlow/CheckPage/CheckPage.ts +++ b/src/WriteFeedbackFlow/CheckPage/CheckPage.ts @@ -15,7 +15,7 @@ export const CheckPage = ({ }) => StreamlinePageResponse({ title: plainText(translate(locale, 'write-feedback-flow', 'checkTitle')()), - nav: html` ${translate(locale, 'write-feedback-flow', 'back')()}`, main: html` diff --git a/src/WriteFeedbackFlow/DecideNextPage.ts b/src/WriteFeedbackFlow/DecideNextPage.ts index aab10a64f..540d71fbe 100644 --- a/src/WriteFeedbackFlow/DecideNextPage.ts +++ b/src/WriteFeedbackFlow/DecideNextPage.ts @@ -3,16 +3,54 @@ import type * as Feedback from '../Feedback/index.js' import * as Routes from '../routes.js' import type { Uuid } from '../types/index.js' +const onInProgressState = pipe( + Match.type(), + Match.withReturnType>(), + Match.when( + state => typeof state.feedback === 'undefined', + () => Routes.WriteFeedbackEnterFeedback, + ), + Match.when( + state => typeof state.codeOfConductAgreed === 'undefined', + () => Routes.WriteFeedbackCodeOfConduct, + ), + Match.orElse(() => Routes.WriteFeedbackCheck), +) + export const NextPageFromState = pipe( Match.type>(), Match.withReturnType>(), - Match.tag('FeedbackInProgress', () => Routes.WriteFeedbackEnterFeedback), + Match.tag('FeedbackInProgress', onInProgressState), Match.tag('FeedbackReadyForPublishing', () => Routes.WriteFeedbackCheck), Match.tag('FeedbackBeingPublished', () => Routes.WriteFeedbackPublishing), Match.tag('FeedbackPublished', () => Routes.WriteFeedbackPublished), Match.exhaustive, ) +const onInProgressCommand = pipe( + Match.type<{ + command: (Feedback.EnterFeedback | Feedback.AgreeToCodeOfConduct)['_tag'] + feedback: Feedback.FeedbackState + }>(), + Match.withReturnType>(), + Match.when( + { + command: command => command !== 'EnterFeedback', + feedback: feedback => feedback._tag === 'FeedbackInProgress' && typeof feedback.feedback === 'undefined', + }, + () => Routes.WriteFeedbackEnterFeedback, + ), + Match.when( + { + command: command => command !== 'AgreeToCodeOfConduct', + feedback: feedback => + feedback._tag === 'FeedbackInProgress' && typeof feedback.codeOfConductAgreed === 'undefined', + }, + () => Routes.WriteFeedbackCodeOfConduct, + ), + Match.orElse(() => Routes.WriteFeedbackCheck), +) + export const NextPageAfterCommand = pipe( Match.type<{ command: Exclude['_tag'] @@ -20,8 +58,8 @@ export const NextPageAfterCommand = pipe( }>(), Match.withReturnType>(), Match.when({ command: 'StartFeedback' }, () => Routes.WriteFeedbackEnterFeedback), - Match.when({ command: 'EnterFeedback' }, () => Routes.WriteFeedbackCheck), - Match.when({ command: 'AgreeToCodeOfConduct' }, () => Routes.WriteFeedbackCheck), + Match.when({ command: 'EnterFeedback' }, onInProgressCommand), + Match.when({ command: 'AgreeToCodeOfConduct' }, onInProgressCommand), Match.when({ command: 'PublishFeedback' }, () => Routes.WriteFeedbackPublishing), Match.exhaustive, ) diff --git a/src/WriteFeedbackFlow/EnterFeedbackPage/EnterFeedbackForm.ts b/src/WriteFeedbackFlow/EnterFeedbackPage/EnterFeedbackForm.ts index f2827e8a7..990f6a41e 100644 --- a/src/WriteFeedbackFlow/EnterFeedbackPage/EnterFeedbackForm.ts +++ b/src/WriteFeedbackFlow/EnterFeedbackPage/EnterFeedbackForm.ts @@ -30,7 +30,7 @@ export const fromBody = (body: unknown) => export const fromFeedback = pipe( Match.type(), - Match.tag('FeedbackInProgress', () => new EmptyForm()), + Match.tag('FeedbackInProgress', ({ feedback }) => (feedback ? new CompletedForm({ feedback }) : new EmptyForm())), Match.tag('FeedbackReadyForPublishing', ({ feedback }) => new CompletedForm({ feedback })), Match.exhaustive, ) diff --git a/test/Feedback/Feedback.test.ts b/test/Feedback/Feedback.test.ts index 4df729cbe..a1c92dce2 100644 --- a/test/Feedback/Feedback.test.ts +++ b/test/Feedback/Feedback.test.ts @@ -71,6 +71,7 @@ describe('when ready for publication', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), ) .when(new _.StartFeedback({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') })) .thenError(new _.FeedbackWasAlreadyStarted())) @@ -79,6 +80,7 @@ describe('when ready for publication', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), ) .when(new _.EnterFeedback({ feedback: html`

Some different feedback.

` })) .then(new _.FeedbackWasEntered({ feedback: html`

Some different feedback.

` }))) @@ -87,6 +89,7 @@ describe('when ready for publication', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), ) .when(new _.AgreeToCodeOfConduct()) .then()) @@ -95,6 +98,7 @@ describe('when ready for publication', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), ) .when(new _.PublishFeedback()) .then(new _.FeedbackPublicationWasRequested())) @@ -103,6 +107,7 @@ describe('when ready for publication', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), ) .when(new _.MarkFeedbackAsPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') })) .then(new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }))) @@ -113,6 +118,7 @@ describe('when being published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackPublicationWasRequested(), ) .when(new _.StartFeedback({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') })) @@ -122,6 +128,7 @@ describe('when being published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackPublicationWasRequested(), ) .when(new _.EnterFeedback({ feedback: html`

Some different feedback.

` })) @@ -131,6 +138,7 @@ describe('when being published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackPublicationWasRequested(), ) .when(new _.AgreeToCodeOfConduct()) @@ -140,6 +148,7 @@ describe('when being published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackPublicationWasRequested(), ) .when(new _.PublishFeedback()) @@ -149,6 +158,7 @@ describe('when being published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackPublicationWasRequested(), ) .when(new _.MarkFeedbackAsPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') })) @@ -160,6 +170,7 @@ describe('when published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }), ) .when(new _.StartFeedback({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') })) @@ -169,15 +180,17 @@ describe('when published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }), ) .when(new _.EnterFeedback({ feedback: html`

Some different feedback.

` })) .thenError(new _.FeedbackWasAlreadyPublished())) - test('cannot agree to the code of conduct', () => + test('cannot re-agree to the code of conduct', () => given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }), ) .when(new _.AgreeToCodeOfConduct()) @@ -187,6 +200,7 @@ describe('when published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }), ) .when(new _.PublishFeedback()) @@ -196,6 +210,7 @@ describe('when published', () => { given( new _.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), new _.FeedbackWasEntered({ feedback: html`

Some feedback.

` }), + new _.CodeOfConductWasAgreed(), new _.FeedbackWasPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') }), ) .when(new _.MarkFeedbackAsPublished({ id: 107286, doi: Doi('10.5072/zenodo.107286') })) diff --git a/test/Feedback/Queries.test.ts b/test/Feedback/Queries.test.ts index 9f1f0b4c7..f7eb88312 100644 --- a/test/Feedback/Queries.test.ts +++ b/test/Feedback/Queries.test.ts @@ -14,6 +14,14 @@ describe('GetAllUnpublishedFeedbackByAnAuthorForAPrereview', () => { event: new Feedback.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), resourceId: '358f7fc0-9725-4192-8673-d7c64f398401' as Uuid.Uuid, }, + { + event: new Feedback.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), + resourceId: '51a9ea9e-a960-4b51-83a5-9901a47690c2' as Uuid.Uuid, + }, + { + event: new Feedback.FeedbackWasEntered({ feedback: html`Some text` }), + resourceId: '51a9ea9e-a960-4b51-83a5-9901a47690c2' as Uuid.Uuid, + }, { event: new Feedback.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, @@ -22,6 +30,10 @@ describe('GetAllUnpublishedFeedbackByAnAuthorForAPrereview', () => { event: new Feedback.FeedbackWasEntered({ feedback: html`Some text` }), resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, }, + { + event: new Feedback.CodeOfConductWasAgreed(), + resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, + }, { event: new Feedback.FeedbackWasStarted({ prereviewId: 123, authorId: Orcid('0000-0002-1825-0097') }), resourceId: 'eb8146ea-e643-4ca3-9dc1-2f26013c42b0' as Uuid.Uuid, @@ -30,6 +42,10 @@ describe('GetAllUnpublishedFeedbackByAnAuthorForAPrereview', () => { event: new Feedback.FeedbackWasEntered({ feedback: html`Some other text` }), resourceId: 'eb8146ea-e643-4ca3-9dc1-2f26013c42b0' as Uuid.Uuid, }, + { + event: new Feedback.CodeOfConductWasAgreed(), + resourceId: 'eb8146ea-e643-4ca3-9dc1-2f26013c42b0' as Uuid.Uuid, + }, { event: new Feedback.FeedbackPublicationWasRequested(), resourceId: 'eb8146ea-e643-4ca3-9dc1-2f26013c42b0' as Uuid.Uuid, @@ -46,6 +62,11 @@ describe('GetAllUnpublishedFeedbackByAnAuthorForAPrereview', () => { authorId: Orcid('0000-0002-1825-0097'), prereviewId: 123, }), + '51a9ea9e-a960-4b51-83a5-9901a47690c2': new Feedback.FeedbackInProgress({ + authorId: Orcid('0000-0002-1825-0097'), + feedback: html`Some text`, + prereviewId: 123, + }), '2b9e777b-f14d-4294-8e27-2b442e496050': new Feedback.FeedbackReadyForPublishing({ authorId: Orcid('0000-0002-1825-0097'), feedback: html`Some text`, @@ -123,6 +144,10 @@ describe('GetAllUnpublishedFeedbackByAnAuthorForAPrereview', () => { event: new Feedback.FeedbackWasEntered({ feedback: html`Some text` }), resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, }, + { + event: new Feedback.CodeOfConductWasAgreed(), + resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, + }, { event: new Feedback.FeedbackWasPublished({ id: 456, doi: Doi('10.5072/zenodo.456') }), resourceId: '2b9e777b-f14d-4294-8e27-2b442e496050' as Uuid.Uuid, diff --git a/test/WriteFeedbackFlow/DecideNextPage.test.ts b/test/WriteFeedbackFlow/DecideNextPage.test.ts index eba24fe2f..8120e13d7 100644 --- a/test/WriteFeedbackFlow/DecideNextPage.test.ts +++ b/test/WriteFeedbackFlow/DecideNextPage.test.ts @@ -5,8 +5,17 @@ import * as Routes from '../../src/routes.js' import * as fc from '../fc.js' describe('NextPageFromState', () => { - test.prop([fc.feedbackInProgress()])('FeedbackInProgress', feedback => { - expect(_.NextPageFromState(feedback)).toStrictEqual(Routes.WriteFeedbackEnterFeedback) + describe('FeedbackInProgress', () => { + test.prop([fc.feedbackInProgress({ feedback: fc.constant(undefined) })])('no feedback', feedback => { + expect(_.NextPageFromState(feedback)).toStrictEqual(Routes.WriteFeedbackEnterFeedback) + }) + + test.prop([fc.feedbackInProgress({ feedback: fc.html(), codeOfConductAgreed: fc.constant(undefined) })])( + 'no codeOfConductAgreed', + feedback => { + expect(_.NextPageFromState(feedback)).toStrictEqual(Routes.WriteFeedbackCodeOfConduct) + }, + ) }) test.prop([fc.feedbackReadyForPublishing()])('FeedbackReadyForPublishing', feedback => { @@ -29,13 +38,52 @@ describe('NextPageAfterCommand', () => { ) }) - test.prop([fc.feedbackState()])('EnterFeedback', feedback => { - expect(_.NextPageAfterCommand({ command: 'EnterFeedback', feedback })).toStrictEqual(Routes.WriteFeedbackCheck) + describe('EnterFeedback', () => { + describe('FeedbackInProgress', () => { + test.prop([fc.feedbackInProgress({ codeOfConductAgreed: fc.constant(undefined) })])( + 'no codeOfConductAgreed', + feedback => { + expect(_.NextPageAfterCommand({ command: 'EnterFeedback', feedback })).toStrictEqual( + Routes.WriteFeedbackCodeOfConduct, + ) + }, + ) + + test.prop([fc.feedbackInProgress({ codeOfConductAgreed: fc.constant(true) })])('completed', feedback => { + expect(_.NextPageAfterCommand({ command: 'EnterFeedback', feedback })).toStrictEqual(Routes.WriteFeedbackCheck) + }) + }) + + test.prop([fc.feedbackState().filter(feedback => feedback._tag !== 'FeedbackInProgress')])( + 'not FeedbackInProgress', + feedback => { + expect(_.NextPageAfterCommand({ command: 'EnterFeedback', feedback })).toStrictEqual(Routes.WriteFeedbackCheck) + }, + ) }) - test.prop([fc.feedbackState()])('AgreeToCodeOfConduct', feedback => { - expect(_.NextPageAfterCommand({ command: 'AgreeToCodeOfConduct', feedback })).toStrictEqual( - Routes.WriteFeedbackCheck, + describe('AgreeToCodeOfConduct', () => { + describe('FeedbackInProgress', () => { + test.prop([fc.feedbackInProgress({ feedback: fc.constant(undefined) })])('no feedback', feedback => { + expect(_.NextPageAfterCommand({ command: 'AgreeToCodeOfConduct', feedback })).toStrictEqual( + Routes.WriteFeedbackEnterFeedback, + ) + }) + + test.prop([fc.feedbackInProgress({ feedback: fc.html() })])('completed', feedback => { + expect(_.NextPageAfterCommand({ command: 'AgreeToCodeOfConduct', feedback })).toStrictEqual( + Routes.WriteFeedbackCheck, + ) + }) + }) + + test.prop([fc.feedbackState().filter(feedback => feedback._tag !== 'FeedbackInProgress')])( + 'not FeedbackInProgress', + feedback => { + expect(_.NextPageAfterCommand({ command: 'AgreeToCodeOfConduct', feedback })).toStrictEqual( + Routes.WriteFeedbackCheck, + ) + }, ) }) diff --git a/test/fc.ts b/test/fc.ts index 51fb518bd..2c8ec9edd 100644 --- a/test/fc.ts +++ b/test/fc.ts @@ -1307,11 +1307,19 @@ export const feedbackError = (): fc.Arbitrary => export const feedbackNotStarted = (): fc.Arbitrary => constant(new Feedback.FeedbackNotStarted()) -export const feedbackInProgress = (): fc.Arbitrary => +export const feedbackInProgress = ({ + codeOfConductAgreed, + feedback, +}: { + codeOfConductAgreed?: fc.Arbitrary + feedback?: fc.Arbitrary +} = {}): fc.Arbitrary => fc .record({ authorId: orcid(), prereviewId: fc.integer(), + feedback: feedback ?? fc.option(html(), { nil: undefined }), + codeOfConductAgreed: codeOfConductAgreed ?? constantFrom(true, undefined), }) .map(data => new Feedback.FeedbackInProgress(data))