/** * Test script for certification display functionality * * This script tests the trainer profile display with the new certification system * by checking existing data and testing the display components. */ const { chromium } = require('playwright'); // Configuration const BASE_URL = process.env.BASE_URL || 'https://upskill-staging.measurequick.com'; const HEADLESS = process.env.HEADLESS !== 'false'; async function testCertificationDisplay() { console.log('šŸŽ­ Testing certification display components...'); const browser = await chromium.launch({ headless: HEADLESS }); const page = await browser.newPage(); try { // First, test the find-a-trainer page to see trainer profiles console.log('šŸ“ Navigating to find-a-trainer page...'); await page.goto(`${BASE_URL}/find-a-trainer/`); await page.waitForLoadState('networkidle'); await page.waitForTimeout(3000); // Check for various certification display elements console.log('šŸ” Checking for certification display elements...'); // New certification system elements const certificationCards = await page.locator('.hvac-certification-card').count(); const certificationGrids = await page.locator('.hvac-certifications-grid').count(); const certificationTitles = await page.locator('.hvac-certification-title').count(); const certificationBadges = await page.locator('.hvac-certification-status-badge').count(); const certificationExpiration = await page.locator('.hvac-certification-expiration').count(); // Legacy certification elements const legacyCertSections = await page.locator('.hvac-certification-section').count(); const legacyCertStatuses = await page.locator('.hvac-cert-status').count(); // General trainer profile elements const trainerProfiles = await page.locator('.hvac-trainer-card, .trainer-profile, .hvac-profile-card').count(); console.log('\nšŸ“Š Display elements found:'); console.log(` šŸŽ“ New certification cards: ${certificationCards}`); console.log(` šŸ“± New certification grids: ${certificationGrids}`); console.log(` šŸ·ļø New certification titles: ${certificationTitles}`); console.log(` šŸ… New certification badges: ${certificationBadges}`); console.log(` ā° New expiration elements: ${certificationExpiration}`); console.log(` šŸ“œ Legacy cert sections: ${legacyCertSections}`); console.log(` šŸ”– Legacy cert statuses: ${legacyCertStatuses}`); console.log(` šŸ‘¤ Trainer profiles: ${trainerProfiles}`); // Take screenshot of current state await page.screenshot({ path: '/tmp/find-trainer-certification-test.png', fullPage: true }); console.log('šŸ“ø Screenshot saved: /tmp/find-trainer-certification-test.png'); // Check page source for certification-related classes const content = await page.content(); const hasNewCertClasses = content.includes('hvac-certification-card') || content.includes('hvac-certifications-grid'); const hasLegacyCertClasses = content.includes('hvac-certification-section') || content.includes('hvac-cert-status'); console.log('\nšŸ” CSS classes detected:'); console.log(` ✨ New certification classes: ${hasNewCertClasses ? 'āœ… Found' : 'āŒ Not found'}`); console.log(` šŸ“œ Legacy certification classes: ${hasLegacyCertClasses ? 'āœ… Found' : 'āŒ Not found'}`); // Try to find individual trainer profiles to test console.log('\nšŸŽÆ Looking for individual trainer profiles...'); const profileLinks = await page.locator('a[href*="/trainer/"], a[href*="trainer-profile"], a[href*="/profile/"]').count(); console.log(` šŸ”— Found ${profileLinks} potential trainer profile links`); if (profileLinks > 0) { console.log(' šŸš€ Testing first trainer profile...'); try { await page.locator('a[href*="/trainer/"], a[href*="trainer-profile"], a[href*="/profile/"]').first().click(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(2000); // Check certification display on individual profile const profileCertCards = await page.locator('.hvac-certification-card').count(); const profileCertGrids = await page.locator('.hvac-certifications-grid').count(); const profileLegacyCerts = await page.locator('.hvac-certification-section').count(); console.log(` šŸ“Š Individual profile elements:)`); console.log(` šŸŽ“ Certification cards: ${profileCertCards}`); console.log(` šŸ“± Certification grids: ${profileCertGrids}`); console.log(` šŸ“œ Legacy sections: ${profileLegacyCerts}`); // Take screenshot of individual profile await page.screenshot({ path: '/tmp/individual-trainer-profile-test.png', fullPage: true }); console.log(' šŸ“ø Individual profile screenshot: /tmp/individual-trainer-profile-test.png'); } catch (profileError) { console.log(` āš ļø Could not test individual profile: ${profileError.message}`); } } // Check for JavaScript errors const logs = []; page.on('console', msg => { if (msg.type() === 'error') { logs.push(msg.text()); } }); // Reload to capture any console errors await page.reload(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); if (logs.length > 0) { console.log('\nāŒ JavaScript errors detected:'); logs.forEach(log => console.log(` šŸ’„ ${log}`)); } else { console.log('\nāœ… No JavaScript errors detected'); } return { newCertificationElements: { cards: certificationCards, grids: certificationGrids, titles: certificationTitles, badges: certificationBadges, expiration: certificationExpiration }, legacyElements: { sections: legacyCertSections, statuses: legacyCertStatuses }, general: { trainerProfiles, profileLinks, hasNewClasses: hasNewCertClasses, hasLegacyClasses: hasLegacyCertClasses }, errors: logs.length }; } catch (error) { console.error('āŒ Test failed:', error.message); await page.screenshot({ path: '/tmp/certification-display-test-error.png' }); console.log('šŸ“ø Error screenshot: /tmp/certification-display-test-error.png'); throw error; } finally { await browser.close(); } } async function testDirectProfileAccess() { console.log('\nšŸŽÆ Testing direct profile access...'); const browser = await chromium.launch({ headless: HEADLESS }); const page = await browser.newPage(); try { // Try to access trainer dashboard or profile pages directly const testUrls = [ `${BASE_URL}/trainer/dashboard/`, `${BASE_URL}/trainer/profile/`, `${BASE_URL}/training-login/` // Login page to check if it exists ]; for (const url of testUrls) { console.log(` šŸ“ Testing ${url}...`); try { await page.goto(url, { timeout: 10000 }); await page.waitForLoadState('networkidle'); const title = await page.title(); const statusCode = page.url(); console.log(` šŸ“„ Page title: ${title}`); console.log(` 🌐 Final URL: ${statusCode}`); // Check for certification elements on this page const certCards = await page.locator('.hvac-certification-card').count(); const certGrids = await page.locator('.hvac-certifications-grid').count(); if (certCards > 0 || certGrids > 0) { console.log(` āœ… Found certification elements! Cards: ${certCards}, Grids: ${certGrids}`); await page.screenshot({ path: `/tmp/direct-access-${url.split('/').slice(-2, -1)[0]}.png` }); console.log(` šŸ“ø Screenshot saved for ${url}`); } } catch (urlError) { console.log(` āŒ Failed to access ${url}: ${urlError.message}`); } } } finally { await browser.close(); } } // Main test function async function main() { console.log('šŸš€ Starting certification display test...\n'); try { // Test 1: Check display components on find-a-trainer const displayResults = await testCertificationDisplay(); // Test 2: Try direct profile access await testDirectProfileAccess(); // Evaluate results console.log('\nšŸ“‹ Test Results Summary:'); console.log('=' .repeat(50)); const hasNewSystem = displayResults.newCertificationElements.cards > 0 || displayResults.newCertificationElements.grids > 0 || displayResults.general.hasNewClasses; const hasLegacySystem = displayResults.legacyElements.sections > 0 || displayResults.legacyElements.statuses > 0 || displayResults.general.hasLegacyClasses; if (hasNewSystem) { console.log('āœ… NEW CERTIFICATION SYSTEM: Active and displaying'); console.log(` šŸŽ“ Certification cards found: ${displayResults.newCertificationElements.cards}`); console.log(` šŸ“± Certification grids found: ${displayResults.newCertificationElements.grids}`); } else { console.log('āŒ NEW CERTIFICATION SYSTEM: Not detected'); } if (hasLegacySystem) { console.log('šŸ“œ LEGACY CERTIFICATION SYSTEM: Still active'); console.log(` šŸ“„ Legacy sections found: ${displayResults.legacyElements.sections}`); } else { console.log('āœ… LEGACY CERTIFICATION SYSTEM: Not detected (expected)'); } if (displayResults.general.trainerProfiles > 0) { console.log(`šŸ‘„ TRAINER PROFILES: ${displayResults.general.trainerProfiles} found`); } else { console.log('āŒ TRAINER PROFILES: None found (may need data)'); } if (displayResults.errors > 0) { console.log(`āŒ JAVASCRIPT ERRORS: ${displayResults.errors} detected`); } else { console.log('āœ… JAVASCRIPT ERRORS: None detected'); } // Overall assessment if (hasNewSystem && displayResults.errors === 0) { console.log('\nšŸŽ‰ OVERALL ASSESSMENT: SUCCESS - New certification system is working!'); } else if (hasLegacySystem && !hasNewSystem) { console.log('\nāš ļø OVERALL ASSESSMENT: LEGACY ONLY - New system not activated yet'); } else { console.log('\nā“ OVERALL ASSESSMENT: MIXED RESULTS - May need investigation'); } } catch (error) { console.error('\nšŸ’„ Test failed:', error.message); process.exit(1); } console.log('\nšŸ Certification display test completed!'); console.log('\nScreenshots saved in /tmp/ for review:'); console.log(' šŸ“ø /tmp/find-trainer-certification-test.png'); console.log(' šŸ“ø /tmp/individual-trainer-profile-test.png (if available)'); } // Run the test main().catch(console.error);