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 { await this.navigate('/hvac-dashboard/'); } async clickCreateEvent(): Promise { await this.click(this.createEventButton); await this.waitForNavigation(); } async clickViewProfile(): Promise { await this.click(this.viewProfileButton); await this.waitForNavigation(); } async logout(): Promise { 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 { 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 { 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 { await this.page.click(`${this.eventsTable} a:has-text("${eventName}")`); await this.waitForNavigation(); } }