Files
sign/packages/app-tests/e2e/user/auth-flow.spec.ts

67 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-10-03 09:53:47 +01:00
import { type Page, expect, test } from '@playwright/test';
2024-02-22 22:58:51 +11:00
import {
extractUserVerificationToken,
seedTestEmail,
2024-02-22 22:58:51 +11:00
seedUser,
unseedUser,
unseedUserByEmail,
} from '@documenso/prisma/seed/users';
2023-10-03 09:53:47 +01:00
test.use({ storageState: { cookies: [], origins: [] } });
test('[USER] can sign up with email and password', async ({ page }: { page: Page }) => {
2024-02-22 22:58:51 +11:00
const username = 'Test User';
const email = seedTestEmail();
2024-02-22 22:58:51 +11:00
const password = 'Password123#';
2023-10-03 09:53:47 +01:00
await page.goto('/signup');
await page.getByLabel('Name').fill(username);
await page.getByLabel('Email').fill(email);
await page.getByLabel('Password', { exact: true }).fill(password);
const canvas = page.locator('canvas');
const box = await canvas.boundingBox();
if (box) {
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(box.x + box.width / 4, box.y + box.height / 4);
await page.mouse.up();
}
2024-02-29 15:19:38 +11:00
await page.getByRole('button', { name: 'Next', exact: true }).click();
await page.getByLabel('Public profile username').fill(Date.now().toString());
2024-02-29 14:26:37 +11:00
await page.getByRole('button', { name: 'Complete', exact: true }).click();
2024-02-22 22:58:51 +11:00
await page.waitForURL('/unverified-account');
const { token } = await extractUserVerificationToken(email);
await page.goto(`/verify-email/${token}`);
await expect(page.getByRole('heading')).toContainText('Email Confirmed!');
await page.getByRole('link', { name: 'Go back home' }).click();
2023-10-03 09:53:47 +01:00
await page.waitForURL('/documents');
await expect(page).toHaveURL('/documents');
2024-02-22 22:58:51 +11:00
await unseedUserByEmail(email);
2023-10-03 09:53:47 +01:00
});
test('[USER] can sign in using email and password', async ({ page }: { page: Page }) => {
2024-02-22 22:58:51 +11:00
const user = await seedUser();
2023-10-03 09:53:47 +01:00
await page.goto('/signin');
2024-02-22 22:58:51 +11:00
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password', { exact: true }).fill('password');
2023-10-03 09:53:47 +01:00
await page.getByRole('button', { name: 'Sign In' }).click();
await page.waitForURL('/documents');
await expect(page).toHaveURL('/documents');
2024-02-22 22:58:51 +11:00
await unseedUser(user.id);
2023-10-03 09:53:47 +01:00
});