File size: 2,185 Bytes
867b17d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import type { Page } from '@playwright/test';
import { expect } from '../fixtures';
export class AuthPage {
constructor(private page: Page) {}
async gotoLogin() {
await this.page.goto('/login');
await expect(this.page.getByRole('heading')).toContainText('Sign In');
}
async gotoRegister() {
await this.page.goto('/register');
await expect(this.page.getByRole('heading')).toContainText('Sign Up');
}
async register(email: string, password: string) {
await this.gotoRegister();
await this.page.getByPlaceholder('user@acme.com').click();
await this.page.getByPlaceholder('user@acme.com').fill(email);
await this.page.getByLabel('Password').click();
await this.page.getByLabel('Password').fill(password);
await this.page.getByRole('button', { name: 'Sign Up' }).click();
}
async login(email: string, password: string) {
await this.gotoLogin();
await this.page.getByPlaceholder('user@acme.com').click();
await this.page.getByPlaceholder('user@acme.com').fill(email);
await this.page.getByLabel('Password').click();
await this.page.getByLabel('Password').fill(password);
await this.page.getByRole('button', { name: 'Sign In' }).click();
}
async logout(email: string, password: string) {
await this.login(email, password);
await this.page.waitForURL('/');
await this.openSidebar();
const userNavButton = this.page.getByTestId('user-nav-button');
await expect(userNavButton).toBeVisible();
await userNavButton.click();
const userNavMenu = this.page.getByTestId('user-nav-menu');
await expect(userNavMenu).toBeVisible();
const authMenuItem = this.page.getByTestId('user-nav-item-auth');
await expect(authMenuItem).toContainText('Sign out');
await authMenuItem.click();
const userEmail = this.page.getByTestId('user-email');
await expect(userEmail).toContainText('Guest');
}
async expectToastToContain(text: string) {
await expect(this.page.getByTestId('toast')).toContainText(text);
}
async openSidebar() {
const sidebarToggleButton = this.page.getByTestId('sidebar-toggle-button');
await sidebarToggleButton.click();
}
}
|