diff --git a/src/components/detail/detail-trust-gate.test.tsx b/src/components/detail/detail-trust-gate.test.tsx new file mode 100644 index 0000000..e41cef7 --- /dev/null +++ b/src/components/detail/detail-trust-gate.test.tsx @@ -0,0 +1,107 @@ +/** + * @jest-environment jsdom + */ +import { describe, it, expect, jest, beforeEach } from '@jest/globals'; +import { render, screen } from '@testing-library/react'; +import React from 'react'; + +/** + * DEC-N4 的渲染侧守卫(2026-10-17 补,抓到一条真缺陷)。 + * + * 缺陷本身:`DetailTrustSection` 第 97 行算了 `gateCaseItems(caseStudies)`, + * 第 105 行用 `publishableCases.length > 0` 决定整块要不要出现, + * 第 160 行也用 `publishableCases.length > 0` 包住了案例网格—— + * **但第 175 行渲染的是 `caseStudies.map`**。 + * 后果是 fail-open:只要有一条过了闸,未授权 / 无 verified 口径的案例照样出现在页面上。 + * 门槛只当了"这块要不要出现"的开关,没做它声称的逐条隐藏。 + * 全量功能 E2E 补跑(§14)把这条暴露出来后修的为 `publishableCases.map`。 + * + * 本文件的断言方向刻意与"缺陷存在时"相反 ⇒ 回退成 `caseStudies.map` 必须转红(变异验证已做)。 + */ + +const passable = { + client: '甲客户集团', + industry: '制造', + challenge: '挑战甲', + solution: '方案甲', + result: '成果甲', + authorized: true, + basis: 'verified' as const, +}; + +const failable = { + client: '乙客户公司', + industry: '零售', + challenge: '挑战乙', + solution: '方案乙', + result: '成果乙', + // 缺 authorized 与 basis ⇒ 必须被闸住(fail-closed) +}; + +const failableNoVerified = { + client: '丙客户实业', + industry: '能源', + challenge: '挑战丙', + solution: '方案丙', + result: '成果丙', + authorized: true, + basis: 'target' as const, // 有授权但口径是目标 ⇒ 仍闸住 +}; + +beforeEach(() => { + jest.restoreAllMocks(); + jest.spyOn(console, 'error').mockImplementation(() => undefined); +}); + +async function loadSection() { + const mod = await import('./detail-trust-section'); + const Section = (mod as { DetailTrustSection?: React.ComponentType> }).DetailTrustSection + ?? (mod as unknown as { default: React.ComponentType> }).default; + return Section; +} + +describe('DetailTrustSection · 案例逐条过闸(渲染侧)', () => { + it('过了闸的出、没过闸的一条都不出(即使同组里有过闸的)', async () => { + const Section = await loadSection(); + render( +
, + ); + expect(screen.getByText('甲客户集团')).toBeInTheDocument(); + // 下面三条是缺陷存在时会失败的核心断言 + expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument(); + expect(screen.queryByText('丙客户实业')).not.toBeInTheDocument(); + expect(screen.queryByText('挑战乙')).not.toBeInTheDocument(); + expect(screen.queryByText('成果丙')).not.toBeInTheDocument(); + }); + + it('全部没过闸 ⇒ 案例区整块不出现,且隐藏原因逐条 console.error(不静默)', async () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined); + const Section = await loadSection(); + render(
); + expect(screen.queryByText('乙客户公司')).not.toBeInTheDocument(); + expect(screen.queryByText('他们已经实现了转型突破')).not.toBeInTheDocument(); + expect(spy.mock.calls.flat().join(' ')).toContain('反伪造门槛'); + }); + + it('被闸住的条目不得占用网格位置(数量对账,防"隐藏但仍渲染")', async () => { + const Section = await loadSection(); + const { container } = render( +
, + ); + // 网格标题 + 每条一个卡片;只有 1 条应出现 + const heading = screen.getByText('他们已经实现了转型突破'); + const grid = heading.parentElement?.parentElement as HTMLElement; + const cards = grid.querySelectorAll('[class*="rounded"], article'); + expect(heading).toBeTruthy(); + expect(cards.length).toBeGreaterThan(0); + expect(container.textContent).not.toContain('挑战乙'); + }); +}); diff --git a/src/components/detail/detail-trust-section.tsx b/src/components/detail/detail-trust-section.tsx index 729931e..51b80c2 100644 --- a/src/components/detail/detail-trust-section.tsx +++ b/src/components/detail/detail-trust-section.tsx @@ -172,7 +172,7 @@ export function DetailTrustSection({
- {caseStudies.map((study, index) => ( + {publishableCases.map((study, index) => (