Files
tokens-reef/tests/e2e/pages/DashboardPage.ts
Developer 8b19f56ba4 fix: update E2E test API paths and payloads to match backend
- user-apikey-lifecycle: /api/v1/keys -> /api/v1/api-keys (24 occurrences)
- admin-users: balance payload uses balance+operation+notes
- admin-groups: rate-multiplier already uses correct format
2026-04-02 22:35:48 +08:00

45 lines
1.4 KiB
TypeScript

/**
* DashboardPage — Page Object for the Admin Dashboard (/admin/dashboard)
*
* Improvements:
* - Removed waitForTimeout anti-pattern; use proper waits.
* - More specific locators for sidebar and stat cards.
*/
import { Page, Locator, expect } from '@playwright/test';
export class DashboardPage {
readonly page: Page;
readonly title: Locator;
readonly sidebar: Locator;
/** Statistics / metric cards on the dashboard */
readonly statCards: Locator;
constructor(page: Page) {
this.page = page;
this.title = page.locator('h1, h2, [class*="title"], [class*="t-page-header__title"]').first();
this.sidebar = page.locator('nav, aside, [class*="sidebar"], [class*="t-menu"], [class*="t-layout__sider"]').first();
this.statCards = page.locator('[class*="t-statistic"], [class*="statistic"], [class*="stat-card"]');
}
async goto() {
await this.page.goto('/admin/dashboard', { waitUntil: 'networkidle' });
}
async expectSidebarVisible() {
await expect(this.sidebar).toBeVisible({ timeout: 10_000 });
}
async navigateTo(section: string) {
const link = this.sidebar.locator(`a:has-text("${section}")`);
await link.click();
// Wait for navigation to complete
await this.page.waitForLoadState('networkidle');
}
async expectAtLeastOneStatCard() {
const count = await this.statCards.count();
expect(count, 'Dashboard should have at least one stat card').toBeGreaterThan(0);
}
}