home.spec.ts 2.5 KB
import { expect, test } from '@playwright/test';

const useRealApi = process.env.E2E_SINGLE_PAGE_API_MODE === 'real';

const homeFixture = {
  site_title: 'AI Agent 招聘站',
  site_subtitle: '用智能体提升岗位协作效率',
  background_image: '',
  background_blur_image: '',
  capsule_tag: {
    text: 'Agent Hiring',
  },
  tabs: [
    {
      tab_id: 'tab-001',
      position_code: 'sales',
      position_name: '销售岗位',
      main_title: '让线索转化更高效',
      sub_title: '自动整理客户线索和跟进建议',
      qrcode_url: 'https://example.com/qrcode.png',
      qrcode_status: 'available',
      agents: [
        {
          agent_id: 'agent-001',
          agent_name: '销售助理 Agent',
          icon_url: '',
          media_url: '',
          media_type: 'image',
          speech_title: '线索跟进建议',
          speech_content: '自动整理客户线索和跟进建议',
          status: 'active',
        },
      ],
    },
  ],
  methodology: {
    display_status: true,
    main_title: '方法论',
    sub_title: '从岗位任务到智能体配置',
    steps: [
      {
        step_icon: '',
        step_name: '识别岗位',
        step_image: '',
        step_description: '确认岗位关键任务',
      },
    ],
  },
};

test('single page renders home content from mocked contract', async ({ page }) => {
  test.skip(useRealApi, '真实测试环境模式下跳过 mock 契约用例');

  await page.route('**/api/v1/**', async (route) => {
    await route.fulfill({
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify({
        code: 200,
        message: 'success',
        data: homeFixture,
      }),
    });
  });

  await page.goto('/gl-agent-position/');

  await expect(page.getByText('AI Agent 招聘站')).toBeVisible();
  await expect(page.getByText('销售岗位')).toBeVisible();
  await expect(page.getByText('线索跟进建议').first()).toBeVisible();
  await expect(page.getByText('方法论')).toBeVisible();
});

test('single page can load from configured test environment', async ({ page }) => {
  test.skip(!useRealApi, '默认模式下跳过真实测试环境用例');

  await page.goto('/gl-agent-position/');

  await page.waitForFunction(() => {
    const text = document.body.innerText;
    return text.trim().length > 0 && !text.includes('加载中');
  });

  const bodyText = await page.locator('body').innerText();
  expect(bodyText).not.toContain('加载失败');
  expect(bodyText.trim().length).toBeGreaterThan(10);
});