upskill-event-manager/wordpress-dev/tests/e2e/trainer-journey-simplified.test.ts

185 lines
No EOL
8.1 KiB
TypeScript

import { STAGING_URL, PATHS, TIMEOUTS } from './config/staging-config';
import { test, expect } from '@playwright/test';
// STAGING_URL is now imported from config
test.describe('Trainer User Journey - Simplified', () => {
test('Step 4a: Create Event - Direct', async ({ page }) => {
// Login
await page.goto(PATHS.login);
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'Test123!');
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Navigate to event creation page
await page.goto(`${STAGING_URL}/manage-event/`);
await page.waitForLoadState('networkidle');
// Fill event details
await page.fill('#post_title, input[name="post_title"]', 'HVAC Training Event');
// Fill description
try {
const frame = page.frameLocator('iframe[id$="_ifr"]');
await frame.locator('body').fill('This is a test HVAC training event.');
} catch (e) {
await page.fill('#tcepostcontent, textarea[name="post_content"]', 'This is a test HVAC training event.');
}
// Fill dates
await page.fill('input[name="EventStartDate"]', '01/20/2025');
await page.fill('input[name="EventStartTime"]', '10:00 AM');
await page.fill('input[name="EventEndDate"]', '01/20/2025');
await page.fill('input[name="EventEndTime"]', '12:00 PM');
// Set venue and organizer to "Use New..." if dropdowns exist
const venueSelector = await page.locator('select#saved_tribe_venue');
if (await venueSelector.count() > 0) {
await venueSelector.selectOption('-1');
// Fill venue details if fields appear
const venueNameField = await page.locator('input[name="Venue[Venue]"]');
if (await venueNameField.isVisible()) {
await venueNameField.fill('HVAC Training Center');
await page.fill('input[name="Venue[City]"]', 'Austin');
await page.fill('input[name="Venue[State]"]', 'TX');
await page.fill('input[name="Venue[Zip]"]', '78701');
}
}
const organizerSelector = await page.locator('select#saved_tribe_organizer');
if (await organizerSelector.count() > 0) {
await organizerSelector.selectOption('-1');
// Fill organizer details if fields appear
const organizerNameField = await page.locator('input[name="Organizer[Organizer]"]');
if (await organizerNameField.isVisible()) {
await organizerNameField.fill('Test Trainer');
await page.fill('input[name="Organizer[Email]"]', 'trainer@test.com');
await page.fill('input[name="Organizer[Phone]"]', '555-0123');
}
}
// Submit the form
await page.click('input[value="Submit Event"], button:has-text("Submit Event")');
await page.waitForLoadState('networkidle');
await page.waitForTimeout(3000);
// Check for success
const viewYourEventsButton = await page.locator('text="VIEW YOUR SUBMITTED EVENTS"').isVisible().catch(() => false);
console.log('View Your Events button visible:', viewYourEventsButton);
const currentUrl = page.url();
console.log('Current URL:', currentUrl);
await page.screenshot({ path: 'test-results/screenshots/event-created-simplified.png' });
expect(viewYourEventsButton).toBeTruthy();
});
test('Step 4c: Modify Event from My Events', async ({ page }) => {
// Login
await page.goto(PATHS.login);
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'Test123!');
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Navigate to My Events
await page.goto(`${STAGING_URL}/my-events/`);
await page.waitForLoadState('networkidle');
// Check for events in upcoming or past tabs
const tabs = ['UPCOMING EVENTS', 'PAST EVENTS'];
let foundEvent = false;
for (const tab of tabs) {
const tabLink = page.locator(`a:has-text("${tab}")`);
if (await tabLink.count() > 0) {
await tabLink.click();
await page.waitForLoadState('networkidle');
const eventRows = page.locator('tr.community-events-event-row');
if (await eventRows.count() > 0) {
foundEvent = true;
// Click Edit on the first event
const editLink = eventRows.first().locator('a:has-text("Edit")');
if (await editLink.count() > 0) {
await editLink.click();
await page.waitForLoadState('networkidle');
// Modify the event
await page.fill('input[name="post_title"]', 'Updated HVAC Training Event');
// Submit the update
const updateButton = page.locator('input[value="Update"], input[value="Submit Event"]');
await updateButton.click();
await page.waitForLoadState('networkidle');
await page.screenshot({ path: 'test-results/screenshots/event-modified.png' });
break;
}
}
}
}
expect(foundEvent).toBeTruthy();
});
test('Step 4d: Delete Event from Edit Page', async ({ page }) => {
// Login
await page.goto(PATHS.login);
await page.fill('#user_login', 'test_trainer');
await page.fill('#user_pass', 'Test123!');
await page.click('#wp-submit');
await page.waitForLoadState('networkidle');
// Navigate to My Events
await page.goto(`${STAGING_URL}/my-events/`);
await page.waitForLoadState('networkidle');
// Find an event to delete
const tabs = ['UPCOMING EVENTS', 'PAST EVENTS'];
let deletedEvent = false;
for (const tab of tabs) {
const tabLink = page.locator(`a:has-text("${tab}")`);
if (await tabLink.count() > 0) {
await tabLink.click();
await page.waitForLoadState('networkidle');
const eventRows = page.locator('tr.community-events-event-row');
const initialCount = await eventRows.count();
if (initialCount > 0) {
// Click Edit on the first event
const editLink = eventRows.first().locator('a:has-text("Edit")');
if (await editLink.count() > 0) {
await editLink.click();
await page.waitForLoadState('networkidle');
// Look for delete options
const deleteLink = page.locator('a:has-text("Delete Event"), a:has-text("Move to Trash")');
if (await deleteLink.count() > 0) {
await deleteLink.click();
// Handle confirmation if present
const confirmButton = page.locator('button:has-text("Yes"), button:has-text("OK")');
if (await confirmButton.isVisible()) {
await confirmButton.click();
}
await page.waitForLoadState('networkidle');
deletedEvent = true;
await page.screenshot({ path: 'test-results/screenshots/event-deleted.png' });
break;
}
}
}
}
}
expect(deletedEvent).toBeTruthy();
});
});