upskill-event-manager/wordpress-dev/tests/e2e/certificate-management.test.ts
bengizmo fbc2d818c0 feat: Add comprehensive certificate E2E tests
- Created CertificatePage class for testing certificate functionality
- Updated DashboardPage to support certificate links in navigation
- Implemented test data generator for certificate testing
- Added tests for certificate generation with checked-in users
- Added tests for certificate generation with non-checked-in users
- Added certificate management (view/email/revoke) tests
- Created comprehensive trainer journey test including certificates
- Added utility script to run certificate-specific tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-20 20:44:42 -03:00

188 lines
No EOL
8.3 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { CertificatePage } from './pages/CertificatePage';
import { DashboardPage } from './pages/DashboardPage';
import { CertificateTestData } from './utils/CertificateTestData';
const STAGING_URL = 'https://wordpress-974670-5399585.cloudwaysapps.com';
test.describe('Certificate Management @certificate-management', () => {
let eventName: string | null = null;
test.beforeAll(async ({ browser }) => {
console.log('Setting up test data for certificate management tests...');
// Create a new browser context for data setup
const context = await browser.newContext();
const page = await context.newPage();
// Set up the test data
const testData = new CertificateTestData(page);
await testData.loginAsTrainer();
// Create a test event with attendees (some checked-in, some not)
eventName = await testData.setupCertificateTestEvent();
console.log(`Test event created: ${eventName}`);
// Generate certificates for the test event
if (eventName) {
const certificatePage = new CertificatePage(page);
// Navigate to generate certificates page
await page.goto(`${STAGING_URL}/generate-certificates/`);
await page.waitForLoadState('networkidle');
// Select the test event
await certificatePage.selectEvent(eventName);
// Select all attendees
await certificatePage.selectAllAttendees();
// Generate certificates
await certificatePage.generateCertificates();
console.log('Generated certificates for test event');
}
// Close the setup context
await context.close();
});
test('View, email, and revoke certificates', async ({ page }) => {
// Skip test if event creation failed
test.skip(!eventName, 'Test event creation failed in setup');
console.log('Step 1: Logging in...');
await page.goto(`${STAGING_URL}/community-login/`);
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'Test123!');
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
await expect(page).toHaveURL(/hvac-dashboard/);
console.log('Step 2: Navigate to dashboard...');
const dashboardPage = new DashboardPage(page);
await dashboardPage.navigate();
console.log('Step 3: Navigate to Certificate Reports...');
await dashboardPage.clickCertificateReports();
const certificatePage = new CertificatePage(page);
// Verify we're on the certificate reports page
const pageVisible = await certificatePage.isCertificateReportsPageVisible();
expect(pageVisible).toBeTruthy();
// Filter certificates for the test event
if (eventName) {
console.log('Step 4: Search for certificates from test event...');
await certificatePage.searchCertificates(eventName);
// Check certificate count
const certificateCount = await certificatePage.getCertificateCount();
console.log(`Found ${certificateCount} certificates for event`);
expect(certificateCount).toBeGreaterThan(0);
if (certificateCount > 0) {
// Test View Certificate
console.log('Step 5: Testing View Certificate functionality...');
await certificatePage.viewCertificate(0);
// Close the preview
await certificatePage.closePreview();
// Test Email Certificate
console.log('Step 6: Testing Email Certificate functionality...');
await certificatePage.emailCertificate(0);
// Check for success message after email
const emailSuccess = await certificatePage.isSuccessMessageVisible();
expect(emailSuccess).toBeTruthy();
// Test Revoke Certificate (if more than one certificate exists)
if (certificateCount > 1) {
console.log('Step 7: Testing Revoke Certificate functionality...');
await certificatePage.revokeCertificate(1);
// Check for success message after revocation
const revokeSuccess = await certificatePage.isSuccessMessageVisible();
expect(revokeSuccess).toBeTruthy();
// Verify certificate count decreased
await certificatePage.searchCertificates(eventName); // Refresh the list
const newCertificateCount = await certificatePage.getCertificateCount();
expect(newCertificateCount).toBeLessThan(certificateCount);
console.log(`Certificate count after revocation: ${newCertificateCount}`);
} else {
console.log('Only one certificate found, skipping revocation test');
}
}
}
console.log('Certificate management test completed successfully');
});
test('Pagination and filtering in Certificate Reports', async ({ page }) => {
// Skip test if event creation failed
test.skip(!eventName, 'Test event creation failed in setup');
console.log('Step 1: Logging in...');
await page.goto(`${STAGING_URL}/community-login/`);
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'Test123!');
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
console.log('Step 2: Navigate to Certificate Reports...');
const dashboardPage = new DashboardPage(page);
await dashboardPage.navigate();
await dashboardPage.clickCertificateReports();
const certificatePage = new CertificatePage(page);
// Verify we're on the certificate reports page
const pageVisible = await certificatePage.isCertificateReportsPageVisible();
expect(pageVisible).toBeTruthy();
// Test filtering functionality
console.log('Step 3: Testing filtering functionality...');
// 1. Filter by event name
if (eventName) {
await certificatePage.searchCertificates(eventName);
// Verify results contain only certificates for the test event
const certificateCount = await certificatePage.getCertificateCount();
console.log(`Found ${certificateCount} certificates for event "${eventName}"`);
expect(certificateCount).toBeGreaterThan(0);
}
// 2. Filter by a non-existent name (should show no results)
const randomText = `non-existent-event-${Math.random().toString(36).substring(2, 8)}`;
await certificatePage.searchCertificates(randomText);
// Verify no results
const noResultsCount = await certificatePage.getCertificateCount();
console.log(`Found ${noResultsCount} certificates for random text "${randomText}"`);
expect(noResultsCount).toBe(0);
// Test pagination if available
console.log('Step 4: Testing pagination functionality (if available)...');
// Clear the search first
await certificatePage.searchCertificates('');
// Check if pagination is visible (this might not be if there aren't enough certificates)
const isPaginationVisible = await certificatePage.isPaginationVisible();
if (isPaginationVisible) {
console.log('Pagination is visible, testing pagination functionality...');
// Add specific pagination testing here if there's pagination in the UI
// This would involve clicking next/previous buttons and verifying different results
} else {
console.log('No pagination visible, skipping pagination tests');
}
console.log('Certificate reporting pagination and filtering test completed');
});
});