release: dev → main(对标语法批 §11–§14,116 笔,FF-only) #30

Merged
zhangxiang merged 116 commits from dev into main 2026-10-20 07:43:42 +08:00
2 changed files with 108 additions and 1 deletions
Showing only changes of commit 220ece524d - Show all commits

No files matched your search

@@ -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<Record<string, unknown>> }).DetailTrustSection
?? (mod as unknown as { default: React.ComponentType<Record<string, unknown>> }).default;
return Section;
}
describe('DetailTrustSection · 案例逐条过闸(渲染侧)', () => {
it('过了闸的出、没过闸的一条都不出(即使同组里有过闸的)', async () => {
const Section = await loadSection();
render(
<Section
caseStudies={[passable, failable, failableNoVerified]}
dataProofs={[]}
certifications={[]}
/>,
);
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(<Section caseStudies={[failable]} dataProofs={[]} certifications={[]} />);
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(
<Section
caseStudies={[passable, failable, failableNoVerified]}
dataProofs={[]}
certifications={[]}
/>,
);
// 网格标题 + 每条一个卡片;只有 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('挑战乙');
});
});
@@ -172,7 +172,7 @@ export function DetailTrustSection({
</motion.div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{caseStudies.map((study, index) => (
{publishableCases.map((study, index) => (
<motion.div
key={study.client}
initial={{ opacity: 0, y: 24 }}