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 Generation for Non-Checked-In Attendees @certificate', () => { let eventName: string | null = null; test.beforeAll(async ({ browser }) => { console.log('Setting up test data for non-checked-in certificate 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}`); // Close the setup context await context.close(); }); test('Generate certificates for non-checked-in attendees', 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: Verify certificate links are visible...'); await dashboardPage.clickGenerateCertificates(); console.log('Step 4: Attempt to generate certificates for non-checked-in attendees...'); const certificatePage = new CertificatePage(page); // Verify we're on the generate certificates page const pageVisible = await certificatePage.isGenerateCertificatesPageVisible(); expect(pageVisible).toBeTruthy(); // Select the test event if (eventName) { await certificatePage.selectEvent(eventName); // Get attendee counts const totalAttendees = await certificatePage.getAttendeeCount(); const checkedInAttendees = await certificatePage.getCheckedInAttendeeCount(); const nonCheckedInAttendees = totalAttendees - checkedInAttendees; console.log(`Found ${totalAttendees} total attendees, ${nonCheckedInAttendees} non-checked-in`); expect(totalAttendees).toBeGreaterThan(0); expect(nonCheckedInAttendees).toBeGreaterThan(0); // Select only non-checked-in attendees await certificatePage.selectNonCheckedInAttendees(); // Generate certificates await certificatePage.generateCertificates(); // Check for success or warning message // Note: The implementation could allow this with warnings, // or it could block generation for non-checked-in attendees const successVisible = await certificatePage.isSuccessMessageVisible(); const errorVisible = await certificatePage.isErrorMessageVisible(); if (successVisible) { const successMessage = await certificatePage.getSuccessMessage(); console.log(`Success message: ${successMessage}`); // If certificates were generated for non-checked-in attendees, // check them in the reports page console.log('Step 5: Verify certificates in Certificate Reports...'); // Navigate to certificate reports await dashboardPage.navigate(); await dashboardPage.clickCertificateReports(); // Verify we're on the certificate reports page const reportsPageVisible = await certificatePage.isCertificateReportsPageVisible(); expect(reportsPageVisible).toBeTruthy(); // Filter certificates for the test event await certificatePage.searchCertificates(eventName); // Check certificate count const certificateCount = await certificatePage.getCertificateCount(); console.log(`Found ${certificateCount} certificates for event`); // We should have certificates for the non-checked-in attendees expect(certificateCount).toBeGreaterThan(0); // View a certificate if (certificateCount > 0) { await certificatePage.viewCertificate(0); // Close the preview await certificatePage.closePreview(); } } else if (errorVisible) { // If the system prevents generating certificates for non-checked-in attendees, // verify the appropriate error message is shown const errorMessage = await certificatePage.getErrorMessage(); console.log(`Error message: ${errorMessage}`); expect(errorMessage).toContain("check-in") || expect(errorMessage).toContain("attendance"); // Verify no certificates were generated for non-checked-in attendees console.log('Verifying no certificates were generated...'); // Navigate to certificate reports await dashboardPage.navigate(); await dashboardPage.clickCertificateReports(); // Filter certificates for the test event await certificatePage.searchCertificates(eventName); // Search for any certificates generated since we started the test const certificateCount = await certificatePage.getCertificateCount(); // There shouldn't be any new certificates for non-checked-in attendees // Note: This simple verification might be inaccurate if there were already certificates // for this event that we didn't account for console.log(`Found ${certificateCount} certificates for event`); } else { // If neither success nor error message is visible, something unexpected happened console.log('No success or error message found after certificate generation attempt'); expect(false).toBeTruthy(); // Fail the test } } console.log('Certificate generation test for non-checked-in attendees completed'); }); });