import { STAGING_URL, PATHS, TIMEOUTS } from './config/staging-config'; import { test, expect } from '@playwright/test'; import * as dotenv from 'dotenv'; import { resolve } from 'path'; dotenv.config({ path: resolve(__dirname, '../../../../.env') }); test.use({ screenshot: 'on', video: 'on', trace: 'on', actionTimeout: 15000, timeout: 120000 }); test.describe('Debug Event Ownership', () => { const stagingUrl = process.env.UPSKILL_STAGING_URL || 'https://upskill-staging.measurequick.com'; test('create event and verify ownership', async ({ page }) => { const username = 'test_trainer'; const password = 'Test123!'; console.log('Starting event ownership debug test'); // Step 1: Login via wp-admin await page.goto(stagingUrl + '/wp-login.php'); await page.fill('#user_login', username); await page.fill('#user_pass', password); await page.click('#wp-submit'); await page.waitForURL('**/wp-admin/**'); console.log('Logged in successfully'); // Step 2: Create a new event via Community Events form await page.goto(stagingUrl + '/manage-event/'); // Wait for either form or redirect await page.waitForLoadState('networkidle'); const currentUrl = page.url(); console.log('Current URL after navigation:', currentUrl); // Check if we got redirected due to permission issues if (!currentUrl.includes('manage-event')) { console.error('Redirected away from manage-event page:', currentUrl); await page.screenshot({ path: 'manage-event-redirect.png' }); return; } // Wait for form to load await page.waitForSelector('input[name="post_title"]', { state: 'visible', timeout: 30000 }); const testTitle = `Ownership Test ${Date.now()}`; await page.fill('input[name="post_title"]', testTitle); // Fill minimal required fields const tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); const dateStr = tomorrow.toISOString().split('T')[0]; await page.fill('input[name="EventStartDate"]', dateStr); await page.fill('input[name="EventEndDate"]', dateStr); await page.fill('input[name="EventStartTime"]', '10:00'); await page.fill('input[name="EventEndTime"]', '12:00'); // Fill description const descField = await page.locator('textarea[name="tcepostcontent"]').isVisible().catch(() => false); if (descField) { await page.fill('textarea[name="tcepostcontent"]', 'Ownership test event'); } else { const iframe = page.frameLocator('iframe#tcepostcontent_ifr'); await iframe.locator('body').fill('Ownership test event'); } // Submit await page.click('input[type="submit"][value="Submit Event"]'); await page.waitForLoadState('networkidle'); console.log('Event submitted'); // Step 3: Go to WP Admin events list await page.goto(stagingUrl + '/wp-admin/edit.php?post_type=tribe_events'); await page.waitForLoadState('networkidle'); // Find our event const eventRow = await page.locator(`tr:has-text("${testTitle}")`).first(); const rowExists = await eventRow.isVisible().catch(() => false); if (rowExists) { // Get author info const authorText = await eventRow.locator('.author').textContent().catch(() => 'Not found'); console.log('Event author:', authorText); // Click on the event to view details await eventRow.locator('.row-title').click(); await page.waitForLoadState('networkidle'); // Check author in edit screen const authorSelect = await page.locator('#post_author_override').textContent().catch(() => null); console.log('Author in edit screen:', authorSelect); await page.screenshot({ path: 'event-edit-screen.png' }); } else { console.error('Could not find test event in admin list'); } // Step 4: Check dashboard await page.goto(stagingUrl + '/hvac-dashboard/'); await page.waitForLoadState('networkidle'); await page.waitForTimeout(3000); // Get stats const totalEventsSelector = '.hvac-stat-block:has-text("Total Events") .hvac-stat-number, .stat:has-text("Total Events") .number, [class*="total-events"] .number'; const totalEvents = await page.locator(totalEventsSelector).textContent().catch(() => '0'); console.log('Dashboard Total Events:', totalEvents); // Check recent events const recentEventsExist = await page.locator('.hvac-recent-events, .recent-events, [class*="recent"]').isVisible().catch(() => false); console.log('Recent events section exists:', recentEventsExist); if (recentEventsExist) { const eventTitles = await page.locator('.event-title, .hvac-event-title').allTextContents(); console.log('Recent event titles:', eventTitles); const hasOurEvent = eventTitles.some(title => title.includes(testTitle)); console.log('Our test event in recent events:', hasOurEvent); } await page.screenshot({ path: 'dashboard-after-creation.png' }); // Step 5: Check My Events await page.goto(stagingUrl + '/my-events/'); await page.waitForLoadState('networkidle'); const myEventsHasOurEvent = await page.locator(`text="${testTitle}"`).isVisible().catch(() => false); console.log('Test event in My Events:', myEventsHasOurEvent); await page.screenshot({ path: 'my-events-after-creation.png' }); // Summary console.log('\n=== Ownership Test Summary ==='); console.log('Event created:', testTitle); console.log('Dashboard shows events:', totalEvents); console.log('Event visible in My Events:', myEventsHasOurEvent); console.log('Event found in admin:', rowExists); }); });