/** * Test script for verifying the new create/edit event pages with authentication * Tests REST API enhancement and field population */ const { chromium } = require('playwright'); async function loginAsTrainer(page) { console.log('š Logging in as test trainer...'); // Go to login page await page.goto('https://upskill-staging.measurequick.com/trainer/training-login/', { waitUntil: 'networkidle', timeout: 30000 }); // Fill login form await page.fill('#username, #user_login, input[name="log"]', 'test_trainer'); await page.fill('#password, #user_pass, input[name="pwd"]', 'TestTrainer123!'); // Submit form await page.click('input[type="submit"], button[type="submit"]'); // Wait for navigation await page.waitForTimeout(3000); console.log(' Logged in successfully'); } (async () => { const browser = await chromium.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const context = await browser.newContext({ ignoreHTTPSErrors: true }); const page = await context.newPage(); console.log('š Testing Create/Edit Event Pages with Authentication...\n'); try { // Login first await loginAsTrainer(page); // Test 1: Check if create-event page exists and renders correctly console.log('\nš Test 1: Checking create-event page (authenticated)...'); await page.goto('https://upskill-staging.measurequick.com/trainer/create-event/', { waitUntil: 'networkidle', timeout: 30000 }); const createPageTitle = await page.title(); console.log(` Page title: ${createPageTitle}`); // Check page content const pageContent = await page.evaluate(() => { return { hasH1: document.querySelector('h1')?.textContent, hasNotice: document.querySelector('.hvac-form-notice')?.textContent?.trim(), hasNavMenu: !!document.querySelector('.hvac-nav-menu, .hvac-trainer-navigation'), bodyClasses: document.body.className }; }); console.log(` H1 Title: "${pageContent.hasH1}"`); console.log(` Notice: ${pageContent.hasNotice ? '"' + pageContent.hasNotice + '"' : 'Not found'}`); console.log(` Navigation menu: ${pageContent.hasNavMenu ? 'ā ' : 'ā'}`); console.log(` Body classes: ${pageContent.bodyClasses}`); // Check if TEC form is present const formCheck = await page.evaluate(() => { return { hasTribeForm: !!document.querySelector('#tribe-community-events'), hasTribeContainer: !!document.querySelector('.tribe-events-community'), hasFormTag: !!document.querySelector('form'), formAction: document.querySelector('form')?.action, formMethod: document.querySelector('form')?.method }; }); console.log('\n Form presence check:'); console.log(` - #tribe-community-events: ${formCheck.hasTribeForm ? 'ā ' : 'ā'}`); console.log(` - .tribe-events-community: ${formCheck.hasTribeContainer ? 'ā ' : 'ā'}`); console.log(` -