2025-09-21 12:03:29 +01:00
|
|
|
import type { Page } from '@playwright/test';
|
|
|
|
|
import { expect } from '../fixtures';
|
2025-04-25 23:40:15 -07:00
|
|
|
|
|
|
|
|
export class AuthPage {
|
2025-09-21 12:03:29 +01:00
|
|
|
constructor(private page: Page) {}
|
2025-04-25 23:40:15 -07:00
|
|
|
|
|
|
|
|
async gotoLogin() {
|
2025-09-21 12:03:29 +01:00
|
|
|
await this.page.goto('/login');
|
|
|
|
|
await expect(this.page.getByRole('heading')).toContainText('Sign In');
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async gotoRegister() {
|
2025-09-21 12:03:29 +01:00
|
|
|
await this.page.goto('/register');
|
|
|
|
|
await expect(this.page.getByRole('heading')).toContainText('Sign Up');
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async register(email: string, password: string) {
|
|
|
|
|
await this.gotoRegister();
|
2025-09-21 12:03:29 +01:00
|
|
|
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();
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async login(email: string, password: string) {
|
|
|
|
|
await this.gotoLogin();
|
2025-09-21 12:03:29 +01:00
|
|
|
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();
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async logout(email: string, password: string) {
|
|
|
|
|
await this.login(email, password);
|
2025-09-21 12:03:29 +01:00
|
|
|
await this.page.waitForURL('/');
|
2025-04-25 23:40:15 -07:00
|
|
|
|
|
|
|
|
await this.openSidebar();
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
const userNavButton = this.page.getByTestId('user-nav-button');
|
2025-04-25 23:40:15 -07:00
|
|
|
await expect(userNavButton).toBeVisible();
|
|
|
|
|
|
|
|
|
|
await userNavButton.click();
|
2025-09-21 12:03:29 +01:00
|
|
|
const userNavMenu = this.page.getByTestId('user-nav-menu');
|
2025-04-25 23:40:15 -07:00
|
|
|
await expect(userNavMenu).toBeVisible();
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
const authMenuItem = this.page.getByTestId('user-nav-item-auth');
|
|
|
|
|
await expect(authMenuItem).toContainText('Sign out');
|
2025-04-25 23:40:15 -07:00
|
|
|
|
|
|
|
|
await authMenuItem.click();
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
const userEmail = this.page.getByTestId('user-email');
|
|
|
|
|
await expect(userEmail).toContainText('Guest');
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async expectToastToContain(text: string) {
|
2025-09-21 12:03:29 +01:00
|
|
|
await expect(this.page.getByTestId('toast')).toContainText(text);
|
2025-04-25 23:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async openSidebar() {
|
2025-09-21 12:03:29 +01:00
|
|
|
const sidebarToggleButton = this.page.getByTestId('sidebar-toggle-button');
|
2025-04-25 23:40:15 -07:00
|
|
|
await sidebarToggleButton.click();
|
|
|
|
|
}
|
|
|
|
|
}
|