/** * Debug Description Field Population Issue * Investigate why tcepostcontent field isn't being populated by our system */ const { chromium } = require('playwright'); const config = { baseUrl: process.env.UPSKILL_STAGING_URL || 'https://upskill-staging.measurequick.com', testEventId: '10000028', credentials: { username: 'test_trainer', password: 'TestTrainer123!' } }; console.log('๐Ÿ› Debug Description Field Population Issue'); console.log(`๐ŸŽฏ Target Event ID: ${config.testEventId}`); console.log('๐Ÿ” Investigating #tcepostcontent field population'); console.log(''); async function debugDescriptionField() { const browser = await chromium.launch({ headless: true }); // Run in headless mode const context = await browser.newContext({ viewport: { width: 1920, height: 1080 } }); const page = await context.newPage(); // Enable detailed console logging page.on('console', msg => { if (msg.text().includes('HVAC') || msg.text().includes('Description')) { console.log(`๐Ÿ” [Console] ${msg.text()}`); } }); try { // Login console.log('๐Ÿ” Logging in...'); await page.goto(`${config.baseUrl}/training-login/`); await page.fill('input[name="log"]', config.credentials.username); await page.fill('input[name="pwd"]', config.credentials.password); await page.click('button[type="submit"]'); await page.waitForLoadState('networkidle'); // Navigate to event edit page console.log('๐Ÿ“‹ Navigating to event edit page...'); await page.goto(`${config.baseUrl}/trainer/event/manage/?event_id=${config.testEventId}`); await page.waitForSelector('#tribe-community-events'); await page.waitForTimeout(3000); // Let our system run console.log('๐Ÿ› DEBUGGING DESCRIPTION FIELD'); console.log('==============================='); // Step 1: Check if our comprehensive system loaded const systemStatus = await page.evaluate(() => { return { systemLoaded: typeof hvac_event_comprehensive !== 'undefined', eventDataExists: typeof hvac_event_comprehensive !== 'undefined' && hvac_event_comprehensive.event_data !== null, debugMode: typeof hvac_event_comprehensive !== 'undefined' && hvac_event_comprehensive.debug, contentData: typeof hvac_event_comprehensive !== 'undefined' && hvac_event_comprehensive.event_data ? hvac_event_comprehensive.event_data.core?.content : null }; }); console.log('\n๐Ÿ”ง SYSTEM STATUS:'); console.log(`System Loaded: ${systemStatus.systemLoaded ? 'โœ…' : 'โŒ'}`); console.log(`Event Data Exists: ${systemStatus.eventDataExists ? 'โœ…' : 'โŒ'}`); console.log(`Debug Mode: ${systemStatus.debugMode ? 'โœ…' : 'โŒ'}`); console.log(`Content Data Available: ${systemStatus.contentData ? 'โœ…' : 'โŒ'}`); if (systemStatus.contentData) { console.log(`Content: "${systemStatus.contentData.substring(0, 100)}..."`); } // Step 2: Check the tcepostcontent field status const fieldStatus = await page.evaluate(() => { const textarea = document.querySelector('#tcepostcontent'); if (!textarea) return { error: 'Field not found' }; return { exists: true, visible: textarea.offsetHeight > 0 && textarea.offsetWidth > 0, value: textarea.value, placeholder: textarea.placeholder, readOnly: textarea.readOnly, disabled: textarea.disabled, style: { display: getComputedStyle(textarea).display, visibility: getComputedStyle(textarea).visibility, opacity: getComputedStyle(textarea).opacity } }; }); console.log('\n๐Ÿ“ TCEPOSTCONTENT FIELD STATUS:'); console.log('==============================='); if (fieldStatus.error) { console.log(`โŒ ${fieldStatus.error}`); } else { console.log(`Field Exists: โœ…`); console.log(`Visible: ${fieldStatus.visible ? 'โœ…' : 'โŒ'}`); console.log(`Current Value: "${fieldStatus.value}"`); console.log(`Placeholder: "${fieldStatus.placeholder}"`); console.log(`Read Only: ${fieldStatus.readOnly ? 'โŒ' : 'โœ…'}`); console.log(`Disabled: ${fieldStatus.disabled ? 'โŒ' : 'โœ…'}`); console.log(`Display: ${fieldStatus.style.display}`); console.log(`Visibility: ${fieldStatus.style.visibility}`); console.log(`Opacity: ${fieldStatus.style.opacity}`); } // Step 3: Manually test field population console.log('\n๐Ÿงช MANUAL FIELD POPULATION TEST:'); console.log('================================='); const testContent = "This is a test description to verify field population works!"; const populationResult = await page.evaluate((content) => { const textarea = document.querySelector('#tcepostcontent'); if (!textarea) return { error: 'Field not found for population test' }; try { // Try multiple population methods const results = {}; // Method 1: Direct value assignment textarea.value = content; results.directValue = textarea.value === content; // Method 2: Using jQuery if available if (typeof $ !== 'undefined') { $(textarea).val(content + ' (jQuery)'); results.jquery = $(textarea).val().includes('jQuery'); } else { results.jquery = 'jQuery not available'; } // Method 3: Trigger events textarea.dispatchEvent(new Event('input', { bubbles: true })); textarea.dispatchEvent(new Event('change', { bubbles: true })); results.eventsTriggered = true; // Method 4: Focus and blur textarea.focus(); textarea.blur(); results.focusBlur = true; return { success: true, results, finalValue: textarea.value }; } catch (error) { return { error: error.message }; } }, testContent); if (populationResult.error) { console.log(`โŒ Population test failed: ${populationResult.error}`); } else { console.log(`โœ… Population test completed`); console.log(`Direct Value: ${populationResult.results.directValue ? 'โœ…' : 'โŒ'}`); console.log(`jQuery: ${populationResult.results.jquery === true ? 'โœ…' : populationResult.results.jquery === false ? 'โŒ' : 'โš ๏ธ ' + populationResult.results.jquery}`); console.log(`Events Triggered: ${populationResult.results.eventsTriggered ? 'โœ…' : 'โŒ'}`); console.log(`Focus/Blur: ${populationResult.results.focusBlur ? 'โœ…' : 'โŒ'}`); console.log(`Final Value: "${populationResult.finalValue}"`); } // Step 4: Check if TinyMCE is interfering const tinymceStatus = await page.evaluate(() => { return { available: typeof tinymce !== 'undefined', editors: typeof tinymce !== 'undefined' ? Object.keys(tinymce.editors) : [], tcepostcontentEditor: typeof tinymce !== 'undefined' ? (tinymce.get('tcepostcontent') ? true : false) : false }; }); console.log('\n๐Ÿ“ TINYMCE STATUS:'); console.log('=================='); console.log(`TinyMCE Available: ${tinymceStatus.available ? 'โœ…' : 'โŒ'}`); console.log(`Total Editors: ${tinymceStatus.editors.length}`); if (tinymceStatus.editors.length > 0) { console.log(`Editor IDs: ${tinymceStatus.editors.join(', ')}`); } console.log(`tcepostcontent Editor: ${tinymceStatus.tcepostcontentEditor ? 'โœ… (INTERFERENCE POSSIBLE)' : 'โŒ'}`); // Step 5: Try to populate with our actual comprehensive system approach console.log('\n๐Ÿ”„ TESTING COMPREHENSIVE SYSTEM APPROACH:'); console.log('========================================='); const comprehensiveTest = await page.evaluate(() => { if (typeof hvac_event_comprehensive === 'undefined' || !hvac_event_comprehensive.event_data) { return { error: 'Comprehensive system not loaded' }; } const content = hvac_event_comprehensive.event_data.core?.content; if (!content) { return { error: 'No content data available' }; } // Test our comprehensive system's field population function const selectors = [ '#tcepostcontent', 'textarea[name="tcepostcontent"]', '#post_content', 'textarea[name="post_content"]', '.tribe-community-events-form-content textarea', '.wp-editor-area' ]; let field = null; let usedSelector = null; // Find the field using our selectors for (let selector of selectors) { try { const element = document.querySelector(selector); if (element) { field = element; usedSelector = selector; break; } } catch (e) { // Continue to next selector } } if (!field) { return { error: 'No field found with comprehensive system selectors' }; } // Try to populate using comprehensive system logic try { // Handle TinyMCE if present if (typeof tinymce !== 'undefined') { const editor = tinymce.get(field.id); if (editor) { editor.setContent(content); return { success: true, method: 'TinyMCE', selector: usedSelector, finalValue: editor.getContent() }; } } // Handle regular form fields field.value = content; field.dispatchEvent(new Event('change', { bubbles: true })); field.dispatchEvent(new Event('input', { bubbles: true })); return { success: true, method: 'Direct', selector: usedSelector, finalValue: field.value }; } catch (error) { return { error: `Population failed: ${error.message}` }; } }); if (comprehensiveTest.error) { console.log(`โŒ ${comprehensiveTest.error}`); } else { console.log(`โœ… Comprehensive system approach worked!`); console.log(`Method: ${comprehensiveTest.method}`); console.log(`Selector: ${comprehensiveTest.selector}`); console.log(`Final Value: "${comprehensiveTest.finalValue.substring(0, 100)}..."`); } // Wait a bit to see the result await page.waitForTimeout(2000); // Take screenshot for visual verification await page.screenshot({ path: 'test-results/description-field-debug.png', fullPage: true }); console.log('\n๐Ÿ“ธ Screenshot saved: test-results/description-field-debug.png'); console.log('\nโœ… Description field debug completed!'); return { systemStatus, fieldStatus, populationResult, tinymceStatus, comprehensiveTest }; } catch (error) { console.error('โŒ Debug failed:', error); await page.screenshot({ path: 'test-results/description-debug-error.png' }); throw error; } finally { await browser.close(); } } // Run the debug debugDescriptionField() .then(() => { console.log('\n๐ŸŽฏ Description field debug completed successfully'); process.exit(0); }) .catch((error) => { console.error('\n๐Ÿ’ฅ Description field debug failed:', error); process.exit(1); });