upskill-event-manager/wordpress-dev/tests/e2e/certificate-basic.spec.ts

120 lines
No EOL
3.9 KiB
TypeScript

import { STAGING_URL, PATHS, TIMEOUTS } from './config/staging-config';
import { test, expect } from '@playwright/test';
// Constants
// STAGING_URL is now imported from config
const LOGIN_URL = PATHS.login;
const DASHBOARD_URL = PATHS.dashboard;
const USERNAME = 'test_trainer';
const PASSWORD = 'Test123!';
// Test: Login and navigate to Generate Certificates page
test('Should navigate to Generate Certificates page', async ({ page }) => {
// Login
await page.goto(LOGIN_URL);
await page.fill('#user_login', USERNAME);
await page.fill('#user_pass', PASSWORD);
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Verify login was successful
await expect(page).toHaveURL(/hvac-dashboard/);
// Navigate to dashboard first
await page.goto(DASHBOARD_URL);
await page.waitForLoadState('networkidle');
// Look for Generate Certificates link
const generateLink = page.locator('a:has-text("Generate Certificates")');
await expect(generateLink).toBeVisible();
// Click the link
await generateLink.click();
await page.waitForLoadState('networkidle');
// Check page title
const title = await page.title();
expect(title).toContain('Generate Certificates');
// Check for event dropdown
const eventDropdown = page.locator('#event_id');
await expect(eventDropdown).toBeVisible();
// Count options to verify dropdown is populated
const optionCount = await page.locator('#event_id option').count();
expect(optionCount).toBeGreaterThan(1);
});
// Test: Login and navigate to Certificate Reports page
test('Should navigate to Certificate Reports page', async ({ page }) => {
// Login
await page.goto(LOGIN_URL);
await page.fill('#user_login', USERNAME);
await page.fill('#user_pass', PASSWORD);
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Verify login was successful
await expect(page).toHaveURL(/hvac-dashboard/);
// Navigate to dashboard first
await page.goto(DASHBOARD_URL);
await page.waitForLoadState('networkidle');
// Look for Certificate Reports link
const reportsLink = page.locator('a:has-text("Certificate Reports")');
await expect(reportsLink).toBeVisible();
// Click the link
await reportsLink.click();
await page.waitForLoadState('networkidle');
// Check page title
const title = await page.title();
expect(title).toContain('Certificate Reports');
// Check for filter form
const filterForm = page.locator('form.hvac-certificate-filters');
await expect(filterForm).toBeVisible();
});
// Test: Filter certificates by event
test('Should filter certificates by event', async ({ page }) => {
// Login
await page.goto(LOGIN_URL);
await page.fill('#user_login', USERNAME);
await page.fill('#user_pass', PASSWORD);
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Navigate to Certificate Reports page
await page.goto(`${STAGING_URL}/certificate-reports/`);
await page.waitForLoadState('networkidle');
// Check for filter form
const filterForm = page.locator('form.hvac-certificate-filters');
await expect(filterForm).toBeVisible();
// Check if event filter exists
const eventFilter = page.locator('#filter_event');
await expect(eventFilter).toBeVisible();
// Get options count
const optionCount = await page.locator('#filter_event option').count();
// Test different filter options
if (optionCount > 1) {
// Select the first non-empty option
await eventFilter.selectOption({ index: 1 });
// Apply filter
const filterButton = page.locator('button[type="submit"]');
await filterButton.click();
await page.waitForLoadState('networkidle');
// Log the filter results (can't guarantee there will be certificates)
const certificateItems = page.locator('.hvac-certificate-item');
const certificateCount = await certificateItems.count();
console.log(`Found ${certificateCount} certificates after filtering by event`);
}
});