upskill-event-manager/wordpress-dev/tests/e2e/pages/DashboardPage.ts
bengizmo 57f696e0a8 Implement trainer journey E2E tests (Steps 1-5)
- Add comprehensive trainer journey test implementation
- Cover login, dashboard access, event creation, modification, and deletion
- Fix TinyMCE editor interaction issues
- Handle venue and organizer form fields
- Add proper waits and error handling
- Update documentation with test findings
- Document event persistence issues in staging

Test Status: All trainer journey steps (1-5) are now passing
Key Finding: Events persist to My Events page but not main dashboard

Co-authored-by: Ben Reed <ben@tealmaker.com>
2025-05-18 17:56:23 -03:00

115 lines
No EOL
4.3 KiB
TypeScript

import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
export class DashboardPage extends BasePage {
private readonly createEventButton = 'a:has-text("Create Event")';
private readonly viewProfileButton = 'a:has-text("View Profile")';
private readonly logoutButton = 'a:has-text("Logout")';
private readonly eventsTable = 'table';
private readonly statsSection = '.hvac-stats-grid';
private readonly totalEventsCard = '.hvac-stat-card:has-text("Total Events")';
private readonly upcomingEventsCard = '.hvac-stat-card:has-text("Upcoming Events")';
private readonly pastEventsCard = '.hvac-stat-card:has-text("Past Events")';
private readonly totalRevenueCard = '.hvac-stat-card:has-text("Total Revenue")';
constructor(page: Page) {
super(page);
}
async navigateToDashboard(): Promise<void> {
await this.navigate('/hvac-dashboard/');
}
async clickCreateEvent(): Promise<void> {
await this.click(this.createEventButton);
await this.waitForNavigation();
}
async clickViewProfile(): Promise<void> {
await this.click(this.viewProfileButton);
await this.waitForNavigation();
}
async logout(): Promise<void> {
await this.click(this.logoutButton);
await this.waitForNavigation();
}
async getStatistics(): Promise<{
totalEvents: string;
upcomingEvents: string;
pastEvents: string;
revenue: string;
}> {
return {
totalEvents: await this.page.locator(this.totalEventsCard).locator('p').textContent() || '0',
upcomingEvents: await this.page.locator(this.upcomingEventsCard).locator('p').textContent() || '0',
pastEvents: await this.page.locator(this.pastEventsCard).locator('p').textContent() || '0',
revenue: await this.page.locator(this.totalRevenueCard).locator('p').textContent() || '$0.00'
};
}
async isEventsTableVisible(): Promise<boolean> {
return await this.isVisible(this.eventsTable);
}
async getEventRowData(index: number): Promise<{
status: string;
name: string;
date: string;
organizer: string;
capacity: string;
soldTickets: string;
revenue: string;
}> {
const row = await this.page.locator(`${this.eventsTable} tbody tr`).nth(index);
// Check if this is a "No events found" row
const cellCount = await row.locator('td').count();
if (cellCount === 1) {
const text = await row.locator('td').textContent();
if (text?.includes('No events found')) {
return {
status: '',
name: text,
date: '',
organizer: '',
capacity: '',
soldTickets: '',
revenue: ''
};
}
}
return {
status: await row.locator('td:nth-child(1)').textContent() || '',
name: await row.locator('td:nth-child(2)').textContent() || '',
date: await row.locator('td:nth-child(3)').textContent() || '',
organizer: await row.locator('td:nth-child(4)').textContent() || '',
capacity: await row.locator('td:nth-child(5)').textContent() || '',
soldTickets: await row.locator('td:nth-child(6)').textContent() || '',
revenue: await row.locator('td:nth-child(7)').textContent() || ''
};
}
async getEventCount(): Promise<number> {
const rows = await this.page.locator(`${this.eventsTable} tbody tr`).count();
// Check if the only row is "No events found"
if (rows === 1) {
const firstRow = await this.page.locator(`${this.eventsTable} tbody tr`).first();
const cellCount = await firstRow.locator('td').count();
if (cellCount === 1) {
const text = await firstRow.locator('td').textContent();
if (text?.includes('No events found')) {
return 0;
}
}
}
return rows;
}
async clickEventName(eventName: string): Promise<void> {
await this.page.click(`${this.eventsTable} a:has-text("${eventName}")`);
await this.waitForNavigation();
}
}