Skip to content

Commit

Permalink
Show an input to query the list
Browse files Browse the repository at this point in the history
Refs #1742
  • Loading branch information
thewilkybarkid committed Jun 10, 2024
1 parent a303a43 commit e0f7538
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 90 deletions.
7 changes: 6 additions & 1 deletion integration/finding-a-review.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,16 @@ test.extend(canUseSearchQueries)('can find an older review of a certain preprint
await page.goto('/')
await page.getByRole('link', { name: 'See all reviews' }).click()

const filters = page.getByRole('search', { name: 'Filter' })

await expect(page).toHaveTitle('Recent PREreviews (page 1) | PREreview')
await expect(filters.getByLabel('Query')).toHaveValue('')

await page.goto('/reviews?query=Chlamydomonas+reinhardtii')
await filters.getByLabel('Query').fill('Chlamydomonas reinhardtii')
await filters.getByRole('button', { name: 'Filter results' }).click()

await expect(page).toHaveTitle('Recent PREreviews (Chlamydomonas reinhardtii, page 1) | PREreview')
await expect(filters.getByLabel('Query')).toHaveValue('Chlamydomonas reinhardtii')
})

test('can view an older review in a specific language', async ({ page }) => {
Expand Down
6 changes: 4 additions & 2 deletions src/reviews-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export const reviewsPage = ({
error =>
match(error)
.with('not-found', () =>
page === 1 ? emptyPage({ field, language, query: canUseSearchQueries ? query : undefined }) : pageNotFound,
page === 1
? emptyPage({ field, language, query: canUseSearchQueries ? query : undefined }, canUseSearchQueries)
: pageNotFound,
)
.with('unavailable', () => failureMessage)
.exhaustive(),
createPage,
prereviews => createPage(prereviews, canUseSearchQueries),
),
)
34 changes: 24 additions & 10 deletions src/reviews-page/reviews-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import type { NonEmptyString } from '../types/string'
import { getSubfieldName } from '../types/subfield'
import type { RecentPrereviews } from './recent-prereviews'

export const createPage = ({ currentPage, field, language, query, totalPages, recentPrereviews }: RecentPrereviews) =>
export const createPage = (
{ currentPage, field, language, query, totalPages, recentPrereviews }: RecentPrereviews,
canUseSearchQueries: boolean,
) =>
PageResponse({
title: title({ currentPage, field, language, query }),
extraSkipLink: [html`Skip to results`, '#results'],
main: html`
<h1>Recent PREreviews</h1>
${form({ field, language, query })}
${form({ canUseSearchQueries, field, language, query })}
<ol class="cards" id="results">
${pipe(
Expand Down Expand Up @@ -111,18 +114,17 @@ export const createPage = ({ currentPage, field, language, query, totalPages, re
current: 'reviews',
})

export const emptyPage = ({
field,
language,
query,
}: { field?: FieldId; language?: LanguageCode; query?: NonEmptyString } = {}) =>
export const emptyPage = (
{ field, language, query }: { field?: FieldId; language?: LanguageCode; query?: NonEmptyString },
canUseSearchQueries: boolean,
) =>
PageResponse({
title: title({ currentPage: 1, field, language, query }),
extraSkipLink: [html`Skip to results`, '#results'],
main: html`
<h1>Recent PREreviews</h1>
${form({ field, language, query })}
${form({ canUseSearchQueries, field, language, query })}
<div class="inset" id="results">
<p>No PREreviews have been published yet.</p>
Expand All @@ -147,7 +149,12 @@ const title = ({
return plainText`Recent PREreviews (${formatList('en', { style: 'narrow' })(details)})`
}

const form = ({ field, language, query }: Pick<RecentPrereviews, 'field' | 'language' | 'query'>) => html`
const form = ({
canUseSearchQueries,
field,
language,
query,
}: Pick<RecentPrereviews, 'field' | 'language' | 'query'> & { canUseSearchQueries: boolean }) => html`
<form
method="get"
action="${format(reviewsMatch.formatter, {})}"
Expand All @@ -157,7 +164,14 @@ const form = ({ field, language, query }: Pick<RecentPrereviews, 'field' | 'lang
>
<h2 class="visually-hidden" id="filter-label">Filter</h2>
<input type="hidden" name="page" value="1" />
${query ? html`<input type="hidden" name="query" value="${query}" />` : ''}
${canUseSearchQueries
? html`<div>
<label for="query">Query</label>
<input type="text" name="query" id="query" ${query === undefined ? '' : html`value="${query}"`} />
</div>`
: query
? html`<input type="hidden" name="query" value="${query}" />`
: ''}
<div>
<label for="language">Language</label>
<select name="language" id="language">
Expand Down
92 changes: 55 additions & 37 deletions visual-regression/reviews-page/reviews-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,124 @@ import { expect, test } from '../base'
import PlainDate = Temporal.PlainDate

test('content looks right', async ({ showPage }) => {
const response = createPage({
currentPage: 1,
totalPages: 3,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
})
const response = createPage(
{
currentPage: 1,
totalPages: 3,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
},
false,
)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right with a query', async ({ showPage }) => {
const response = createPage({
currentPage: 1,
totalPages: 3,
query: 'Josiah Carberry' as NonEmptyString,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
})
const response = createPage(
{
currentPage: 1,
totalPages: 3,
query: 'Josiah Carberry' as NonEmptyString,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
},
true,
)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right with a language', async ({ showPage }) => {
const response = createPage({
currentPage: 1,
totalPages: 3,
language: 'es',
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
})
const response = createPage(
{
currentPage: 1,
totalPages: 3,
language: 'es',
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
},
false,
)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right with a field', async ({ showPage }) => {
const response = createPage({
currentPage: 1,
totalPages: 3,
field: '30',
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
})
const response = createPage(
{
currentPage: 1,
totalPages: 3,
field: '30',
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
},
false,
)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right when empty', async ({ showPage }) => {
const response = emptyPage()
const response = emptyPage({}, false)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right when empty with a query', async ({ showPage }) => {
const response = emptyPage({ query: 'Josiah Carberry' as NonEmptyString })
const response = emptyPage({ query: 'Josiah Carberry' as NonEmptyString }, true)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right when empty with a language', async ({ showPage }) => {
const response = emptyPage({ language: 'es' })
const response = emptyPage({ language: 'es' }, false)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks right when empty with a field', async ({ showPage }) => {
const response = emptyPage({ field: '30' })
const response = emptyPage({ field: '30' }, false)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks on a middle page', async ({ showPage }) => {
const response = createPage({
currentPage: 2,
totalPages: 3,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
})
const response = createPage(
{
currentPage: 2,
totalPages: 3,
recentPrereviews: [recentPrereview1, recentPrereview2, recentPrereview3, recentPrereview4, recentPrereview5],
},
false,
)

const content = await showPage(response)

await expect(content).toHaveScreenshot()
})

test('content looks on the last page', async ({ showPage }) => {
const response = createPage({
currentPage: 3,
totalPages: 3,
recentPrereviews: [recentPrereview1],
})
const response = createPage(
{
currentPage: 3,
totalPages: 3,
recentPrereviews: [recentPrereview1],
},
false,
)

const content = await showPage(response)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e0f7538

Please sign in to comment.