#!/usr/bin/env node /** * Comprehensive Organizer Management Test * Tests the complete organizer management workflow including authentication */ const { chromium } = require('playwright'); // Configuration const config = { BASE_URL: process.env.BASE_URL || 'http://localhost:8080', HEADLESS: process.env.HEADLESS !== 'false', USERNAME: process.env.TEST_USERNAME || 'testtrainer', PASSWORD: process.env.TEST_PASSWORD || 'TestPass123!' }; async function runComprehensiveOrganizerTest() { console.log('๐Ÿงช Comprehensive Organizer Management Test'); console.log('==========================================\n'); const browser = await chromium.launch({ headless: config.HEADLESS, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); let testResults = { passed: 0, failed: 0, skipped: 0, details: [] }; try { // Test 1: Login as trainer console.log('1. Testing trainer login...'); try { await page.goto(`${config.BASE_URL}/community-login/`); await page.waitForLoadState('networkidle'); // Check if login form exists const loginForm = await page.locator('#loginform'); if (await loginForm.isVisible()) { await page.fill('#user_login', config.USERNAME); await page.fill('#user_pass', config.PASSWORD); await page.click('#wp-submit'); await page.waitForLoadState('networkidle'); // Check if redirected to trainer dashboard const currentUrl = page.url(); if (currentUrl.includes('/trainer/dashboard/')) { console.log(' โœ… Login successful'); testResults.passed++; testResults.details.push('Login: โœ… Successful'); } else { console.log(' โŒ Login failed - not redirected to dashboard'); testResults.failed++; testResults.details.push('Login: โŒ Not redirected to dashboard'); } } else { console.log(' โญ๏ธ Login form not found - may already be logged in'); testResults.skipped++; testResults.details.push('Login: โญ๏ธ Form not found'); } } catch (error) { console.log(` โŒ Login error: ${error.message}`); testResults.failed++; testResults.details.push(`Login: โŒ Error - ${error.message}`); } // Test 2: Access organizer list page console.log('\n2. Testing organizer list page access...'); try { await page.goto(`${config.BASE_URL}/trainer/organizer/list/`); await page.waitForLoadState('networkidle'); const response = await page.goto(`${config.BASE_URL}/trainer/organizer/list/`, { waitUntil: 'networkidle' }); const status = response.status(); if (status === 200) { const pageTitle = await page.locator('h1').textContent(); if (pageTitle && pageTitle.includes('Organizers')) { console.log(' โœ… Organizer list page accessible'); testResults.passed++; testResults.details.push('Organizer List: โœ… Accessible'); } else { console.log(' โŒ Page accessible but title incorrect'); testResults.failed++; testResults.details.push('Organizer List: โŒ Incorrect title'); } } else { console.log(` โŒ Organizer list page returned ${status}`); testResults.failed++; testResults.details.push(`Organizer List: โŒ Status ${status}`); } } catch (error) { console.log(` โŒ Error accessing organizer list: ${error.message}`); testResults.failed++; testResults.details.push(`Organizer List: โŒ ${error.message}`); } // Test 3: Access organizer manage page console.log('\n3. Testing organizer manage page access...'); try { await page.goto(`${config.BASE_URL}/trainer/organizer/manage/`); await page.waitForLoadState('networkidle'); const response = await page.goto(`${config.BASE_URL}/trainer/organizer/manage/`, { waitUntil: 'networkidle' }); const status = response.status(); if (status === 200) { const pageTitle = await page.locator('h1').textContent(); if (pageTitle && (pageTitle.includes('Create') || pageTitle.includes('Organizer'))) { console.log(' โœ… Organizer manage page accessible'); testResults.passed++; testResults.details.push('Organizer Manage: โœ… Accessible'); } else { console.log(' โŒ Page accessible but title incorrect'); testResults.failed++; testResults.details.push('Organizer Manage: โŒ Incorrect title'); } } else { console.log(` โŒ Organizer manage page returned ${status}`); testResults.failed++; testResults.details.push(`Organizer Manage: โŒ Status ${status}`); } } catch (error) { console.log(` โŒ Error accessing organizer manage: ${error.message}`); testResults.failed++; testResults.details.push(`Organizer Manage: โŒ ${error.message}`); } // Test 4: Check shortcode processing console.log('\n4. Testing shortcode processing...'); try { const content = await page.content(); const hasUnprocessedShortcode = content.includes('[hvac_trainer_organizer_manage]'); const hasFormContainer = content.includes('hvac-organizer-manage'); if (!hasUnprocessedShortcode && hasFormContainer) { console.log(' โœ… Shortcode processed correctly'); testResults.passed++; testResults.details.push('Shortcode: โœ… Processed correctly'); } else if (hasUnprocessedShortcode) { console.log(' โŒ Shortcode not processed'); testResults.failed++; testResults.details.push('Shortcode: โŒ Not processed'); } else { console.log(' โŒ Form container not found'); testResults.failed++; testResults.details.push('Shortcode: โŒ Form container not found'); } } catch (error) { console.log(` โŒ Error checking shortcode: ${error.message}`); testResults.failed++; testResults.details.push(`Shortcode: โŒ ${error.message}`); } // Test 5: Check form elements console.log('\n5. Testing form elements...'); try { const form = await page.locator('#hvac-organizer-form'); if (await form.isVisible()) { console.log(' โœ… Main form visible'); // Check required fields const requiredFields = ['org_name', 'hq_city', 'hq_state', 'hq_country']; let fieldsFound = 0; for (const field of requiredFields) { const fieldElement = await page.locator(`#${field}`); if (await fieldElement.isVisible()) { fieldsFound++; } } if (fieldsFound === requiredFields.length) { console.log(' โœ… All required fields present'); testResults.passed++; testResults.details.push('Form Fields: โœ… All present'); } else { console.log(` โŒ Only ${fieldsFound}/${requiredFields.length} required fields found`); testResults.failed++; testResults.details.push(`Form Fields: โŒ Only ${fieldsFound}/${requiredFields.length} found`); } } else { console.log(' โŒ Main form not visible'); testResults.failed++; testResults.details.push('Form Fields: โŒ Form not visible'); } } catch (error) { console.log(` โŒ Error checking form elements: ${error.message}`); testResults.failed++; testResults.details.push(`Form Elements: โŒ ${error.message}`); } // Test 6: Check assets loading console.log('\n6. Testing assets loading...'); try { const content = await page.content(); const cssLoaded = content.includes('hvac-organizers.css') || content.includes('hvac-organizers-style'); const jsLoaded = content.includes('hvac-organizers.js'); if (cssLoaded && jsLoaded) { console.log(' โœ… CSS and JS assets loaded'); testResults.passed++; testResults.details.push('Assets: โœ… CSS and JS loaded'); } else if (cssLoaded) { console.log(' โš ๏ธ CSS loaded but JS missing'); testResults.failed++; testResults.details.push('Assets: โŒ JS missing'); } else if (jsLoaded) { console.log(' โš ๏ธ JS loaded but CSS missing'); testResults.failed++; testResults.details.push('Assets: โŒ CSS missing'); } else { console.log(' โŒ Neither CSS nor JS loaded'); testResults.failed++; testResults.details.push('Assets: โŒ Neither CSS nor JS loaded'); } } catch (error) { console.log(` โŒ Error checking assets: ${error.message}`); testResults.failed++; testResults.details.push(`Assets: โŒ ${error.message}`); } // Test 7: Check navigation console.log('\n7. Testing navigation elements...'); try { const hasNavigation = await page.locator('.hvac-menu, .trainer-menu').isVisible(); const hasBreadcrumbs = await page.locator('.hvac-breadcrumb, .breadcrumb').isVisible(); let navScore = 0; if (hasNavigation) { console.log(' โœ… Navigation menu found'); navScore++; } if (hasBreadcrumbs) { console.log(' โœ… Breadcrumbs found'); navScore++; } if (navScore === 2) { testResults.passed++; testResults.details.push('Navigation: โœ… Menu and breadcrumbs present'); } else if (navScore === 1) { testResults.passed++; testResults.details.push('Navigation: โš ๏ธ Partial navigation present'); } else { testResults.failed++; testResults.details.push('Navigation: โŒ No navigation elements found'); } } catch (error) { console.log(` โŒ Error checking navigation: ${error.message}`); testResults.failed++; testResults.details.push(`Navigation: โŒ ${error.message}`); } } catch (globalError) { console.log(`๐Ÿ’ฅ Global test error: ${globalError.message}`); testResults.failed++; testResults.details.push(`Global: โŒ ${globalError.message}`); } finally { await browser.close(); } // Print results console.log('\n๐Ÿ“Š Test Results Summary'); console.log('======================='); console.log(`โœ… Passed: ${testResults.passed}`); console.log(`โŒ Failed: ${testResults.failed}`); console.log(`โญ๏ธ Skipped: ${testResults.skipped}`); const total = testResults.passed + testResults.failed; const successRate = total > 0 ? Math.round((testResults.passed / total) * 100) : 0; console.log(`๐Ÿ“ˆ Success Rate: ${successRate}%`); console.log('\n๐Ÿ“‹ Detailed Results:'); testResults.details.forEach(detail => { console.log(` ${detail}`); }); if (successRate >= 80) { console.log('\n๐ŸŽ‰ Organizer management functionality is working well!'); } else if (successRate >= 50) { console.log('\nโš ๏ธ Organizer management has some issues but basic functionality works.'); } else { console.log('\nโŒ Organizer management needs significant fixes.'); } return testResults; } // Run the test if (require.main === module) { runComprehensiveOrganizerTest().catch(console.error); } module.exports = runComprehensiveOrganizerTest;