-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page with basic details about the logged-in user
Refs #976
- Loading branch information
1 parent
ba069a5
commit 88fdb28
Showing
37 changed files
with
360 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { areLoggedIn, canLogIn, expect, test } from './base' | ||
|
||
test.extend(canLogIn).extend(areLoggedIn)('can view my details', async ({ javaScriptEnabled, page }) => { | ||
await page.goto('/my-details') | ||
|
||
await expect(page.getByRole('heading', { level: 1 })).toHaveText('My details') | ||
await expect(page).toHaveScreenshot() | ||
|
||
await page.keyboard.press('Tab') | ||
|
||
await expect(page.getByRole('link', { name: 'Skip to main content' })).toBeFocused() | ||
await expect(page).toHaveScreenshot() | ||
|
||
await page.keyboard.press('Enter') | ||
|
||
if (javaScriptEnabled) { | ||
await expect(page.getByRole('main')).toBeFocused() | ||
} | ||
await expect(page).toHaveScreenshot() | ||
}) |
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-1-Desktop-Chrome-high-contrast--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ots/can-view-my-details-1-Desktop-Chrome-high-contrast-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...apshots/log-in.spec.ts-snapshots/can-view-my-details-1-Desktop-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-1-Desktop-Chrome-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pshots/log-in.spec.ts-snapshots/can-view-my-details-1-Desktop-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pec.ts-snapshots/can-view-my-details-1-Desktop-Firefox-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
....spec.ts-snapshots/can-view-my-details-1-Mobile-Chrome-high-contrast--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...hots/can-view-my-details-1-Mobile-Chrome-high-contrast-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...on/snapshots/log-in.spec.ts-snapshots/can-view-my-details-1-iPhone-11-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...g-in.spec.ts-snapshots/can-view-my-details-1-iPhone-11-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-2-Desktop-Chrome-high-contrast--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ots/can-view-my-details-2-Desktop-Chrome-high-contrast-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...apshots/log-in.spec.ts-snapshots/can-view-my-details-2-Desktop-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-2-Desktop-Chrome-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pshots/log-in.spec.ts-snapshots/can-view-my-details-2-Desktop-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pec.ts-snapshots/can-view-my-details-2-Desktop-Firefox-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
....spec.ts-snapshots/can-view-my-details-2-Mobile-Chrome-high-contrast--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...hots/can-view-my-details-2-Mobile-Chrome-high-contrast-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...on/snapshots/log-in.spec.ts-snapshots/can-view-my-details-2-iPhone-11-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...g-in.spec.ts-snapshots/can-view-my-details-2-iPhone-11-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-3-Desktop-Chrome-high-contrast--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ots/can-view-my-details-3-Desktop-Chrome-high-contrast-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...apshots/log-in.spec.ts-snapshots/can-view-my-details-3-Desktop-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...spec.ts-snapshots/can-view-my-details-3-Desktop-Chrome-no-JavaScript--linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pshots/log-in.spec.ts-snapshots/can-view-my-details-3-Desktop-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...pec.ts-snapshots/can-view-my-details-3-Desktop-Firefox-no-JavaScript--linux.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
....spec.ts-snapshots/can-view-my-details-3-Mobile-Chrome-high-contrast--linux.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...hots/can-view-my-details-3-Mobile-Chrome-high-contrast-no-JavaScript--linux.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...on/snapshots/log-in.spec.ts-snapshots/can-view-my-details-3-iPhone-11-linux.png
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...g-in.spec.ts-snapshots/can-view-my-details-3-iPhone-11-no-JavaScript--linux.png
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { Reader } from 'fp-ts/Reader' | ||
import { pipe } from 'fp-ts/function' | ||
import { type ResponseEnded, Status, type StatusOpen } from 'hyper-ts' | ||
import type { OAuthEnv } from 'hyper-ts-oauth' | ||
import * as RM from 'hyper-ts/lib/ReaderMiddleware' | ||
import { P, match } from 'ts-pattern' | ||
import { html, plainText, sendHtml } from './html' | ||
import { logInAndRedirect } from './log-in' | ||
import { serviceUnavailable } from './middleware' | ||
import { type FathomEnv, type PhaseEnv, page } from './page' | ||
import type { PublicUrlEnv } from './public-url' | ||
import { myDetailsMatch } from './routes' | ||
import { getUser } from './user' | ||
import type { GetUserEnv, User } from './user' | ||
|
||
export const myDetails = pipe( | ||
getUser, | ||
chainReaderKW(createPage), | ||
RM.ichainFirst(() => RM.status(Status.OK)), | ||
RM.ichainMiddlewareKW(sendHtml), | ||
RM.orElseW(error => | ||
match(error) | ||
.with( | ||
'no-session', | ||
() => | ||
logInAndRedirect(myDetailsMatch.formatter, {}) as RM.ReaderMiddleware< | ||
GetUserEnv & FathomEnv & PhaseEnv & PublicUrlEnv & OAuthEnv, | ||
StatusOpen, | ||
ResponseEnded, | ||
never, | ||
void | ||
>, | ||
) | ||
.with(P.instanceOf(Error), () => serviceUnavailable) | ||
.exhaustive(), | ||
), | ||
) | ||
|
||
function createPage(user: User) { | ||
return page({ | ||
title: plainText`My details`, | ||
content: html` | ||
<main id="main-content"> | ||
<h1>My details</h1> | ||
<dl> | ||
<div> | ||
<dt>ORCID iD</dt> | ||
<dd><a href="https://orcid.org/${user.orcid}" class="orcid">${user.orcid}</a></dd> | ||
</div> | ||
<div> | ||
<dt>PREreview pseudonym</dt> | ||
<dd>${user.pseudonym}</dd> | ||
</div> | ||
</dl> | ||
</main> | ||
`, | ||
skipLinks: [[html`Skip to main content`, '#main-content']], | ||
user, | ||
}) | ||
} | ||
|
||
// https://github.com/DenisFrezzato/hyper-ts/pull/85 | ||
function fromReaderK<R, A extends ReadonlyArray<unknown>, B, I = StatusOpen, E = never>( | ||
f: (...a: A) => Reader<R, B>, | ||
): (...a: A) => RM.ReaderMiddleware<R, I, I, E, B> { | ||
return (...a) => RM.rightReader(f(...a)) | ||
} | ||
|
||
// https://github.com/DenisFrezzato/hyper-ts/pull/85 | ||
function chainReaderKW<R2, A, B>( | ||
f: (a: A) => Reader<R2, B>, | ||
): <R1, I, E>(ma: RM.ReaderMiddleware<R1, I, I, E, A>) => RM.ReaderMiddleware<R1 & R2, I, I, E, B> { | ||
return RM.chainW(fromReaderK(f)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.