const { test, expect } = require('@playwright/test');

const WP_ADMIN_USER = 'playwright';
const WP_ADMIN_PASSWORD = '%Pzx*H1F(U79q6lQXsU)Ofxl';
const SITE_URL = 'https://streamers.channel';

test.describe('WordPress Login', () => {
  test('should login to WordPress admin', async ({ page }) => {
    // Navigate to WordPress login page
    await page.goto(`${SITE_URL}/wp-login.php`);
    
    // Fill in login credentials
    await page.fill('#user_login', WP_ADMIN_USER);
    await page.fill('#user_pass', WP_ADMIN_PASSWORD);
    
    // Click login button
    await page.click('#wp-submit');
    
    // Wait for dashboard to load
    await page.waitForURL(/wp-admin/);
    
    // Verify we're logged in
    await expect(page).toHaveURL(/wp-admin/);
    await expect(page.locator('#wpadminbar')).toBeVisible();
  });

  test('should access plugins page', async ({ page }) => {
    // First login
    await page.goto(`${SITE_URL}/wp-login.php`);
    await page.fill('#user_login', WP_ADMIN_USER);
    await page.fill('#user_pass', WP_ADMIN_PASSWORD);
    await page.click('#wp-submit');
    await page.waitForURL(/wp-admin/);
    
    // Navigate to plugins page
    await page.goto(`${SITE_URL}/wp-admin/plugins.php`);
    
    // Verify plugins page loaded
    await expect(page).toHaveURL(/plugins\.php/);
    await expect(page.locator('.wp-list-table.plugins')).toBeVisible();
  });
});