Files
myeasycms-v2/apps/e2e/tests/authentication/auth.po.ts
giancarlo 93964e174a Update UI layout and enhance email confirmation test
The UI layout for the site header, site footer, and account section was updated to improve visual spacing and arrangement. In addition, the authentication test for email confirmation was enhanced, specifically by adding checking that the response from visiting the mailbox is not null. This improves the robustness and reliability of the test.
2024-04-11 21:29:46 +08:00

81 lines
1.9 KiB
TypeScript

import { expect, 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 signOut() {
await this.page.click('[data-test="account-dropdown-trigger"]');
await this.page.click('[data-test="account-dropdown-sign-out"]');
}
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);
return expect(async() => {
const res = await this.mailbox.visitMailbox(email);
expect(res).not.toBeNull();
}).toPass();
}
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);
}
}