test(qa): e2e 装配修正 + 集成/门禁测试与工具链重构
- e2e:修死选择器与蜜罐误命中、补断言、GA4/security-headers 用例诚实标注 skip 边界;新增 assert-helpers/fixtures/hydrated/primary-nav/touch-targets 等复用桩。 - 集成层:config/test/jest.integration.config.js + tests-integration/ 真库 一次性 SQLite 用例,teardown 守卫开发库指纹。 - 门禁工具链:jest.setup 归位到根、scripts/accessibility 全站 axe 节点计数、 check-brand-text-token/check-motion-constraints 机械守卫、stryker/lighthouse 配置收敛。
This commit is contained in:
+40
-26
@@ -1,4 +1,4 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { test, expect } from './fixtures';
|
||||
|
||||
/**
|
||||
* P5: 边缘情况与缺失路径 E2E 测试
|
||||
@@ -42,6 +42,9 @@ test.describe('404 页面 - 未找到页面', { tag: '@regression' }, () => {
|
||||
await page.goto('/missing-page', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
await page.waitForTimeout(1500);
|
||||
|
||||
// N-27 修复:四个推荐链接在 src/app/not-found-content.tsx:41-81 中恒定渲染,
|
||||
// 原 `if (count > 0 && isVisible)` 守卫会让本例在链接缺失时静默通过。
|
||||
// 改为主内容区内作用域的轮询断言——任何一条缺失/隐藏即失败。
|
||||
const recommendedLinks = [
|
||||
{ text: '产品', expectedPath: '/products' },
|
||||
{ text: '解决方案', expectedPath: '/solutions' },
|
||||
@@ -50,11 +53,9 @@ test.describe('404 页面 - 未找到页面', { tag: '@regression' }, () => {
|
||||
];
|
||||
|
||||
for (const { text, expectedPath } of recommendedLinks) {
|
||||
const link = page.locator(`a:has-text("${text}")`).first();
|
||||
if (await link.count() > 0 && await link.isVisible()) {
|
||||
const href = await link.getAttribute('href');
|
||||
expect(href).toBe(expectedPath);
|
||||
}
|
||||
const link = page.locator(`main a:has-text("${text}")`).first();
|
||||
await expect(link, `404 页缺少推荐链接「${text}」`).toBeVisible();
|
||||
await expect(link).toHaveAttribute('href', expectedPath);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -71,26 +72,34 @@ test.describe('404 页面 - 未找到页面', { tag: '@regression' }, () => {
|
||||
test.describe('错误边界 - 应用级错误处理', { tag: '@regression' }, () => {
|
||||
|
||||
test('错误页面包含重试按钮', async ({ page }) => {
|
||||
// 通过直接访问错误页面组件路径模拟错误状态
|
||||
// 未知路径渲染 src/app/not-found-content.tsx:其恢复动作是
|
||||
// 「返回上一页」<button>(not-found-content.tsx:30-33)+「返回首页」CTA。
|
||||
// N-27 修复:原守卫 `if (count > 0)` ⇒ 页面空了也绿。改为硬断言两者可见。
|
||||
await page.goto('/error-test-trigger', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
await page.waitForTimeout(1500);
|
||||
|
||||
// 检查是否有返回首页链接(错误边界通用元素)
|
||||
const homeLink = page.locator('a[href="/"]').first();
|
||||
if (await homeLink.count() > 0) {
|
||||
await expect(homeLink).toBeVisible();
|
||||
}
|
||||
const backButton = page.locator('main button', { hasText: '返回上一页' }).first();
|
||||
await expect(backButton).toBeVisible();
|
||||
|
||||
const homeLink = page.locator('main a[href="/"]').first();
|
||||
await expect(homeLink).toBeVisible();
|
||||
});
|
||||
|
||||
test('错误页面包含返回首页链接', async ({ page }) => {
|
||||
await page.goto('/error-boundary-test', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
await page.waitForTimeout(1500);
|
||||
|
||||
const homeLink = page.locator('a[href="/"]').first();
|
||||
if (await homeLink.count() > 0) {
|
||||
const text = await homeLink.textContent();
|
||||
expect(text).toContain('返回首页');
|
||||
}
|
||||
// N-27 修复:守卫改为硬断言,并验证链接真的能回到首页
|
||||
// (与 :32 的差异:此例覆盖点击后的导航行为,不只是文案存在)。
|
||||
const homeLink = page.locator('main a[href="/"]').first();
|
||||
await expect(homeLink).toBeVisible();
|
||||
await expect(homeLink).toContainText('返回首页');
|
||||
|
||||
await Promise.all([
|
||||
page.waitForURL((url) => new URL(url).pathname === '/', { waitUntil: 'commit', timeout: 15000 }),
|
||||
homeLink.click(),
|
||||
]);
|
||||
expect(new URL(page.url()).pathname).toBe('/');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -112,16 +121,21 @@ test.describe('加载状态 - 页面过渡', { tag: '@regression' }, () => {
|
||||
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 30000 });
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// 点击到产品页面
|
||||
const productLink = page.locator('a[href="/products"]').first();
|
||||
if (await productLink.count() > 0 && await productLink.isVisible()) {
|
||||
await productLink.click();
|
||||
await page.waitForTimeout(1000);
|
||||
// N-27 修复:原守卫 `if (count > 0 && isVisible)` 依赖 header 巨型下拉里的
|
||||
// `a[href="/products"]`(未 hover 时隐藏 ⇒ 断言常被跳过)。
|
||||
// 改用主内容区恒定渲染的叙事区行动链接(home-content-v15 NARRATIVE_ACTS 第三幕,
|
||||
// p2-functional-e2e 亦以同选择器作硬断言),导航与内容都变硬断言。
|
||||
const productLink = page
|
||||
.locator('[data-testid="narrative-section"] a[href="/products"]')
|
||||
.first();
|
||||
await expect(productLink).toBeVisible();
|
||||
|
||||
// 导航过程中页面仍应包含某些元素
|
||||
const bodyText = await page.locator('body').textContent();
|
||||
expect(bodyText!.length).toBeGreaterThan(50);
|
||||
}
|
||||
await productLink.click();
|
||||
await expect(page).toHaveURL((url) => url.pathname === '/products');
|
||||
|
||||
// 导航完成后页面仍应包含实际内容
|
||||
const bodyText = await page.locator('body').textContent();
|
||||
expect(bodyText!.length).toBeGreaterThan(50);
|
||||
});
|
||||
|
||||
test('刷新页面后内容仍然加载', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user