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

test.describe('用户相关页面', () => {
  const userPages = [
    { path: '/my', title: '我的' },
    { path: '/my/learning', title: '学习进度' },
    { path: '/my/favorites', title: '收藏夹' },
    { path: '/my/member', title: '会员中心' },
    { path: '/my/settings', title: '设置' },
    { path: '/my/dashboard', title: '数据看板' },
    { path: '/notifications', title: '通知' },
  ];

  for (const { path, title } of userPages) {
    test.describe(`${path}`, () => {
      test.beforeEach(async ({ page }) => {
        await page.goto(path);
      });

      test('页面标题元素存在', async ({ page }) => {
        const anyHeading = page.locator('h1, h2, h3, h4, [class*="text-2xl"], [class*="text-3xl"]');
        const count = await anyHeading.count();
        expect(count).toBeGreaterThanOrEqual(1);
      });

      test('无错误展示', async ({ page }) => {
        await expect(page.locator('body')).not.toHaveText(/500/);
        await expect(page.locator('body')).not.toHaveText(/Application Error/);
      });
    });
  }
});
