Files
twenty/packages/twenty-apps/examples/postcard/e2e/auth.setup.ts
T
Paul Rastoin d1ba63d4a4 Postcard app e2e front component rendering test (#21600)
# Introduction
Creating a playwright test, quite granular and verbose that will verify
that the post card preview front component is rendered as expected on
the tested twenty instance

This covers everything e2e from twenty front, front comp renderer,
assets cdn rendered redirection etc
Style bridge etc

## Note

The playwright test setup assumes the application has already been
installed once, it's mainly used by the merge queue as a high level
front component and logic function ( will be in the same ci ) regression
bottleneck
The goal isn't for this test to be run locally
2026-06-15 13:02:19 +00:00

69 lines
2.4 KiB
TypeScript

import { type Locator, expect, test as setup } from '@playwright/test';
import * as fs from 'fs';
import * as path from 'path';
const AUTH_DIR = path.resolve(__dirname, '.auth');
const STORAGE_STATE = path.join(AUTH_DIR, 'user.json');
const WORKSPACE_ORIGIN_FILE = path.join(AUTH_DIR, 'workspace-origin.txt');
const LOGIN = process.env.E2E_LOGIN ?? 'tim@apple.dev';
const PASSWORD = process.env.E2E_PASSWORD ?? 'tim@apple.dev';
const WORKSPACE_NAME = process.env.E2E_WORKSPACE_NAME ?? 'Apple';
const isVisible = async (locator: Locator) =>
locator.isVisible().catch(() => false);
setup('authenticate', async ({ page }) => {
await page.goto('/');
// A fresh load shows the auth provider choice even when credentials are prefilled.
const continueWithEmail = page.getByRole('button', {
name: 'Continue with Email',
});
const emailField = page.getByPlaceholder('Email');
// Wait on the concrete auth UI rather than networkidle (flaky per Playwright).
await expect(continueWithEmail.or(emailField).first()).toBeVisible();
if (await isVisible(continueWithEmail)) {
await continueWithEmail.click();
}
if (await isVisible(emailField)) {
await emailField.fill(LOGIN);
await page.getByRole('button', { name: 'Continue', exact: true }).click();
}
const passwordField = page.getByPlaceholder('Password');
await passwordField.waitFor({ state: 'visible' });
await passwordField.fill(PASSWORD);
const signInButton = page.getByRole('button', { name: 'Sign in' });
await expect(signInButton).toBeEnabled();
await signInButton.click();
// Multi-workspace logins land on a picker; single-workspace logins skip it.
const workspacePicker = page.getByText('Choose a workspace');
const reachedPicker = await workspacePicker
.waitFor({ state: 'visible', timeout: 10_000 })
.then(() => true)
.catch(() => false);
if (reachedPicker) {
await page.getByText(WORKSPACE_NAME, { exact: true }).click();
await page.waitForFunction(() => window.location.href.includes('verify'));
await page.waitForFunction(() => !window.location.href.includes('verify'));
}
await page.waitForFunction(
() => window.localStorage.getItem('tokenPairState') !== null,
undefined,
{ timeout: 15_000 },
);
fs.mkdirSync(AUTH_DIR, { recursive: true });
fs.writeFileSync(WORKSPACE_ORIGIN_FILE, new URL(page.url()).origin);
await page.context().storageState({ path: STORAGE_STATE });
});