/** * Debug test for custom event edit template loading * Tests multiple approaches to identify why template isn't loading */ const { chromium } = require('playwright'); async function debugTemplateLoading() { console.log('šŸ” Debugging Custom Event Edit Template Loading...\n'); const browser = await chromium.launch({ headless: false, args: ['--disable-dev-shm-usage', '--no-sandbox'] }); const context = await browser.newContext({ viewport: { width: 1280, height: 720 } }); const page = await context.newPage(); const baseUrl = process.env.UPSKILL_STAGING_URL || 'https://upskill-staging.measurequick.com'; try { // Step 1: Login with correct credentials console.log('1ļøāƒ£ Logging in with JoeMedosch credentials...'); await page.goto(`${baseUrl}/training-login/`); await page.waitForLoadState('networkidle'); await page.fill('input[name="log"]', 'JoeMedosch@gmail.com'); await page.fill('input[name="pwd"]', 'JoeTrainer2025@'); const submitButton = await page.$('input[type="submit"]') || await page.$('button[type="submit"]') || await page.$('#wp-submit'); if (submitButton) { await submitButton.click(); } await page.waitForTimeout(3000); console.log('āœ… Login submitted\n'); // Step 2: Test different URL patterns console.log('2ļøāƒ£ Testing different URL patterns...\n'); const urlPatterns = [ '/trainer/event/edit/?event_id=6161', '/trainer/event/edit?event_id=6161', '/trainer/event/edit/', '/trainer/event/edit', ]; for (const pattern of urlPatterns) { console.log(`Testing: ${pattern}`); await page.goto(`${baseUrl}${pattern}`); await page.waitForLoadState('networkidle'); // Check what loaded const pageTitle = await page.title(); const customForm = await page.$('.hvac-event-edit-wrapper'); const tecForm = await page.$('.tribe-community-events'); const content = await page.content(); console.log(` Title: ${pageTitle}`); console.log(` Custom form: ${customForm ? 'āœ… Found' : 'āŒ Not found'}`); console.log(` TEC form: ${tecForm ? 'āš ļø Found' : 'āœ… Not found'}`); // Check for specific indicators if (content.includes('hvac-event-edit-wrapper')) { console.log(' āœ… Custom template HTML detected'); } if (content.includes('404') || content.includes('Page not found')) { console.log(' āŒ 404 error'); } if (content.includes('')) { console.log(' āœ… Template comment marker found'); } console.log(''); } // Step 3: Check page structure console.log('3ļøāƒ£ Checking page structure at /trainer/event/edit/?event_id=6161...\n'); await page.goto(`${baseUrl}/trainer/event/edit/?event_id=6161`); await page.waitForLoadState('networkidle'); // Check body classes const bodyClasses = await page.evaluate(() => document.body.className); console.log(`Body classes: ${bodyClasses}`); // Check for WordPress admin bar const adminBar = await page.$('#wpadminbar'); console.log(`Admin bar: ${adminBar ? 'Present' : 'Not present'}`); // Check page ID const pageId = await page.evaluate(() => { const bodyClass = document.body.className; const match = bodyClass.match(/page-id-(\d+)/); return match ? match[1] : null; }); console.log(`Page ID from body class: ${pageId || 'Not found'}`); // Check template const templateClass = await page.evaluate(() => { const bodyClass = document.body.className; const match = bodyClass.match(/page-template-([^ ]+)/); return match ? match[1] : null; }); console.log(`Template class: ${templateClass || 'Not found'}`); // Step 4: Check page content structure console.log('\n4ļøāƒ£ Analyzing page content structure...\n'); // Check for main content area const mainContent = await page.$('#main') || await page.$('.site-main') || await page.$('[role="main"]'); if (mainContent) { console.log('āœ… Main content area found'); // Get the HTML of main content const mainHtml = await mainContent.evaluate(el => el.innerHTML.substring(0, 500)); console.log('Main content preview:'); console.log(mainHtml); } else { console.log('āŒ Main content area not found'); } // Step 5: Check for form elements console.log('\n5ļøāƒ£ Checking for form elements...\n'); const formSelectors = { 'Custom wrapper': '.hvac-event-edit-wrapper', 'Form element': 'form.hvac-event-form', 'Title field': '#post_title', 'Start date': '#EventStartDate', 'Submit button': 'button[type="submit"]', 'Nonce field': 'input[name="hvac_event_nonce"]' }; for (const [name, selector] of Object.entries(formSelectors)) { const element = await page.$(selector); console.log(`${name}: ${element ? 'āœ… Found' : 'āŒ Not found'}`); } // Step 6: Take screenshot for visual inspection console.log('\n6ļøāƒ£ Taking screenshot for inspection...\n'); const timestamp = Date.now(); await page.screenshot({ path: `template-debug-${timestamp}.png`, fullPage: true }); console.log(`šŸ“ø Screenshot saved as template-debug-${timestamp}.png`); // Step 7: Check console errors console.log('\n7ļøāƒ£ Checking for console errors...\n'); page.on('console', msg => { if (msg.type() === 'error') { console.log(`Console error: ${msg.text()}`); } }); // Reload to catch any console errors await page.reload(); await page.waitForTimeout(2000); console.log('\nāœ… Debug test complete!'); } catch (error) { console.error('\nāŒ Debug test failed:', error.message); await page.screenshot({ path: `template-debug-error-${Date.now()}.png`, fullPage: true }); console.log('šŸ“ø Error screenshot saved'); throw error; } finally { await browser.close(); } } // Run debug test debugTemplateLoading() .then(() => { console.log('\n✨ Debug test completed successfully!'); process.exit(0); }) .catch(error => { console.error('\nšŸ’„ Debug test failed:', error); process.exit(1); });