/** * Test Organizer Management Functionality * * This script tests the organizer management page to verify: * 1. Page loads correctly * 2. Shortcode is processed * 3. Form elements are present * 4. CRUD functionality works */ const { chromium } = require('playwright'); async function testOrganizerManagement() { console.log('๐Ÿงช Testing Organizer Management Functionality\n'); const browser = await chromium.launch({ headless: process.env.HEADLESS !== 'false', timeout: 30000 }); const page = await browser.newPage(); const BASE_URL = process.env.BASE_URL || 'http://localhost:8080'; try { console.log('๐Ÿ“‹ Test Results:'); console.log('================'); // Test 1: Check if organizer manage page exists console.log('\n1. Testing page accessibility...'); const response = await page.goto(`${BASE_URL}/trainer/organizer/manage/`, { waitUntil: 'networkidle', timeout: 15000 }); const status = response.status(); console.log(` Status: ${status} ${status === 200 ? 'โœ…' : 'โŒ'}`); if (status === 404) { console.log(' โŒ Page not found - WordPress pages may not be created'); console.log(' ๐Ÿ’ก Solution: Run HVAC_Page_Manager::create_required_pages()'); return; } if (status !== 200) { console.log(` โŒ Unexpected status: ${status}`); return; } // Test 2: Check for shortcode processing console.log('\n2. Testing shortcode processing...'); await page.waitForTimeout(3000); const content = await page.content(); const hasUnprocessedShortcode = content.includes('[hvac_trainer_organizer_manage]'); const hasFormContainer = content.includes('hvac-organizer-manage'); const hasOrgForm = content.includes('hvac-organizer-form'); const hasOrgNameField = content.includes('org_name') || content.includes('Organization Name'); console.log(` Shortcode not processed: ${hasUnprocessedShortcode ? 'โŒ' : 'โœ…'}`); console.log(` Has form container: ${hasFormContainer ? 'โœ…' : 'โŒ'}`); console.log(` Has organizer form: ${hasOrgForm ? 'โœ…' : 'โŒ'}`); console.log(` Has org name field: ${hasOrgNameField ? 'โœ…' : 'โŒ'}`); if (hasUnprocessedShortcode) { console.log(' โŒ Shortcode is not being processed'); console.log(' ๐Ÿ’ก Check: HVAC_Organizers class instantiation and shortcode registration'); } // Test 3: Check for required form elements if (hasFormContainer || hasOrgForm) { console.log('\n3. Testing form elements...'); const requiredElements = [ 'input[name="org_name"]', 'textarea[name="org_description"]', 'input[name="hq_city"]', 'input[name="hq_state"]', 'select[name="hq_country"]', 'input[name="org_email"]', 'input[name="org_website"]' ]; for (const selector of requiredElements) { const exists = await page.locator(selector).count() > 0; const fieldName = selector.replace(/input\[name="([^"]+)"\]/, '$1').replace(/textarea\[name="([^"]+)"\]/, '$1').replace(/select\[name="([^"]+)"\]/, '$1'); console.log(` ${fieldName}: ${exists ? 'โœ…' : 'โŒ'}`); } } else { console.log('\n3. โŒ Cannot test form elements - form not found'); } // Test 4: Check for CSS and JS assets console.log('\n4. Testing assets...'); const cssLoaded = content.includes('hvac-organizers.css') || content.includes('hvac-organizers-style'); const jsLoaded = content.includes('hvac-organizers.js'); console.log(` CSS loaded: ${cssLoaded ? 'โœ…' : 'โŒ'}`); console.log(` JS loaded: ${jsLoaded ? 'โœ…' : 'โŒ'}`); // Test 5: Check for navigation and breadcrumbs console.log('\n5. Testing navigation...'); const hasNavigation = content.includes('hvac-menu') || content.includes('trainer-menu'); const hasBreadcrumbs = content.includes('breadcrumb') || content.includes('hvac-breadcrumb'); console.log(` Has navigation: ${hasNavigation ? 'โœ…' : 'โŒ'}`); console.log(` Has breadcrumbs: ${hasBreadcrumbs ? 'โœ…' : 'โŒ'}`); // Summary console.log('\n๐Ÿ“Š Summary:'); console.log('==========='); const tests = [ { name: 'Page accessible', passed: status === 200 }, { name: 'Shortcode processed', passed: !hasUnprocessedShortcode }, { name: 'Form container present', passed: hasFormContainer || hasOrgForm }, { name: 'Form fields present', passed: hasOrgNameField }, { name: 'Assets loaded', passed: cssLoaded && jsLoaded } ]; const passedTests = tests.filter(t => t.passed).length; const totalTests = tests.length; console.log(`\nPassed: ${passedTests}/${totalTests} tests`); if (passedTests === totalTests) { console.log('๐ŸŽ‰ All tests passed! Organizer management is working correctly.'); } else { console.log('โš ๏ธ Some tests failed. Issues found:'); tests.filter(t => !t.passed).forEach(t => { console.log(` - ${t.name}`); }); } // Get page title for reference const title = await page.title(); console.log(`\nPage title: "${title}"`); } catch (error) { console.error('\nโŒ Test failed with error:', error.message); if (error.message.includes('ERR_CONNECTION_REFUSED')) { console.log('๐Ÿ’ก Solution: Start the testing environment with: docker compose -f tests/docker-compose.test.yml up -d'); } } finally { await browser.close(); } } // Run the test testOrganizerManagement().catch(console.error);