import { test, expect } from '@playwright/test';

test.describe('冒烟测试 - 基础流程', () => {
  test.use({ storageState: { cookies: [], origins: [] } });
  
  test('管理员登录和登出', async ({ page }) => {
    await test.step('导航到登录页面', async () => {
      await page.goto('/login');
      await page.waitForLoadState('networkidle');
    });

    await test.step('输入登录信息', async () => {
      await page.fill('input[type="text"]', 'admin');
      await page.fill('input[type="password"]', 'Test@123');
    });

    await test.step('点击登录按钮', async () => {
      await page.click('button:has-text("登录")');
      await page.waitForURL(/.*dashboard/, { timeout: 10000 });
    });

    await test.step('验证登录成功', async () => {
      await expect(page).toHaveURL(/.*dashboard/);
    });

    await test.step('点击用户菜单', async () => {
      const avatarButton = page.locator('.el-avatar').first();
      await avatarButton.click();
      await page.waitForTimeout(500);
    });

    await test.step('点击退出登录', async () => {
      await page.click('text=退出登录');
      await page.waitForURL(/.*login/, { timeout: 10000 });
    });

    await test.step('验证登出成功', async () => {
      await expect(page).toHaveURL(/.*login/);
    });
  });
});
