Skip to content

Commit

Permalink
Get ready to extract write-review/add-authors-form strings
Browse files Browse the repository at this point in the history
Refs: #1817
  • Loading branch information
erkannt committed Oct 17, 2024
1 parent 004b309 commit 5d2981b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/write-review/add-authors-page/add-authors-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Status } from 'hyper-ts'
import { match } from 'ts-pattern'
import { type MissingE, hasAnError } from '../../form.js'
import { html, plainText, rawHtml } from '../../html.js'
import type { SupportedLocale } from '../../locales/index.js'
import type { PreprintTitle } from '../../preprint.js'
import { StreamlinePageResponse } from '../../response.js'
import {
Expand All @@ -29,6 +30,7 @@ export function addAuthorsForm({
authors: ReadonlyNonEmptyArray<{ name: NonEmptyString; emailAddress: EmailAddress }>
form: AddAuthorsForm
preprint: PreprintTitle
locale: SupportedLocale
}) {
const error = hasAnError(form)

Expand Down
7 changes: 6 additions & 1 deletion src/write-review/add-authors-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { get } from 'spectacles-ts'
import { match } from 'ts-pattern'
import { missingE } from '../../form.js'
import { havingProblemsPage, pageNotFound } from '../../http-error.js'
import { DefaultLocale, type SupportedLocale } from '../../locales/index.js'
import { type GetPreprintTitleEnv, type PreprintTitle, getPreprintTitle } from '../../preprint.js'
import { type LogInResponse, type PageResponse, RedirectResponse, type StreamlinePageResponse } from '../../response.js'
import { writeReviewAddAuthorMatch, writeReviewMatch } from '../../routes.js'
Expand Down Expand Up @@ -46,6 +47,7 @@ export const writeReviewAddAuthors = ({
pipe(
RTE.Do,
RTE.apS('user', pipe(RTE.fromNullable('no-session' as const)(user))),
RTE.apS('locale', RTE.of(DefaultLocale)),
RTE.let('preprint', () => preprint),
RTE.let('method', () => method),
RTE.let('body', () => body),
Expand Down Expand Up @@ -76,6 +78,7 @@ export const writeReviewAddAuthors = ({
...state,
authors: state.authors.value,
form: { anotherAuthor: E.right(undefined) },
locale: state.locale,
}),
)
.otherwise(() => pageNotFound),
Expand All @@ -89,11 +92,13 @@ const handleAddAuthorsForm = ({
body,
form,
preprint,
locale,
}: {
authors: O.Some<RNEA.ReadonlyNonEmptyArray<NonNullable<Form['otherAuthors']>[number]>>
body: unknown
form: Form
preprint: PreprintTitle
locale: SupportedLocale
}) =>
pipe(
E.Do,
Expand All @@ -106,7 +111,7 @@ const handleAddAuthorsForm = ({
),
),
E.matchW(
error => addAuthorsForm({ authors: authors.value, form: error, preprint }),
error => addAuthorsForm({ authors: authors.value, form: error, preprint, locale }),
state =>
match(state)
.with({ anotherAuthor: 'yes' }, () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Doi } from 'doi-ts'
import * as E from 'fp-ts/lib/Either.js'
import { missingE } from '../../src/form.js'
import { html } from '../../src/html.js'
import { DefaultLocale } from '../../src/locales/index.js'
import type { PreprintTitle } from '../../src/preprint.js'
import type { EmailAddress } from '../../src/types/email-address.js'
import type { NonEmptyString } from '../../src/types/string.js'
Expand All @@ -17,13 +18,16 @@ const preprint = {
language: 'en',
} satisfies PreprintTitle

const locale = DefaultLocale

test('content looks right when there is another author', async ({ showPage }) => {
const response = addAuthorsForm({
authors: [{ name: 'Josiah Carberry' as NonEmptyString, emailAddress: '[email protected]' as EmailAddress }],
form: {
anotherAuthor: E.right(undefined),
},
preprint,
locale,
})

const content = await showPage(response)
Expand All @@ -43,6 +47,7 @@ test('content looks right when there are other authors', async ({ showPage }) =>
anotherAuthor: E.right(undefined),
},
preprint,
locale,
})

const content = await showPage(response)
Expand All @@ -57,6 +62,7 @@ test('content looks right when fields are missing', async ({ showPage }) => {
anotherAuthor: E.left(missingE()),
},
preprint,
locale,
})

const content = await showPage(response)
Expand Down

0 comments on commit 5d2981b

Please sign in to comment.