In this update, several end-to-end (e2e) tests were refactored to use Promise.all for parallel execution of operations. This was done to improve the efficiency and stability of the tests, as waiting for each operation one by one could cause bottlenecks and potential failures in the test execution. Receives and click actions were grouped together to allow them to be executed concurrently where possible. The changes were applied across different test scenarios.
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
|
|
import { AuthPageObject } from './auth.po';
|
|
|
|
test.describe('Auth flow', () => {
|
|
test.describe.configure({ mode: 'serial' });
|
|
|
|
let email: string;
|
|
|
|
test('will sign-up and redirect to the home page', async ({ page }) => {
|
|
const auth = new AuthPageObject(page);
|
|
await auth.goToSignUp();
|
|
|
|
email = auth.createRandomEmail();
|
|
|
|
console.log(`Signing up with email ${email} ...`);
|
|
|
|
const signUp = auth.signUp({
|
|
email,
|
|
password: 'password',
|
|
repeatPassword: 'password',
|
|
});
|
|
|
|
const response = page.waitForResponse((resp) => {
|
|
return resp.url().includes('auth');
|
|
});
|
|
|
|
await Promise.all([signUp, response]);
|
|
|
|
await auth.visitConfirmEmailLink(email);
|
|
|
|
await page.waitForURL('**/home');
|
|
|
|
expect(page.url()).toContain('http://localhost:3000/home');
|
|
});
|
|
|
|
test('will sign-in with the correct credentials', async ({ page }) => {
|
|
const auth = new AuthPageObject(page);
|
|
await auth.goToSignIn();
|
|
|
|
console.log(`Signing in with email ${email} ...`);
|
|
|
|
await auth.signIn({
|
|
email,
|
|
password: 'password',
|
|
});
|
|
|
|
await page.waitForURL('**/home');
|
|
|
|
expect(page.url()).toContain('/home');
|
|
|
|
await auth.signOut();
|
|
|
|
expect(page.url()).toContain('/');
|
|
});
|
|
});
|
|
|
|
test.describe('Protected routes', () => {
|
|
test('will redirect to the sign-in page if not authenticated', async ({
|
|
page,
|
|
}) => {
|
|
await page.goto('/home/settings');
|
|
|
|
expect(page.url()).toContain('/auth/sign-in?next=/home/settings');
|
|
});
|
|
|
|
test('will return a 404 for the admin page', async ({ page }) => {
|
|
await page.goto('/admin');
|
|
|
|
expect(page.url()).toContain('/auth/sign-in');
|
|
});
|
|
});
|