chatbot-template/tests/pages/auth.ts

66 lines
2.1 KiB
TypeScript
Raw Normal View History

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