legal-pages-live.spec.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * ================================================================
  3. * 法务页可达性与结构契约 E2E · TC-L-U01 ~ TC-L-U06
  4. * ================================================================
  5. * 需求来源:提交 5a0223b9a「docs(web): add privacy policy and user agreement pages
  6. * for Xiaomi HealthKit application」新增 `web/privacy.html`、`web/agreement.html`。
  7. * 小米运动健康(Xiaomi HealthKit)上架审核要求应用提供**公网可直接访问**的
  8. * 隐私政策与用户协议 URL,且内容需覆盖健康数据收集/授权/撤回等条目。
  9. *
  10. * 覆盖缺口背景:该提交入库后(R260 窗口唯一内容变更)仓库内没有任何用例覆盖
  11. * 这两个页面 —— 属「新增内容零覆盖」。本 spec 补齐,判定两条硬契约:
  12. * ① **可达性**:`/web/privacy.html`、`/web/agreement.html` 线上返回 200(非 404/302 登录墙);
  13. * ② **结构完整性**:隐私政策 9 个章节、用户协议 12 个章节齐全,且协议含「健康数据/授权」条款。
  14. *
  15. * 只读:仅 GET 页面,不提交任何数据。
  16. *
  17. * 运行:
  18. * LIVE_BASE_URL=http://cfc.iwintrue.com npx playwright test -c playwright.config.live.js --project=legal-pages
  19. */
  20. const { test, expect } = require('@playwright/test');
  21. const BASE = process.env.LIVE_BASE_URL || 'http://cfc.iwintrue.com';
  22. // [用例编号, 路径, 期望 title 片段, 一级标题, 期望二级章节数]
  23. const PAGES = [
  24. ['TC-L-U01', '/web/privacy.html', '隐私政策', '浠艾福隐私政策', 9],
  25. ['TC-L-U02', '/web/agreement.html', '用户服务协议', '浠艾福用户服务协议', 12],
  26. ];
  27. test.describe('法务页 · 可达性与结构契约(小米 HealthKit 上架所需)', () => {
  28. for (const [tc, path, titlePart, h1Text, h2Count] of PAGES) {
  29. test(`${tc} ${path} 公网可直接访问(HTTP 200,非登录墙)`, async ({ request }) => {
  30. const resp = await request.get(`${BASE}${path}`, { timeout: 20000, maxRedirects: 0 });
  31. // 明确区分「未部署(404)」与「被登录墙拦截(302)」——两者都不满足上架审核要求
  32. expect(
  33. resp.status(),
  34. `${path} 期望 200,实际 ${resp.status()}(404=未部署到生产 / 302=被鉴权墙拦截)`
  35. ).toBe(200);
  36. const html = await resp.text();
  37. expect(html, `${path} 内容不应为空`).not.toHaveLength(0);
  38. });
  39. test(`${tc} ${path} 标题与章节结构完整`, async ({ page }) => {
  40. const resp = await page.goto(`${BASE}${path}`, { waitUntil: 'domcontentloaded', timeout: 60000 });
  41. const status = resp ? resp.status() : 0;
  42. // 未部署时以明确的失败信息暴露,而不是抛导航异常
  43. expect(status, `${path} 加载失败(HTTP ${status}),页面未部署`).toBe(200);
  44. await expect(page).toHaveTitle(new RegExp(titlePart));
  45. await expect(page.locator('h1').first()).toHaveText(new RegExp(h1Text));
  46. const sections = page.locator('h2');
  47. await expect(
  48. sections,
  49. `${path} 章节数不足:期望 ≥${h2Count},实际 ` + String(await sections.count())
  50. ).toHaveCount(h2Count);
  51. });
  52. }
  53. test('TC-L-U05 用户协议含健康数据授权与撤回条款(HealthKit 审核要点)', async ({ page }) => {
  54. const resp = await page.goto(`${BASE}/web/agreement.html`, { waitUntil: 'domcontentloaded', timeout: 60000 });
  55. expect(resp ? resp.status() : 0, '页面未部署,无法校验健康数据条款').toBe(200);
  56. const body = await page.locator('body').innerText();
  57. // 审核要求:必须说明健康数据范围、授权方式、撤回途径
  58. expect(body, '协议缺少「健康数据」条款').toContain('健康数据');
  59. expect(body, '协议缺少「授权」表述').toContain('授权');
  60. expect(body, '协议缺少「撤回」表述(授权撤回途径)').toContain('撤回');
  61. });
  62. test('TC-L-U06 两个法务页均归属同一主体并可互相跳转或提及', async ({ page }) => {
  63. const resp = await page.goto(`${BASE}/web/privacy.html`, { waitUntil: 'domcontentloaded', timeout: 60000 });
  64. expect(resp ? resp.status() : 0, '隐私政策页未部署').toBe(200);
  65. const body = await page.locator('body').innerText();
  66. expect(body, '隐私政策未标注运营主体「浠艾福」').toContain('浠艾福');
  67. });
  68. });