Files
myeasycms-v2/apps/e2e/tests/authentication/auth.po.ts
giancarlo 9d8d33121a Update e2e tests for authentication
The commit modifies end-to-end testing for the authentication process. It replaces the explicit waitForURL method with the waitForTimeout method and makes the navigation checks less strict. Aside from this, it configures the page navigation methods to wait until there is no network activity
2024-04-11 18:50:55 +08:00

72 lines
1.7 KiB
TypeScript

import { Page } from '@playwright/test';
import { Mailbox } from '../utils/mailbox';
export class AuthPageObject {
private readonly page: Page;
private readonly mailbox: Mailbox;
constructor(page: Page) {
this.page = page;
this.mailbox = new Mailbox(page);
}
goToSignIn() {
return this.page.goto('/auth/sign-in', {
waitUntil: 'networkidle',
});
}
goToSignUp() {
return this.page.goto('/auth/sign-up', {
waitUntil: 'networkidle',
});
}
async signIn(params: {
email: string,
password: string
}) {
await this.page.fill('input[name="email"]', params.email);
await this.page.fill('input[name="password"]', params.password);
await this.page.click('button[type="submit"]');
}
async signUp(params: {
email: string,
password: string,
repeatPassword: string
}) {
await this.page.fill('input[name="email"]', params.email);
await this.page.fill('input[name="password"]', params.password);
await this.page.fill('input[name="repeatPassword"]', params.repeatPassword);
await this.page.click('button[type="submit"]');
}
async visitConfirmEmailLink(email: string) {
await this.page.waitForTimeout(300);
await this.mailbox.visitMailbox(email);
}
createRandomEmail() {
const value = Math.random() * 1000;
return `${value.toFixed(0)}@makerkit.dev`;
}
async signUpFlow(path: string) {
const email = this.createRandomEmail();
await this.page.goto(`/auth/sign-up?next=${path}`, {
waitUntil: 'networkidle',
});
await this.signUp({
email,
password: 'password',
repeatPassword: 'password',
});
await this.visitConfirmEmailLink(email);
}
}