From 8fd4c78d4b573a91be11ba5edaaf21d10bdf52c6 Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 15 Aug 2026 11:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90React=20CardList=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=A9=BA=E7=8A=B6=E6=80=81=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/architecture/refactoring-master-plan.md | 1 + .../components/CardList.behavior.test.tsx | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 frontend/components/CardList.behavior.test.tsx diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index b4dca61..12dc43b 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -662,3 +662,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成测试覆盖率提升切片“React Settings 页面加载错误边界覆盖” | 新增 Settings 页面配置加载失败重试和加载中占位测试;前端 240 个测试、类型检查、注释门禁通过,全源语句覆盖率提升至 53.85%;真实系统配置和登录凭据仍不触网,仅验证可控 Hook 状态下的页面边界 | 下一步:继续补齐 Items/Orders/Rules 页面行为测试 | | 2026-08-15 | 完成测试覆盖率提升切片“React Rules 页面页签与空状态覆盖” | 新增 Rules 兼容入口的自动化、关键词回复、默认回复页签切换和空列表展示测试;前端 241 个测试、类型检查、注释门禁通过,全源语句覆盖率提升至 55.81%;真实规则、商品和账号数据仍不触网,仅验证可控规则数据 Hook 状态下的页面交互 | 下一步:继续补齐 Items/Orders 页面行为测试 | | 2026-08-15 | 完成测试覆盖率提升切片“React AccountList 加载与空状态覆盖” | 新增账号列表加载中、无账号引导状态测试,并隔离二维码、风控、编辑和自动化弹窗子组件;前端 243 个测试、类型检查、注释门禁通过,全源语句覆盖率提升至 56.86%;真实账号、二维码登录和远端资料仍不触网,仅验证可控账号数据状态 | 下一步:继续补齐 CardList/ItemList/OrderList 页面行为测试 | +| 2026-08-15 | 完成测试覆盖率提升切片“React CardList 卡密库存空状态覆盖” | 新增卡密库存页面空列表、添加卡密入口和批量导入入口测试,并隔离批量弹窗与卡密图标组件;前端 244 个测试、类型检查、注释门禁通过,全源语句覆盖率提升至 57.42%;真实卡密库存和导入文件仍不触网,仅验证可控 Hook 状态和页面结构 | 下一步:继续补齐 ItemList/OrderList 页面行为测试 | diff --git a/frontend/components/CardList.behavior.test.tsx b/frontend/components/CardList.behavior.test.tsx new file mode 100644 index 0000000..71583b2 --- /dev/null +++ b/frontend/components/CardList.behavior.test.tsx @@ -0,0 +1,29 @@ +// @vitest-environment jsdom +import { render, screen } from '@testing-library/react'; +import { describe, expect, test, vi } from 'vitest'; +import CardList from './CardList'; +import { useCardBatchActions, useCardsData } from '../app/features/cards/hooks'; + +vi.mock('../app/features/cards/hooks', /* cardsHookMockFactory 提供卡密页面数据和批量状态。 */ () => ({ useCardBatchActions: vi.fn(), useCardsData: vi.fn() })); +vi.mock('../app/features/cards/components/BatchCardImportModal', /* batchModalMockFactory 隔离批量卡密弹窗。 */ () => ({ BatchCardImportModal: /* batchModalRenderer 渲染批量弹窗占位节点。 */ () =>
})); +vi.mock('../app/features/cards/components/CardIcon', /* cardIconMockFactory 隔离卡密图标组件。 */ () => ({ CardIcon: /* cardIconRenderer 渲染卡密图标占位节点。 */ () => })); + +// useCardsDataMock 是卡密列表数据 Hook 的可控替身。 +const useCardsDataMock = vi.mocked(useCardsData); +// useCardBatchActionsMock 是卡密批量操作 Hook 的可控替身。 +const useCardBatchActionsMock = vi.mocked(useCardBatchActions); + +describe('CardList 页面空状态', /* 当前回调覆盖卡密列表无数据和批量入口。 */ () => { + test('没有卡密时展示空状态和添加入口', /* 当前回调验证卡密库存空列表页面。 */ () => { + // loadCards 是卡密列表刷新动作替身。 + const loadCards = vi.fn().mockResolvedValue(undefined); + // openBatchModal 是批量导入弹窗打开动作替身。 + const openBatchModal = vi.fn(); + useCardsDataMock.mockReturnValue({ cards: [], loadCards } as never); + useCardBatchActionsMock.mockReturnValue({ openBatchModal } as never); + render(); + expect(screen.getByText('暂无卡密配置,请点击右上角添加。')).toBeTruthy(); + expect(screen.getByRole('button', { name: '添加新卡密' })).toBeTruthy(); + expect(screen.getByRole('button', { name: '批量导入' })).toBeTruthy(); + }); +});