import { STAGING_URL, PATHS, TIMEOUTS } from './config/staging-config';
import { test, expect } from '@playwright/test';

test.describe('Plugin Activation Verification', () => {
  test('verify plugin is enabled and appears in plugins list', async ({ page }) => {
    // Navigate to the admin plugins page
    await page.goto('https://upskill-staging.measurequick.com/wp-admin/plugins.php');
    
    // Login as admin
    await page.fill('#user_login', process.env.STAGING_ADMIN_USER || 'admin');
    await page.fill('#user_pass', process.env.STAGING_ADMIN_PASSWORD || 'upskill');
    await page.click('#wp-submit');
    
    // Wait for admin plugins page to load
    await page.waitForSelector('.plugins');
    
    // Check if the HVAC Community Events plugin is active
    const pluginRow = await page.locator('tr[data-slug="hvac-community-events"]');
    await expect(pluginRow).toBeVisible();
    
    // Check if the plugin is active
    const isActive = await pluginRow.locator('.active').isVisible();
    expect(isActive).toBeTruthy();
    
    console.log('Plugin is active in the plugins list');
  });
  
  test('verify plugin menu appears in sidebar', async ({ page }) => {
    // Navigate to the WordPress admin
    await page.goto('https://upskill-staging.measurequick.com/wp-admin/');
    
    // Login as admin if not already logged in
    if (await page.locator('#user_login').isVisible()) {
      await page.fill('#user_login', process.env.STAGING_ADMIN_USER || 'admin');
      await page.fill('#user_pass', process.env.STAGING_ADMIN_PASSWORD || 'upskill');
      await page.click('#wp-submit');
    }
    
    // Take a screenshot of the admin menu
    await page.screenshot({ path: 'admin-menu.png' });
    
    // Look for any admin menu items
    const menuItems = await page.locator('#adminmenu li').count();
    console.log(`Found ${menuItems} admin menu items`);
    
    // Dump the entire menu HTML to diagnose issues
    const menuHTML = await page.locator('#adminmenu').innerHTML();
    console.log('Admin menu HTML:', menuHTML);
  });
});