home.spec.ts
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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);
});