fix(qa): 第五轮系统性质量保障缺陷修复 + 单元/集成测试

安全/鉴权:登出清服务端 httpOnly 令牌、登录 IP 限流前置 bcrypt、停用账号
令牌在 6 个内联 role handler 失效、admin/items 存在性 oracle 认证前置、
同意偏好 sanitize fail-closed、api-crypto 按 HTTP 方法判体。

CMS:workflow 状态更新+审计收进交互式 $transaction(失败即回滚)、编辑器
richtext 走 textarea 防换行损毁、array/object 子字段按作用域读写防污染、
about/contact/erp-upgrade 补 ISR revalidate 与路由映射。

UI/a11y:AnimatedCounter 入视口前显起点、CLS 累计上报、MetricCard 动画入
effect 并卸载取消 rAF、后台状态四态映射/搜索防抖+序号守卫/媒体单 input/
吞错改横幅/表单 label-aria 关联。

新增对应判别性单测与 pagination/rate-limit/client-ip/sanitize/validate-content-data
等模块及 tests-integration 真库集成层。
This commit is contained in:
zhangxiang committed 2026-09-28 10:48:07 +08:00
1 parent 040951c0a3
commit a366bd1400
224 files changed
+8938 -5579

No files matched your search

@@ -1,6 +1,6 @@
// @ts-nocheck
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
import { render, act } from '@testing-library/react';
import { render, act, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
// Mock useSyncExternalStore to always return true (mounted in browser environment)
@@ -53,6 +53,7 @@ describe('GoogleAnalytics', () => {
delete (window as any).gtag;
mockPathname.mockReturnValue('/');
mockSearchParams.mockReturnValue(new URLSearchParams());
document.title = '';
process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID = 'G-TEST123';
});
@@ -111,7 +112,7 @@ describe('GoogleAnalytics', () => {
expect(gtagMock).not.toHaveBeenCalled();
});
it('should call config only when navigating to a different URL', () => {
it('should call config only when navigating to a different URL', async () => {
setupGtag();
const { GoogleAnalytics } = require('./GoogleAnalytics');
@@ -123,7 +124,7 @@ describe('GoogleAnalytics', () => {
rerender(<GoogleAnalytics />);
});
expect(gtagMock).toHaveBeenCalledTimes(1);
await waitFor(() => expect(gtagMock).toHaveBeenCalledTimes(1));
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', {
page_path: '/contact',
page_title: document.title,
@@ -131,7 +132,7 @@ describe('GoogleAnalytics', () => {
});
});
it('should include searchParams in navigation page_path', () => {
it('should include searchParams in navigation page_path', async () => {
setupGtag();
const { GoogleAnalytics } = require('./GoogleAnalytics');
@@ -143,12 +144,14 @@ describe('GoogleAnalytics', () => {
rerender(<GoogleAnalytics />);
});
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', expect.objectContaining({
page_path: '/news?page=2',
}));
await waitFor(() =>
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', expect.objectContaining({
page_path: '/news?page=2',
}))
);
});
it('should skip duplicate config when URL is unchanged across re-renders', () => {
it('should skip duplicate config when URL is unchanged across re-renders', async () => {
setupGtag();
const { GoogleAnalytics } = require('./GoogleAnalytics');
@@ -158,13 +161,93 @@ describe('GoogleAnalytics', () => {
act(() => {
rerender(<GoogleAnalytics />);
});
expect(gtagMock).toHaveBeenCalledTimes(1);
await waitFor(() => expect(gtagMock).toHaveBeenCalledTimes(1));
act(() => {
rerender(<GoogleAnalytics />);
});
expect(gtagMock).toHaveBeenCalledTimes(1);
});
// 验收 A-17(探针实证):Next.js 在路由 commit 之后才写入 <title>,
// 同步读取 document.title 会把 SPA pageview 的标题发成空串。
it('should read document.title after metadata paints, not during the navigation commit', async () => {
setupGtag();
document.title = '首页 - 睿新致远';
const { GoogleAnalytics } = require('./GoogleAnalytics');
const { rerender } = render(<GoogleAnalytics />);
mockPathname.mockReturnValue('/privacy');
act(() => {
rerender(<GoogleAnalytics />);
});
expect(gtagMock).not.toHaveBeenCalled();
act(() => {
document.title = '隐私政策 - 睿新致远';
});
await waitFor(() =>
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', expect.objectContaining({
page_path: '/privacy',
page_title: '隐私政策 - 睿新致远',
}))
);
});
// 验收 A-17 复测:真实浏览器里 metadata 不在同一帧落地(chromium-mobile 第 2 帧、
// 桌面第 3–5 帧),只等一帧会把 page_title 发成上一页标题 —— GA4 页面维度被错归属。
it('should keep waiting while the title still belongs to the previous page', async () => {
setupGtag();
document.title = '首页 - 睿新致远';
const { GoogleAnalytics } = require('./GoogleAnalytics');
const { rerender } = render(<GoogleAnalytics />);
mockPathname.mockReturnValue('/privacy');
act(() => {
rerender(<GoogleAnalytics />);
});
const nextFrame = () => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
for (let frame = 0; frame < 4; frame += 1) {
await nextFrame();
}
expect(gtagMock).not.toHaveBeenCalled();
act(() => {
document.title = '隐私政策 - 睿新致远';
});
await waitFor(() =>
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', expect.objectContaining({
page_title: '隐私政策 - 睿新致远',
}))
);
});
// 帧预算只用来「等」,不能吞掉 pageview:两条路由同名时必须在预算耗尽后兜底发出。
it('should still send the pageview when the title never changes', async () => {
setupGtag();
document.title = '固定标题';
const { GoogleAnalytics } = require('./GoogleAnalytics');
const { rerender } = render(<GoogleAnalytics />);
mockPathname.mockReturnValue('/terms');
act(() => {
rerender(<GoogleAnalytics />);
});
await waitFor(() =>
expect(gtagMock).toHaveBeenCalledWith('config', 'G-TEST123', expect.objectContaining({
page_path: '/terms',
page_title: '固定标题',
}))
);
});
});
describe('rendering guards', () => {