/** * Enhanced Field Deployment Validation Test with Authentication * * Tests that all 4 enhanced field sections are properly deployed and accessible: * - Excerpt field with character counter * - Categories multi-select with search * - Featured image upload with media library * - Tags with autocomplete functionality * * This version logs in as a trainer first to access the TEC form */ const { chromium } = require('playwright'); async function testEnhancedFieldDeploymentWithAuth() { console.log('๐Ÿงช Testing Enhanced Field Deployment (with Authentication)...'); const browser = await chromium.launch({ headless: true, slowMo: 500 }); try { const context = await browser.newContext({ viewport: { width: 1200, height: 800 } }); const page = await context.newPage(); // Enable console logging page.on('console', msg => { if (msg.type() === 'log' || msg.type() === 'error') { console.log(`๐Ÿ–ฅ๏ธ ${msg.text()}`); } }); // Step 1: Login as trainer first console.log('๐Ÿ” Step 1: Logging in as trainer...'); await page.goto('https://upskill-staging.measurequick.com/training-login/'); await page.waitForTimeout(2000); // Fill login form await page.fill('#user_login', 'test_trainer'); await page.fill('#user_pass', 'TestTrainer123!'); await page.click('#wp-submit'); // Wait for login redirect await page.waitForTimeout(3000); // Verify login success const currentUrl = page.url(); if (currentUrl.includes('dashboard')) { console.log('โœ… Login successful - redirected to dashboard'); } else { console.log('โš ๏ธ Login redirect unclear, continuing...'); } // Step 2: Navigate to TEC form - try authenticated URLs console.log('\n๐ŸŒ Step 2: Accessing TEC event form...'); const authTestUrls = [ 'https://upskill-staging.measurequick.com/?events-community=add', 'https://upskill-staging.measurequick.com/events/community/add/', 'https://upskill-staging.measurequick.com/trainer/add-event/', 'https://upskill-staging.measurequick.com/event-add/', 'https://upskill-staging.measurequick.com/submit-event/' ]; let formFound = false; let workingUrl = ''; for (const url of authTestUrls) { console.log(`๐ŸŒ Testing authenticated URL: ${url}`); try { await page.goto(url); await page.waitForTimeout(2000); // Check for TEC form elements const tecSelectors = [ '#tribe-community-events-form', '.tribe-community-events', '#tribe-events-community-edit-form', 'form[data-datepicker_format]', '[name="post_title"]', '[name="post_content"]' ]; for (const selector of tecSelectors) { try { const element = await page.waitForSelector(selector, { timeout: 2000 }); if (element) { console.log(`โœ… Found TEC form element: ${selector}`); formFound = true; workingUrl = url; break; } } catch (e) { // Continue to next selector } } if (formFound) break; } catch (error) { console.log(`โŒ URL failed: ${error.message}`); } } if (!formFound) { console.log('โŒ TEC form not found even with authentication'); // Try to find form through navigation console.log('๐Ÿ” Checking dashboard for event creation links...'); await page.goto('https://upskill-staging.measurequick.com/trainer/dashboard/'); await page.waitForTimeout(2000); // Look for add event links const links = await page.$$eval('a', links => links.filter(link => link.textContent.toLowerCase().includes('add') || link.textContent.toLowerCase().includes('create') || link.textContent.toLowerCase().includes('submit') || link.href.includes('event') ).map(link => ({ text: link.textContent.trim(), href: link.href })) ); console.log('๐Ÿ”— Found potential event links:'); links.forEach(link => { console.log(` - "${link.text}": ${link.href}`); }); // Try the first promising link if (links.length > 0) { const firstLink = links[0]; console.log(`๐ŸŽฏ Trying first link: ${firstLink.href}`); await page.goto(firstLink.href); await page.waitForTimeout(2000); // Check again for form for (const selector of ['#tribe-community-events-form', '.tribe-community-events', 'form[data-datepicker_format]']) { try { const element = await page.waitForSelector(selector, { timeout: 2000 }); if (element) { console.log(`โœ… Found TEC form via dashboard link: ${selector}`); formFound = true; workingUrl = firstLink.href; break; } } catch (e) { // Continue } } } } if (!formFound) { await page.screenshot({ path: '/home/ben/dev/upskill-event-manager/test-results/tec-form-not-found.png', fullPage: true }); return { success: false, error: 'TEC Community Events form not accessible even with authentication' }; } console.log(`๐ŸŽฏ TEC Form found at: ${workingUrl}`); // Step 3: Test Enhanced Template and Fields console.log('\n๐Ÿงช Step 3: Testing Enhanced Template and Fields...'); // Test Results const testResults = { enhancedTemplate: false, excerptField: false, categoriesField: false, featuredImageField: false, tagsField: false }; // 1. Check for enhanced template indicator console.log('\n1๏ธโƒฃ Testing Enhanced Template Indicator...'); try { const enhancedIndicator = await page.waitForSelector('.hvac-success-indicator', { timeout: 5000 }); if (enhancedIndicator) { const indicatorText = await enhancedIndicator.textContent(); console.log(`โœ… Enhanced template active: ${indicatorText}`); testResults.enhancedTemplate = true; } } catch (error) { console.log('โŒ Enhanced template indicator not found'); // Check if we're seeing the standard TEC form try { const standardForm = await page.waitForSelector('#tribe-community-events-form', { timeout: 2000 }); if (standardForm) { console.log('๐Ÿ“‹ Standard TEC form detected - enhanced template not overriding'); } } catch (e) { console.log('โš ๏ธ No recognizable TEC form structure found'); } } // 2. Test Excerpt Field console.log('\n2๏ธโƒฃ Testing Excerpt Field...'); try { // Check for excerpt section const excerptSection = await page.waitForSelector('#hvac-excerpt-section', { timeout: 3000 }); if (excerptSection) { console.log('โœ… Excerpt section found'); // Check for textarea const excerptTextarea = await page.querySelector('#hvac_post_excerpt'); if (excerptTextarea) { console.log('โœ… Excerpt textarea found'); // Test character counter await excerptTextarea.fill('Test excerpt content for enhanced field validation'); await page.waitForTimeout(500); const characterCounter = await page.querySelector('#excerpt-counter .current-count'); if (characterCounter) { const count = await characterCounter.textContent(); console.log(`โœ… Character counter working: ${count} characters`); testResults.excerptField = true; } } } } catch (error) { console.log('โŒ Excerpt field not accessible'); } // 3. Test Categories Field console.log('\n3๏ธโƒฃ Testing Categories Field...'); try { const categoriesSection = await page.waitForSelector('#hvac-categories-section', { timeout: 3000 }); if (categoriesSection) { console.log('โœ… Categories section found'); // Check for categories search const searchInput = await page.querySelector('#hvac_categories_search'); if (searchInput) { console.log('โœ… Categories search input found'); // Test search functionality await searchInput.fill('hvac'); await page.waitForTimeout(500); // Check for categories checkboxes const categoryCheckboxes = await page.$$('.hvac-category-checkbox'); if (categoryCheckboxes.length > 0) { console.log(`โœ… Found ${categoryCheckboxes.length} category checkboxes`); testResults.categoriesField = true; } } } } catch (error) { console.log('โŒ Categories field not accessible'); } // 4. Test Featured Image Field console.log('\n4๏ธโƒฃ Testing Featured Image Field...'); try { const featuredImageSection = await page.waitForSelector('#hvac-featured-image-section', { timeout: 3000 }); if (featuredImageSection) { console.log('โœ… Featured image section found'); // Check for upload button const uploadButton = await page.querySelector('#hvac-upload-image-btn'); if (uploadButton) { console.log('โœ… Image upload button found'); // Check for hidden input const hiddenInput = await page.querySelector('#hvac_featured_image_id'); if (hiddenInput) { console.log('โœ… Featured image hidden input found'); testResults.featuredImageField = true; } } } } catch (error) { console.log('โŒ Featured image field not accessible'); } // 5. Test Tags Field console.log('\n5๏ธโƒฃ Testing Tags Field...'); try { const tagsSection = await page.waitForSelector('#hvac-tags-section', { timeout: 3000 }); if (tagsSection) { console.log('โœ… Tags section found'); // Check for tags input const tagsInput = await page.querySelector('#hvac_tags_input'); if (tagsInput) { console.log('โœ… Tags input found'); // Test autocomplete functionality await tagsInput.fill('hv'); await page.waitForTimeout(500); // Check for suggestions dropdown const suggestionsContainer = await page.querySelector('#hvac-tags-suggestions'); if (suggestionsContainer) { console.log('โœ… Tags suggestions container found'); testResults.tagsField = true; } } } } catch (error) { console.log('โŒ Tags field not accessible'); } // Take screenshot for visual verification console.log('\n๐Ÿ“ธ Taking screenshot for visual verification...'); await page.screenshot({ path: '/home/ben/dev/upskill-event-manager/test-results/enhanced-field-deployment-auth.png', fullPage: true }); // Calculate success rate const successfulFields = Object.values(testResults).filter(Boolean).length; const totalFields = Object.keys(testResults).length; const successRate = Math.round((successfulFields / totalFields) * 100); // Final report console.log('\n๐Ÿ“Š Enhanced Field Deployment Test Results (Authenticated):'); console.log('='.repeat(60)); console.log(`Enhanced Template: ${testResults.enhancedTemplate ? 'โœ…' : 'โŒ'}`); console.log(`Excerpt Field: ${testResults.excerptField ? 'โœ…' : 'โŒ'}`); console.log(`Categories Field: ${testResults.categoriesField ? 'โœ…' : 'โŒ'}`); console.log(`Featured Image Field: ${testResults.featuredImageField ? 'โœ…' : 'โŒ'}`); console.log(`Tags Field: ${testResults.tagsField ? 'โœ…' : 'โŒ'}`); console.log('='.repeat(60)); console.log(`Success Rate: ${successfulFields}/${totalFields} (${successRate}%)`); console.log(`Working TEC URL: ${workingUrl}`); if (successRate === 100) { console.log('\n๐ŸŽ‰ ALL ENHANCED FIELDS SUCCESSFULLY DEPLOYED!'); console.log('โœ… 100% field control achieved'); console.log('โœ… WordPress core fields accessible'); console.log('โœ… Enhanced template fully functional'); } else if (successRate > 0) { console.log('\nโš ๏ธ PARTIAL DEPLOYMENT SUCCESS'); console.log(`โœ… ${successfulFields} enhanced fields working`); console.log(`โŒ ${totalFields - successfulFields} fields need debugging`); } else { console.log('\nโŒ ENHANCED TEMPLATE NOT ACTIVE'); console.log('๐Ÿ”ง Template override not working - using standard TEC form'); console.log('๐Ÿ’ก Possible issues:'); console.log(' - Theme template not properly deployed'); console.log(' - Template hierarchy not working'); console.log(' - TEC caching preventing override'); } return { success: successRate === 100, successRate, results: testResults, workingUrl: workingUrl }; } catch (error) { console.error('โŒ Test failed:', error); return { success: false, error: error.message }; } finally { await browser.close(); } } // Run the test if (require.main === module) { testEnhancedFieldDeploymentWithAuth() .then(result => { console.log('\n๐Ÿ Enhanced Field Deployment Test Completed'); process.exit(result.success ? 0 : 1); }) .catch(error => { console.error('โŒ Test runner failed:', error); process.exit(1); }); } module.exports = { testEnhancedFieldDeploymentWithAuth };