test(app): client journeys in Chromium on the isolated stack
Create, search, edit, archive, archived filter, restore; pages of 25; keyboard only; two accounts; a concurrent edit; a retry after a lost answer sends the same request id; network failures; the leave guard; a change of language; FR/EN, desktop and 375 px, axe on every state. signIn shared.
This commit is contained in:
1 parent
b38e62770e
commit
d33a8f6dad
4 files changed
+638
-27
No files matched your search
@@ -21,17 +21,20 @@ const ROUTES: [prefix: string, target: string][] = [
|
||||
['/storage/v1/', `${storageUrl}/`],
|
||||
]
|
||||
|
||||
/** The sandbox URL a request to the fake Supabase origin maps to, or null when unmapped. */
|
||||
export function sandboxUrl(url: string): string | null {
|
||||
const { pathname, search } = new URL(url)
|
||||
const path = pathname + search
|
||||
const mapped = ROUTES.find(([prefix]) => path.startsWith(prefix))
|
||||
return mapped ? mapped[1] + path.slice(mapped[0].length) : null
|
||||
}
|
||||
|
||||
/** Replays the page's Supabase calls on the sandbox; an unmapped path is refused. */
|
||||
export async function routeToSandbox(context: BrowserContext): Promise<void> {
|
||||
await context.route(`${FAKE_SUPABASE_ORIGIN}/**`, async (route) => {
|
||||
const path =
|
||||
new URL(route.request().url()).pathname +
|
||||
new URL(route.request().url()).search
|
||||
const mapped = ROUTES.find(([prefix]) => path.startsWith(prefix))
|
||||
if (!mapped) return route.abort('blockedbyclient')
|
||||
const response = await route.fetch({
|
||||
url: mapped[1] + path.slice(mapped[0].length),
|
||||
})
|
||||
const target = sandboxUrl(route.request().url())
|
||||
if (!target) return route.abort('blockedbyclient')
|
||||
const response = await route.fetch({ url: target })
|
||||
await route.fulfill({ response })
|
||||
})
|
||||
}
|
||||
@@ -43,6 +46,7 @@ const AVATAR_WEBP = Buffer.from(
|
||||
)
|
||||
|
||||
export interface SandboxAccount {
|
||||
id: string
|
||||
email: string
|
||||
password: string
|
||||
displayName: string
|
||||
@@ -105,5 +109,12 @@ export async function createAccount(
|
||||
})
|
||||
const { id } = (await response.json()) as { id: string }
|
||||
if (withAvatar) await seedAvatar(id)
|
||||
return account
|
||||
return { ...account, id }
|
||||
}
|
||||
|
||||
/** The personal workspace of a sandbox account (created by the server at sign-up). */
|
||||
export function workspaceOf(account: SandboxAccount): Promise<string> {
|
||||
return sql(
|
||||
`select id from public.workspaces where personal_user_id = '${account.id}'`,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Dict } from '@/i18n/types'
|
||||
import type { Page } from '@playwright/test'
|
||||
import { expect } from './browser'
|
||||
import type { SandboxAccount } from './sandbox'
|
||||
|
||||
/** Signs in through the login form; resolves on the dashboard once the profile answered. */
|
||||
export async function signIn(page: Page, account: SandboxAccount, dict: Dict) {
|
||||
await page.goto('/login')
|
||||
await page.getByLabel(dict['auth.email']).fill(account.email)
|
||||
await page
|
||||
.getByLabel(dict['auth.password'], { exact: true })
|
||||
.fill(account.password)
|
||||
await page.getByRole('button', { name: dict['auth.login.submit'] }).click()
|
||||
await expect(page).toHaveURL(/\/app\/?$/)
|
||||
// The greeting needs the profile: the session and the first REST call went through.
|
||||
await expect(page.locator('main h1')).toContainText(account.displayName)
|
||||
}
|
||||
Reference in new issue
Block a user