Commit b36a2063 by 胡悦

feat(agent-admin/single-page): 搭建H5官网首页项目并对接真实API

初始化agent-admin下的H5官网首页项目,配置vite+TS+React+Tailwind开发环境与vitest测试链。
实现首页全量业务代码,包括组件、页面、数据hooks与API客户端,对接官方站点真实接口。
更新fix-official-site-agent-config-detail规范,将渠道上下文字段映射修正为qrcode_name、position_code与qrcode_employee_name。
补充完整的单元测试与集成测试用例,同步更新项目文档与openspec配置说明。
1 parent 10156192
Showing 67 changed files with 679 additions and 95 deletions
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
2026-05-24:用户通过 `@fixbug` 要求新开 OpenSpec 处理官网配置问题:岗位展示配置列表点击 `配置Agent` 后,Agent 展示配置页标题应为“岗位名称 + Agent展示配置页”;页面需调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前项详情,并展示关联渠道活码名称、渠道编码、承接员工;编辑配置弹窗需恢复图标上传图片功能。已新建 `workspace/agent-admin/web/openspec/changes/fix-official-site-agent-config-detail/`,完成 proposal、design、spec 和 tasks,并通过 `openspec validate "fix-official-site-agent-config-detail" --strict`。本轮未写业务代码,等待用户确认 artifacts 后再进入 TDD 实现。 2026-05-24:用户通过 `@fixbug` 要求新开 OpenSpec 处理官网配置问题:岗位展示配置列表点击 `配置Agent` 后,Agent 展示配置页标题应为“岗位名称 + Agent展示配置页”;页面需调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前项详情,并展示关联渠道活码名称、渠道编码、承接员工;编辑配置弹窗需恢复图标上传图片功能。已新建 `workspace/agent-admin/web/openspec/changes/fix-official-site-agent-config-detail/`,完成 proposal、design、spec 和 tasks,并通过 `openspec validate "fix-official-site-agent-config-detail" --strict`。本轮未写业务代码,等待用户确认 artifacts 后再进入 TDD 实现。
2026-05-24:用户通过 `@fixbug fix-official-site-agent-config-detail` 补充详情接口字段口径:关联渠道活码使用 `qrcode_name`,渠道编码展示使用 `position_code`,承接员工使用 `qrcode_employee_name`。已更新该 change 的 proposal、design、spec 和 tasks,并通过 `openspec validate "fix-official-site-agent-config-detail" --strict`。本轮未写业务代码,等待用户确认 artifacts 后再进入 TDD 实现。
2026-05-24:用户通过 `@fixbug real-api-integration` 补充岗位展示配置「配置 Agent」弹窗图片上传要求:上传图片需切真实接口,沿用方法论上传链路,`usage_type` 使用 `agent_media` 和 `agent_icon`。已更新 `workspace/agent-admin/web/openspec/changes/real-api-integration/` 的 proposal、design、spec 和 tasks,明确展示素材上传回填 `media_url`、图标上传回填 `icon_url`,均不得使用 mock URL 或旧上传端点;已通过 `openspec validate "real-api-integration" --strict`。本轮未写业务代码,等待用户确认 artifacts 后再进入 TDD 实现。 2026-05-24:用户通过 `@fixbug real-api-integration` 补充岗位展示配置「配置 Agent」弹窗图片上传要求:上传图片需切真实接口,沿用方法论上传链路,`usage_type` 使用 `agent_media` 和 `agent_icon`。已更新 `workspace/agent-admin/web/openspec/changes/real-api-integration/` 的 proposal、design、spec 和 tasks,明确展示素材上传回填 `media_url`、图标上传回填 `icon_url`,均不得使用 mock URL 或旧上传端点;已通过 `openspec validate "real-api-integration" --strict`。本轮未写业务代码,等待用户确认 artifacts 后再进入 TDD 实现。
## 下一步 ## 下一步
...@@ -69,3 +71,4 @@ ...@@ -69,3 +71,4 @@
- 2026-05-24:按 `@fixbug` 更新 `web/openspec/changes/real-api-integration`,补齐渠道活码列表和岗位展示配置列表状态按钮必须由当前行状态派生的规范;本轮未写业务代码,等待用户确认后进入 TDD 实现。 - 2026-05-24:按 `@fixbug` 更新 `web/openspec/changes/real-api-integration`,补齐渠道活码列表和岗位展示配置列表状态按钮必须由当前行状态派生的规范;本轮未写业务代码,等待用户确认后进入 TDD 实现。
- 2026-05-24:按 `@fixbug` 新建 `web/openspec/changes/fix-official-site-agent-config-detail`,锁定官网 Agent 展示配置页详情接口、标题、渠道上下文和编辑弹窗图标上传回归;本轮未写业务代码,等待用户确认后进入 TDD 实现。 - 2026-05-24:按 `@fixbug` 新建 `web/openspec/changes/fix-official-site-agent-config-detail`,锁定官网 Agent 展示配置页详情接口、标题、渠道上下文和编辑弹窗图标上传回归;本轮未写业务代码,等待用户确认后进入 TDD 实现。
- 2026-05-24:按 `@fixbug real-api-integration` 更新既有 change,锁定岗位展示配置「配置 Agent」弹窗真实上传:展示素材使用 `usage_type=agent_media`,图标使用 `usage_type=agent_icon`,上传成功后分别回填 `media_url` / `icon_url` 并参与保存;本轮未写业务代码,等待用户确认后进入 TDD 实现。 - 2026-05-24:按 `@fixbug real-api-integration` 更新既有 change,锁定岗位展示配置「配置 Agent」弹窗真实上传:展示素材使用 `usage_type=agent_media`,图标使用 `usage_type=agent_icon`,上传成功后分别回填 `media_url` / `icon_url` 并参与保存;本轮未写业务代码,等待用户确认后进入 TDD 实现。
- 2026-05-24:按 `@fixbug fix-official-site-agent-config-detail` 更新既有 change,锁定详情接口上下文字段映射:`qrcode_name` -> 关联渠道活码,`position_code` -> 渠道编码,`qrcode_employee_name` -> 承接员工;本轮未写业务代码,等待用户确认后进入 TDD 实现。
# Agent Admin Single Page # Agent Admin Single Page
这里放 Agent 管理平台相关的单页面项目。 这里放 Agent 管理平台相关的单页面项目。当前根目录即 H5 官网首页应用目录。
本项目与管理后台 `web/` 平级,独立管理自己的 OpenSpec、组件和工程配置。当前只定义目录边界,不生成业务实现代码。 本项目与管理后台 `web/` 平级,独立管理自己的 OpenSpec、组件和工程配置。
职责范围: 职责范围:
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
目录说明: 目录说明:
- `openspec/`:单页面项目的页面和交互行为 OpenSpec。 - `openspec/`:单页面项目的页面和交互行为 OpenSpec。
- `src/`:H5 官网首页应用源码。
- `public/`:H5 官网首页静态资源。
- `packages/ui/`:单页面项目可复用 UI 组件。 - `packages/ui/`:单页面项目可复用 UI 组件。
- `packages/config/`:单页面项目工程配置。 - `packages/config/`:单页面项目工程配置。
- `packages/utils/`:单页面项目通用工具。 - `packages/utils/`:单页面项目通用工具。
- `packages/contracts/`:单页面项目视角的字段、枚举、payload 和 mock 数据。 - `packages/contracts/`:单页面项目视角的字段、枚举、payload 和 mock 数据。
## Context ## Context
H5 官网首页位于 `workspace/agent-admin/single-page/packages/h5-home`,当前页面已经按 `official-site-h5-home` change 定义了 Banner、岗位 Tab、Agent 卡片、二维码弹窗和方法论模块,并且该 change 已明确页面应消费 `GET /api/v1/official-site/home`。 H5 官网首页位于 `workspace/agent-admin/single-page`,当前页面已经按 `official-site-h5-home` change 定义了 Banner、岗位 Tab、Agent 卡片、二维码弹窗和方法论模块,并且该 change 已明确页面应消费 `GET /api/v1/official-site/home`。
现有实现仍通过 `src/hooks/useHomeData.ts` 调用 `src/mocks/api.ts` 的 `fetchHomeData()`,该模块使用本地 fixture 和模拟延迟返回数据。这样可以支撑前期页面开发,但会阻断真实后端联调、错误处理验证和后台配置内容在 H5 端的展示。 现有实现仍通过 `src/hooks/useHomeData.ts` 调用 `src/mocks/api.ts` 的 `fetchHomeData()`,该模块使用本地 fixture 和模拟延迟返回数据。这样可以支撑前期页面开发,但会阻断真实后端联调、错误处理验证和后台配置内容在 H5 端的展示。
......
...@@ -29,7 +29,7 @@ H5 官网首页已经按真实聚合接口契约完成页面能力,但当前 ...@@ -29,7 +29,7 @@ H5 官网首页已经按真实聚合接口契约完成页面能力,但当前
## Impact ## Impact
- 影响 H5 单页包:`workspace/agent-admin/single-page/packages/h5-home`。 - 影响 H5 单页应用:`workspace/agent-admin/single-page`。
- 影响 H5 运行时数据源:从本地 mock API 切换为真实 HTTP 接口。 - 影响 H5 运行时数据源:从本地 mock API 切换为真实 HTTP 接口。
- 影响 H5 开发配置:`vite.config.ts` 增加 `/api` 代理,默认联调后端为 `http://192.168.1.191:8000/`。 - 影响 H5 开发配置:`vite.config.ts` 增加 `/api` 代理,默认联调后端为 `http://192.168.1.191:8000/`。
- 影响 H5 Banner 与方法论模块渲染:真实接口数据仍驱动业务内容,但 Banner 背景素材使用本地图片,方法论步骤名称前展示步骤图标。 - 影响 H5 Banner 与方法论模块渲染:真实接口数据仍驱动业务内容,但 Banner 背景素材使用本地图片,方法论步骤名称前展示步骤图标。
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
## 4. 联调与回归 ## 4. 联调与回归
- [ ] 4.1 运行 `openspec validate "h5-real-api-integration" --strict`。 - [ ] 4.1 运行 `openspec validate "h5-real-api-integration" --strict`。
- [ ] 4.2 在 `workspace/agent-admin/single-page/packages/h5-home` 运行类型检查。 - [ ] 4.2 在 `workspace/agent-admin/single-page` 运行类型检查。
- [ ] 4.3 在 `workspace/agent-admin/single-page/packages/h5-home` 运行相关单元测试。 - [ ] 4.3 在 `workspace/agent-admin/single-page` 运行相关单元测试。
- [ ] 4.4 在 `workspace/agent-admin/single-page/packages/h5-home` 运行构建。 - [ ] 4.4 在 `workspace/agent-admin/single-page` 运行构建。
- [ ] 4.5 启动 H5 开发服务,使用默认代理目标 `http://192.168.1.191:8000/` 联调首页接口。 - [ ] 4.5 启动 H5 开发服务,使用默认代理目标 `http://192.168.1.191:8000/` 联调首页接口。
- [ ] 4.6 浏览器验证 PC 与移动端的首页加载、失败重试、岗位 Tab 切换、Agent 卡片选择、二维码弹窗和方法论切换,确认真实接口接入未破坏既有交互。 - [ ] 4.6 浏览器验证 PC 与移动端的首页加载、失败重试、岗位 Tab 切换、Agent 卡片选择、二维码弹窗和方法论切换,确认真实接口接入未破坏既有交互。
- [ ] 4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示“新一代智能协作平台”、方法论步骤图标位于步骤名称前方。 - [ ] 4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示“新一代智能协作平台”、方法论步骤图标位于步骤名称前方。
{ {
"name": "@agent-admin/h5-home", "name": "@agent-admin/single-page",
"version": "0.0.1", "version": "0.0.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@agent-admin/h5-home", "name": "@agent-admin/single-page",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"react": "^19.2.3", "react": "^19.2.3",
......
{ {
"name": "@agent-admin/h5-home", "name": "@agent-admin/single-page",
"private": true, "private": true,
"version": "0.0.1", "version": "0.0.1",
"type": "module", "type": "module",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
`official-site-agent-display-config` 曾定义 `/official-site/job-tabs/:tabId/agents` 独立页面,展示岗位名称、关联渠道活码、渠道编码、承接员工和 Agent 展示配置列表。后续 `real-api-integration` 将页面运行时切换到真实接口后,当前实现主要通过 `/official-site/tabs/{tabId}/agents/configured` 获取列表与部分上下文,没有在页面进入时单独读取 `/api/v1/official-site/tabs/{tab_id}` 的当前岗位 Tab 详情。 `official-site-agent-display-config` 曾定义 `/official-site/job-tabs/:tabId/agents` 独立页面,展示岗位名称、关联渠道活码、渠道编码、承接员工和 Agent 展示配置列表。后续 `real-api-integration` 将页面运行时切换到真实接口后,当前实现主要通过 `/official-site/tabs/{tabId}/agents/configured` 获取列表与部分上下文,没有在页面进入时单独读取 `/api/v1/official-site/tabs/{tab_id}` 的当前岗位 Tab 详情。
用户现在明确要求:从岗位展示配置列表点击 `配置Agent` 后,配置 Agent 页面应展示为“岗位名称 + Agent展示配置页”;Agent 展示配置页需要调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前项详情,并展示对应的关联渠道活码、渠道编码、承接员工;编辑配置弹窗中恢复图标上传图片功能。 用户现在明确要求:从岗位展示配置列表点击 `配置Agent` 后,配置 Agent 页面应展示为“岗位名称 + Agent展示配置页”;Agent 展示配置页需要调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前项详情,并展示对应的关联渠道活码、渠道编码、承接员工;编辑配置弹窗中恢复图标上传图片功能。后续补充确认详情接口字段口径:关联渠道活码使用 `qrcode_name`,渠道编码展示使用 `position_code`,承接员工使用 `qrcode_employee_name`。
## Goals / Non-Goals ## Goals / Non-Goals
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- 让 Agent 展示配置页标题与产品期望一致:`{岗位名称} Agent展示配置页`,不把关联渠道活码拼进标题。 - 让 Agent 展示配置页标题与产品期望一致:`{岗位名称} Agent展示配置页`,不把关联渠道活码拼进标题。
- 页面加载时通过领域 API 调用 `/official-site/tabs/{tab_id}`,最终命中 `/api/v1/official-site/tabs/{tab_id}`,用岗位 Tab 详情作为岗位名称和渠道上下文的权威来源。 - 页面加载时通过领域 API 调用 `/official-site/tabs/{tab_id}`,最终命中 `/api/v1/official-site/tabs/{tab_id}`,用岗位 Tab 详情作为岗位名称和渠道上下文的权威来源。
- 详情区域展示 `关联渠道活码`、`渠道编码`、`承接员工`,其中关联渠道活码取渠道活码名称字段。 - 详情区域展示 `关联渠道活码`、`渠道编码`、`承接员工`,其中关联渠道活码取 `qrcode_name`,渠道编码取 `position_code`,承接员工取 `qrcode_employee_name`。
- 编辑配置弹窗恢复 `图标` 图片上传,上传使用官网素材上传能力,成功后以 `icon_url` 参与预览、校验和保存。 - 编辑配置弹窗恢复 `图标` 图片上传,上传使用官网素材上传能力,成功后以 `icon_url` 参与预览、校验和保存。
- 用测试固定真实接口切换后的回归行为。 - 用测试固定真实接口切换后的回归行为。
...@@ -37,9 +37,9 @@ Agent 展示配置页需要在进入 `/official-site/job-tabs/:tabId/agents` 后 ...@@ -37,9 +37,9 @@ Agent 展示配置页需要在进入 `/official-site/job-tabs/:tabId/agents` 后
详情区域展示三项只读信息: 详情区域展示三项只读信息:
- `关联渠道活码`:取岗位 Tab 详情里的渠道活码名称字段,优先使用 `qrcode_name`。 - `关联渠道活码`:取岗位 Tab 详情里的 `qrcode_name`。
- `渠道编码`:取岗位 Tab 详情里的 `channel_code`。 - `渠道编码`:按详情接口当前字段口径取 `position_code`。
- `承接员工`:取岗位 Tab 详情里的 `employee_name` 或同义员工名称字段。 - `承接员工`:取岗位 Tab 详情里的 `qrcode_employee_name`。
当字段为空时,页面展示 `-`,不允许在 Agent 展示配置页编辑渠道活码、渠道编码或承接员工。 当字段为空时,页面展示 `-`,不允许在 Agent 展示配置页编辑渠道活码、渠道编码或承接员工。
...@@ -62,7 +62,7 @@ Agent 展示配置页需要在进入 `/official-site/job-tabs/:tabId/agents` 后 ...@@ -62,7 +62,7 @@ Agent 展示配置页需要在进入 `/official-site/job-tabs/:tabId/agents` 后
## Risks / Trade-offs ## Risks / Trade-offs
- [Risk] 详情接口和 Agent 配置列表接口可能并行失败,页面错误来源不清。 -> 页面只要任一关键数据加载失败即展示可恢复错误状态,并保留返回列表入口;后续可按错误消息细化。 - [Risk] 详情接口和 Agent 配置列表接口可能并行失败,页面错误来源不清。 -> 页面只要任一关键数据加载失败即展示可恢复错误状态,并保留返回列表入口;后续可按错误消息细化。
- [Risk] 后端真实字段可能使用 `qrcode_name`、`channel_qrcode_name` 或员工字段别名。 -> 在领域 API 适配层兼容已知同义字段,页面层消费稳定模型。 - [Risk] 后端真实字段口径与早期 mock 口径不一致,例如早期页面曾使用 `channel_code` / `employee_name`,但详情接口当前以 `position_code` / `qrcode_employee_name` 承载页面所需展示值。 -> 在领域 API 适配层按详情接口字段建立稳定模型,测试固定 `position_code` 与 `qrcode_employee_name` 映射,避免页面继续读取旧字段。
- [Risk] 图标上传与展示素材上传混用同一状态会导致保存 payload 丢字段。 -> 弹窗拆分 `icon_url` 与 `media_url` 状态、校验和上传处理。 - [Risk] 图标上传与展示素材上传混用同一状态会导致保存 payload 丢字段。 -> 弹窗拆分 `icon_url` 与 `media_url` 状态、校验和上传处理。
- [Risk] 当前工作区已有其他未提交修改。 -> 实施阶段只触及本 change 明确列出的 API、页面、弹窗和测试文件,不混入无关修复。 - [Risk] 当前工作区已有其他未提交修改。 -> 实施阶段只触及本 change 明确列出的 API、页面、弹窗和测试文件,不混入无关修复。
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
官网配置中的岗位展示配置列表点击 `配置Agent` 后,Agent 展示配置页仍存在真实接口切换后的回归问题: 官网配置中的岗位展示配置列表点击 `配置Agent` 后,Agent 展示配置页仍存在真实接口切换后的回归问题:
- 页头展示为 `岗位名称 - 关联渠道活码 - Agent展示配置`,而产品期望为 `岗位名称 + Agent展示配置页`。 - 页头展示为 `岗位名称 - 关联渠道活码 - Agent展示配置`,而产品期望为 `岗位名称 + Agent展示配置页`。
- Agent 展示配置页没有调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前岗位 Tab 详情,导致关联渠道活码、渠道编码、承接员工等上下文不能可靠来自当前项详情。 - Agent 展示配置页没有调用 `/api/v1/official-site/tabs/{tab_id}` 查询当前岗位 Tab 详情,导致关联渠道活码、渠道编码、承接员工等上下文不能可靠来自当前项详情;其中详情接口字段口径应以 `qrcode_name`、`position_code`、`qrcode_employee_name` 为准。
- 编辑配置弹窗在 mock 阶段曾支持 `图标` 上传图片;切换真实接口后该能力缺失,图标无法上传并保存到 Agent 展示配置。 - 编辑配置弹窗在 mock 阶段曾支持 `图标` 上传图片;切换真实接口后该能力缺失,图标无法上传并保存到 Agent 展示配置。
这些问题会影响运营在官网岗位 Tab 下核对渠道活码上下文、编辑 Agent 官网展示图标和确认当前配置对象。 这些问题会影响运营在官网岗位 Tab 下核对渠道活码上下文、编辑 Agent 官网展示图标和确认当前配置对象。
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
- 新增 Web 端缺陷修复规范,限定在官网岗位 Tab 的 Agent 展示配置页和编辑配置弹窗。 - 新增 Web 端缺陷修复规范,限定在官网岗位 Tab 的 Agent 展示配置页和编辑配置弹窗。
- `配置Agent` 跳转到 `/official-site/job-tabs/:tabId/agents` 后,页面标题只展示当前岗位名称与 `Agent展示配置页`。 - `配置Agent` 跳转到 `/official-site/job-tabs/:tabId/agents` 后,页面标题只展示当前岗位名称与 `Agent展示配置页`。
- 页面加载时必须调用 `/api/v1/official-site/tabs/{tab_id}` 获取当前岗位 Tab 详情,并用详情中的渠道活码名称字段、渠道编码、承接员工展示只读上下文。 - 页面加载时必须调用 `/api/v1/official-site/tabs/{tab_id}` 获取当前岗位 Tab 详情,并用详情中的 `qrcode_name` 展示关联渠道活码、`position_code` 展示渠道编码、`qrcode_employee_name` 展示承接员工。
- 编辑配置弹窗恢复 `图标` 上传图片能力,上传成功后写入 `icon_url`,保存 Agent 展示配置时提交图标字段。 - 编辑配置弹窗恢复 `图标` 上传图片能力,上传成功后写入 `icon_url`,保存 Agent 展示配置时提交图标字段。
- 以失败优先测试覆盖详情接口调用、页面展示、图标上传、保存 payload 和异常状态。 - 以失败优先测试覆盖详情接口调用、页面展示、图标上传、保存 payload 和异常状态。
......
...@@ -26,7 +26,7 @@ Agent 撅內蔭憿 SHALL 靚敶 Tab 霂行 ...@@ -26,7 +26,7 @@ Agent 撅內蔭憿 SHALL 靚敶 Tab 霂行
#### Scenario: 详情与 Agent 列表职责分离 #### Scenario: 详情与 Agent 列表职责分离
- **WHEN** 页面同时加载岗位 Tab 详情和 Agent 展示配置列表 - **WHEN** 页面同时加载岗位 Tab 详情和 Agent 展示配置列表
- **THEN** 岗位 Tab 详情 SHALL 提供 `position_name`、渠道活码名称、`channel_code` 和承接员工 - **THEN** 岗位 Tab 详情 SHALL 提供 `position_name`、`qrcode_name`、`position_code` 和 `qrcode_employee_name`
- **AND** Agent 展示配置列表 SHALL 只负责提供 Agent 展示配置数据 - **AND** Agent 展示配置列表 SHALL 只负责提供 Agent 展示配置数据
- **AND** 页面 SHALL NOT 依赖 Agent 展示配置列表接口作为标题和渠道上下文的唯一来源 - **AND** 页面 SHALL NOT 依赖 Agent 展示配置列表接口作为标题和渠道上下文的唯一来源
...@@ -42,13 +42,15 @@ Agent 撅內蔭憿 SHALL 霂餃內敶 Tab 暑 ...@@ -42,13 +42,15 @@ Agent 撅內蔭憿 SHALL 霂餃內敶 Tab 暑
#### Scenario: 展示渠道上下文字段 #### Scenario: 展示渠道上下文字段
- **WHEN** 当前岗位 Tab 详情加载成功 - **WHEN** 当前岗位 Tab 详情加载成功
- **THEN** 页面 SHALL 展示 `关联渠道活码` - **THEN** 页面 SHALL 展示 `关联渠道活码`
- **AND** `关联渠道活码` SHALL 取渠道活码名称字段 - **AND** `关联渠道活码` SHALL 取详情接口 `qrcode_name` 字段
- **AND** 页面 SHALL 展示 `渠道编码` - **AND** 页面 SHALL 展示 `渠道编码`
- **AND** `渠道编码` SHALL 取详情接口 `position_code` 字段
- **AND** 页面 SHALL 展示 `承接员工` - **AND** 页面 SHALL 展示 `承接员工`
- **AND** `承接员工` SHALL 取详情接口 `qrcode_employee_name` 字段
- **AND** 这些字段 SHALL 为只读展示 - **AND** 这些字段 SHALL 为只读展示
#### Scenario: 渠道上下文字段为空 #### Scenario: 渠道上下文字段为空
- **WHEN** 当前岗位 Tab 详情中的渠道活码名称、渠道编码或承接员工为空 - **WHEN** 当前岗位 Tab 详情中的 `qrcode_name`、`position_code` 或 `qrcode_employee_name` 为空
- **THEN** 页面 SHALL 在对应字段展示 `-` - **THEN** 页面 SHALL 在对应字段展示 `-`
- **AND** 页面 SHALL NOT 允许用户在 Agent 展示配置页编辑这些字段 - **AND** 页面 SHALL NOT 允许用户在 Agent 展示配置页编辑这些字段
...@@ -93,7 +95,7 @@ Agent 蝻蔭撘寧 SHALL 辣蝻僎 ...@@ -93,7 +95,7 @@ Agent 蝻蔭撘寧 SHALL 辣蝻僎
#### Scenario: API 与页面测试覆盖详情接口 #### Scenario: API 与页面测试覆盖详情接口
- **WHEN** 实施本修复 - **WHEN** 实施本修复
- **THEN** 测试 MUST 覆盖岗位 Tab 详情 API 请求 `/official-site/tabs/{tab_id}` - **THEN** 测试 MUST 覆盖岗位 Tab 详情 API 请求 `/official-site/tabs/{tab_id}`
- **AND** 测试 MUST 覆盖页面使用详情响应展示标题、关联渠道活码、渠道编码和承接员工 - **AND** 测试 MUST 覆盖页面使用详情响应展示标题、`qrcode_name` 对应的关联渠道活码、`position_code` 对应的渠道编码和 `qrcode_employee_name` 对应的承接员工
#### Scenario: 弹窗测试覆盖图标上传与保存 #### Scenario: 弹窗测试覆盖图标上传与保存
- **WHEN** 实施本修复 - **WHEN** 实施本修复
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- [ ] 1.1 为 `officialSiteTab` 领域 API 增加详情接口失败优先测试:`getOfficialSiteTabDetail(tabId)` 必须请求 `/official-site/tabs/{tab_id}`。 - [ ] 1.1 为 `officialSiteTab` 领域 API 增加详情接口失败优先测试:`getOfficialSiteTabDetail(tabId)` 必须请求 `/official-site/tabs/{tab_id}`。
- [ ] 1.2 为 Agent 展示配置页增加页面测试:从岗位展示配置列表点击 `配置Agent` 后,标题展示为 `{岗位名称} Agent展示配置页`,不拼接渠道活码名称。 - [ ] 1.2 为 Agent 展示配置页增加页面测试:从岗位展示配置列表点击 `配置Agent` 后,标题展示为 `{岗位名称} Agent展示配置页`,不拼接渠道活码名称。
- [ ] 1.3 为 Agent 展示配置页增加页面测试:页面加载时调用岗位 Tab 详情接口,并展示详情响应中的关联渠道活码名称、渠道编码、承接员工。 - [ ] 1.3 为 Agent 展示配置页增加页面测试:页面加载时调用岗位 Tab 详情接口,并展示详情响应中的 `qrcode_name`(关联渠道活码)、`position_code`(渠道编码)、`qrcode_employee_name`(承接员工)。
- [ ] 1.4 为 Agent 展示配置页增加异常测试:岗位 Tab 详情请求失败时展示可恢复错误状态、重试操作和返回列表入口。 - [ ] 1.4 为 Agent 展示配置页增加异常测试:岗位 Tab 详情请求失败时展示可恢复错误状态、重试操作和返回列表入口。
- [ ] 1.5 为编辑配置弹窗增加测试:`图标` 字段使用上传图片组件,已有 `icon_url` 时回显预览。 - [ ] 1.5 为编辑配置弹窗增加测试:`图标` 字段使用上传图片组件,已有 `icon_url` 时回显预览。
- [ ] 1.6 为编辑配置弹窗增加测试:缺少 `icon_url` 保存时展示字段附近校验错误且不调用保存接口。 - [ ] 1.6 为编辑配置弹窗增加测试:缺少 `icon_url` 保存时展示字段附近校验错误且不调用保存接口。
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
## 2. API 与数据适配 ## 2. API 与数据适配
- [ ] 2.1 在 `src/api/officialSiteTab.ts` 新增或补全岗位 Tab 详情类型与 `getOfficialSiteTabDetail(tabId)`。 - [ ] 2.1 在 `src/api/officialSiteTab.ts` 新增或补全岗位 Tab 详情类型与 `getOfficialSiteTabDetail(tabId)`。
- [ ] 2.2 在领域 API 适配层兼容真实详情响应中的渠道活码名称、渠道编码和承接员工字段,并向页面暴露稳定模型。 - [ ] 2.2 在领域 API 适配层按详情接口字段口径映射上下文:`qrcode_name` 映射为关联渠道活码展示值,`position_code` 映射为渠道编码展示值,`qrcode_employee_name` 映射为承接员工展示值,并向页面暴露稳定模型。
- [ ] 2.3 补齐 Agent 展示配置保存 payload 类型中的 `icon_url` 字段,确保保存请求提交图标 URL。 - [ ] 2.3 补齐 Agent 展示配置保存 payload 类型中的 `icon_url` 字段,确保保存请求提交图标 URL。
## 3. 页面与弹窗修复 ## 3. 页面与弹窗修复
- [ ] 3.1 调整 Agent 展示配置页加载逻辑,同时获取岗位 Tab 详情和 Agent 展示配置列表,并以详情作为标题与渠道上下文来源。 - [ ] 3.1 调整 Agent 展示配置页加载逻辑,同时获取岗位 Tab 详情和 Agent 展示配置列表,并以详情作为标题与渠道上下文来源。
- [ ] 3.2 将页头标题调整为 `{position_name} Agent展示配置页`,并保留返回岗位展示配置列表入口。 - [ ] 3.2 将页头标题调整为 `{position_name} Agent展示配置页`,并保留返回岗位展示配置列表入口。
- [ ] 3.3 调整只读上下文区域,展示关联渠道活码名称、渠道编码、承接员工;空值展示 `-`。 - [ ] 3.3 调整只读上下文区域,展示 `qrcode_name` 对应的关联渠道活码、`position_code` 对应的渠道编码、`qrcode_employee_name` 对应的承接员工;空值展示 `-`。
- [ ] 3.4 在编辑配置弹窗恢复 `图标` 上传图片字段,状态独立于展示素材字段。 - [ ] 3.4 在编辑配置弹窗恢复 `图标` 上传图片字段,状态独立于展示素材字段。
- [ ] 3.5 实现图标上传、回显、删除、失败状态和必填校验。 - [ ] 3.5 实现图标上传、回显、删除、失败状态和必填校验。
- [ ] 3.6 保存 Agent 展示配置时提交 `icon_url`,保存成功后刷新列表并展示最新图标。 - [ ] 3.6 保存 Agent 展示配置时提交 `icon_url`,保存成功后刷新列表并展示最新图标。
......
...@@ -28,19 +28,19 @@ ...@@ -28,19 +28,19 @@
- [x] 3.1.4 处理真实 API 返回的 `CreateAgentResponse`,转换为页面需要的详情格式 - [x] 3.1.4 处理真实 API 返回的 `CreateAgentResponse`,转换为页面需要的详情格式
- [x] 3.1.5 添加保存成功提示 `保存成功` - [x] 3.1.5 添加保存成功提示 `保存成功`
- [x] 3.1.6 添加保存失败提示,展示后端错误信息 - [x] 3.1.6 添加保存失败提示,展示后端错误信息
- [x] 3.1.7 为“编辑 Agent 时当前托管企微员工 agent_count > 0 仍可选”补充失败优先测试 - [x] 3.1.7 为”编辑 Agent 时当前托管企微员工 agent_count > 0 仍可选”补充失败优先测试
- [x] 3.1.8 修复托管企微员工选项禁用逻辑:新增时禁用已挂载员工,编辑时允许当前 Agent 自己挂载的员工继续选择,仍禁用其他 Agent 挂载的员工 - [x] 3.1.8 修复托管企微员工选项禁用逻辑:新增时禁用已挂载员工,编辑时允许当前 Agent 自己挂载的员工继续选择,仍禁用其他 Agent 挂载的员工
- [x] 3.1.9 为新增/编辑 Agent 的“托管企微员工选择后必须回显并参与提交校验”补充失败优先测试 - [x] 3.1.9 为新增/编辑 Agent 的”托管企微员工选择后必须回显并参与提交校验”补充失败优先测试
- [x] 3.1.10 修复托管企微员工选择器回显与提交校验逻辑,确保新增选择和编辑详情回填都可提交 - [x] 3.1.10 修复托管企微员工选择器回显与提交校验逻辑,确保新增选择和编辑详情回填都可提交
- [x] 3.1.11 为托管企微员工真实接口场景补充失败优先测试,覆盖“接口只返回 `employee_id` / `wechat_user_id` 时仍能回显选择项” - [x] 3.1.11 为托管企微员工真实接口场景补充失败优先测试,覆盖”接口只返回 `employee_id` / `wechat_user_id` 时仍能回显选择项”
- [x] 3.1.12 修复前端托管企微员工选项映射,改用真实存在的企微侧标识承载选择器 value,避免回显丢失 - [x] 3.1.12 修复前端托管企微员工选项映射,改用真实存在的企微侧标识承载选择器 value,避免回显丢失
- [x] 3.1.13 增加编辑详情当前值保护:详情返回 `managed_user.user_id` / `managed_user.user_name` 时,未改选托管企微员工可回显并按原内部 ID 提交 - [x] 3.1.13 增加编辑详情当前值保护:详情返回 `managed_user.user_id` / `managed_user.user_name` 时,未改选托管企微员工可回显并按原内部 ID 提交
- [x] 3.1.14 按旧接口理解增加前端提交保护;后续已按 3.1.16-3.1.18 的最新接口口径替换为 `employee_id` 提交逻辑 - [x] 3.1.14 按旧接口理解增加前端提交保护;后续已按 3.1.16-3.1.18 的最新接口口径替换为 `employee_id` 提交逻辑
- [x] 3.1.15 在真实浏览器验证新增/编辑 Agent 选择托管企微员工后能够回显;编辑页保留原员工可直接保存 - [x] 3.1.15 在真实浏览器验证新增/编辑 Agent 选择托管企微员工后能够回显;编辑页保留原员工可直接保存
- [x] 3.1.16 按最新接口口径调整托管员工提交逻辑:新增或改选员工时,`managed_user_id` 取所选员工的 `employee_id` - [x] 3.1.16 按最新接口口径调整托管员工提交逻辑:新增或改选员工时,`managed_user_id` 取所选员工的 `employee_id`
- [x] 3.1.17 移除“缺少内部ID”保存拦截,并用失败优先测试覆盖新增页面选择员工后可提交 - [x] 3.1.17 移除”缺少内部ID”保存拦截,并用失败优先测试覆盖新增页面选择员工后可提交
- [x] 3.1.18 浏览器验证新增 Agent 选择托管企微员工后可以回显并发起保存请求,payload 中 `managed_user_id` 等于所选员工 `employee_id` - [x] 3.1.18 浏览器验证新增 Agent 选择托管企微员工后可以回显并发起保存请求,payload 中 `managed_user_id` 等于所选员工 `employee_id`
- [x] 3.1.19 为“详情不提供 `is_steward`,编辑页从列表项按 `agent_id` 取得管家身份”补充失败优先测试,覆盖官网字段矩阵(名称/岗位/托管员工/状态固定只读、描述必填可编辑、Skill 可选)、普通 Agent 校验与列表无匹配项时阻断编辑 - [x] 3.1.19 为”详情不提供 `is_steward`,编辑页从列表项按 `agent_id` 取得管家身份”补充失败优先测试,覆盖官网字段矩阵(名称/岗位/托管员工/状态固定只读、描述必填可编辑、Skill 可选)、普通 Agent 校验与列表无匹配项时阻断编辑
- [x] 3.1.20 修复 Agent 编辑页管家身份来源及特殊规则:加载包含当前 `agent_id` 的列表项并读取 `is_steward`,移除基于详情 `code` 的推断及缺失身份时按普通 Agent 降级的行为,并保护官网规定的管家固定字段不被提交修改 - [x] 3.1.20 修复 Agent 编辑页管家身份来源及特殊规则:加载包含当前 `agent_id` 的列表项并读取 `is_steward`,移除基于详情 `code` 的推断及缺失身份时按普通 Agent 降级的行为,并保护官网规定的管家固定字段不被提交修改
- [ ] 3.1.21 在真实浏览器验证编辑管家 Agent 时名称、岗位、专用托管员工和状态固定只读,描述可填写且 Skill 可不绑定;身份数据无法取得时页面不会开放普通 Agent 编辑提交 - [ ] 3.1.21 在真实浏览器验证编辑管家 Agent 时名称、岗位、专用托管员工和状态固定只读,描述可填写且 Skill 可不绑定;身份数据无法取得时页面不会开放普通 Agent 编辑提交
- [ ] 3.2 替换 Agent 列表页面运行时 mock 数据源,并保持列表、详情、编辑、新增、删除和状态操作可用。 - [ ] 3.2 替换 Agent 列表页面运行时 mock 数据源,并保持列表、详情、编辑、新增、删除和状态操作可用。
...@@ -52,11 +52,11 @@ ...@@ -52,11 +52,11 @@
- [x] 3.5.1 为岗位展示配置列表补充失败优先测试:真实接口列表项只有 `display_status`、没有 `operations` 时,展示中行展示 `下架`,已下架行展示 `上架`。 - [x] 3.5.1 为岗位展示配置列表补充失败优先测试:真实接口列表项只有 `display_status`、没有 `operations` 时,展示中行展示 `下架`,已下架行展示 `上架`。
- [x] 3.5.2 修复岗位展示配置列表状态按钮展示逻辑,按当前行 `display_status` 派生 `上架`/`下架` 按钮和确认弹窗,不再依赖 `operations` 字段。 - [x] 3.5.2 修复岗位展示配置列表状态按钮展示逻辑,按当前行 `display_status` 派生 `上架`/`下架` 按钮和确认弹窗,不再依赖 `operations` 字段。
- [ ] 3.6 替换官网 Agent 展示配置页面运行时 mock 数据源,并保持查询、保存、删除和可选 Agent 选择可用。 - [ ] 3.6 替换官网 Agent 展示配置页面运行时 mock 数据源,并保持查询、保存、删除和可选 Agent 选择可用。
- [ ] 3.6.1 为岗位展示配置「配置 Agent」编辑弹窗的展示素材上传补充失败优先测试:选择图片后必须调用官网素材真实上传接口,multipart 包含 `file` 与 `usage_type=agent_media`,成功后以 `file_url` 或 `cdn_url` 回填 `media_url`,保存 payload 不得包含 mock URL。 - [x] 3.6.1 为岗位展示配置「配置 Agent」编辑弹窗的展示素材上传补充失败优先测试:选择图片后必须调用官网素材真实上传接口,multipart 包含 `file` 与 `usage_type=agent_media`,成功后以 `file_url` 或 `cdn_url` 回填 `media_url`,保存 payload 不得包含 mock URL。
- [ ] 3.6.2 为岗位展示配置「配置 Agent」编辑弹窗的图标上传补充失败优先测试:选择图片后必须调用官网素材真实上传接口,multipart 包含 `file` 与 `usage_type=agent_icon`,成功后以 `file_url` 或 `cdn_url` 回填 `icon_url`,保存 payload 必须携带 `icon_url`。 - [x] 3.6.2 为岗位展示配置「配置 Agent」编辑弹窗的图标上传补充失败优先测试:选择图片后必须调用官网素材真实上传接口,multipart 包含 `file` 与 `usage_type=agent_icon`,成功后以 `file_url` 或 `cdn_url` 回填 `icon_url`,保存 payload 必须携带 `icon_url`。
- [ ] 3.6.3 修复岗位展示配置「配置 Agent」编辑弹窗上传实现:展示素材和图标均复用官网素材上传领域 API,不再生成 `https://mock.assets.local/...` 或调用旧上传端点;上传成功/失败分别展示对应反馈。 - [x] 3.6.3 修复岗位展示配置「配置 Agent」编辑弹窗上传实现:展示素材和图标均复用官网素材上传领域 API,不再生成 `https://mock.assets.local/...` 或调用旧上传端点;上传成功/失败分别展示对应反馈。
- [ ] 3.7 替换方法论配置页面运行时 mock 数据源,并保持查询、保存和上传可用。 - [ ] 3.7 替换方法论配置页面运行时 mock 数据源,并保持查询、保存和上传可用。
- [ ] 3.8 为方法论上传补充失败优先页面测试并修正校验与提交:步骤图标仅 PNG/JPG/JPEG 且最大 2MB,内容图仅 PNG/JPG/JPEG 且最大 10MB;成功状态不得读取不存在的 `file_id`。 - [x] 3.8 为方法论上传补充失败优先页面测试并修正校验与提交:步骤图标仅 PNG/JPG/JPEG 且最大 2MB,内容图仅 PNG/JPG/JPEG 且最大 10MB;成功状态不得读取不存在的 `file_id`。
## 4. 用户反馈与 fixture 边界 ## 4. 用户反馈与 fixture 边界
......
import { describe, it, expect, vi, beforeEach } from 'vitest'; import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react'; import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { AgentDisplayConfigEditModal } from './AgentDisplayConfigEditModal'; import { AgentDisplayConfigEditModal } from './AgentDisplayConfigEditModal';
...@@ -7,6 +7,7 @@ import type { OfficialSiteConfiguredAgent } from '../../api/officialSiteAgentDis ...@@ -7,6 +7,7 @@ import type { OfficialSiteConfiguredAgent } from '../../api/officialSiteAgentDis
vi.mock('../../api/officialSiteAgentDisplay', () => ({ vi.mock('../../api/officialSiteAgentDisplay', () => ({
saveAgentDisplayConfig: vi.fn(), saveAgentDisplayConfig: vi.fn(),
uploadOfficialSiteAsset: vi.fn(),
})); }));
const mockAgent: OfficialSiteConfiguredAgent = { const mockAgent: OfficialSiteConfiguredAgent = {
...@@ -160,4 +161,202 @@ describe('AgentDisplayConfigEditModal', () => { ...@@ -160,4 +161,202 @@ describe('AgentDisplayConfigEditModal', () => {
}); });
}); });
}); });
describe('展示素材真实接口上传', () => {
it('选择图片后调用真实上传接口,multipart 包含 file 与 usage_type=agent_media,成功后以 file_url 回填 media_url', async () => {
const user = userEvent.setup();
const { saveAgentDisplayConfig, uploadOfficialSiteAsset } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(uploadOfficialSiteAsset).mockResolvedValueOnce({
file_id: 'file_media_123',
file_url: 'https://cdn.real.example.com/media.gif',
file_type: 'gif',
file_size: 2048000,
});
vi.mocked(saveAgentDisplayConfig).mockResolvedValueOnce({
media_url: 'https://cdn.real.example.com/media.gif',
media_type: 'gif',
media_size: 2048000,
speech_title: '复盘 Agent',
speech_content: '智能复盘助手',
display_status: 'enable',
sort_order: 1,
});
const onSaveSuccess = vi.fn();
render(
<AgentDisplayConfigEditModal
open={true}
agent={mockAgent}
tabId={1}
onCancel={() => {}}
onSaveSuccess={onSaveSuccess}
/>
);
// 找展示素材的 FormItem 区域
const mediaFormItem = screen.getByTestId('form-item-展示素材');
const fileInput = mediaFormItem.querySelector('input[type="file"]') as HTMLInputElement;
// 使用 fireEvent.change 触发文件选择
const file = new File(['test gif content'], 'new-media.gif', { type: 'image/gif' });
fireEvent.change(fileInput, { target: { files: [file] } });
await waitFor(() => {
// 验证上传接口被调用,FormData 包含 file 和 usage_type=agent_media
expect(uploadOfficialSiteAsset).toHaveBeenCalled();
const formDataArg = vi.mocked(uploadOfficialSiteAsset).mock.calls[0][0] as FormData;
expect(formDataArg.get('usage_type')).toBe('agent_media');
expect(formDataArg.get('file')).not.toBeNull();
});
// 验证 media_url 使用真实上传结果
await waitFor(() => {
const mediaImages = screen.getAllByRole('img');
const newMedia = mediaImages.find(img => img.getAttribute('src') === 'https://cdn.real.example.com/media.gif');
expect(newMedia).toBeInTheDocument();
});
// 保存 payload 不含 mock URL
const saveButton = screen.getByRole('button', { name: '确定' });
await user.click(saveButton);
await waitFor(() => {
expect(saveAgentDisplayConfig).toHaveBeenCalledWith(1, 101, {
speech_title: '复盘 Agent',
speech_content: '智能复盘助手',
display_status: 'enable',
sort_order: 1,
media_url: 'https://cdn.real.example.com/media.gif',
media_type: 'gif',
media_size: 2048000,
icon_url: 'https://cdn.example.com/icon.png',
});
});
});
it('展示素材上传失败展示错误反馈', async () => {
const { uploadOfficialSiteAsset } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(uploadOfficialSiteAsset).mockRejectedValueOnce(new Error('上传失败:文件大小超过限制'));
render(
<AgentDisplayConfigEditModal
open={true}
agent={mockAgent}
tabId={1}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
const mediaFormItem = screen.getByTestId('form-item-展示素材');
const fileInput = mediaFormItem.querySelector('input[type="file"]') as HTMLInputElement;
const file = new File(['test'], 'oversized.gif', { type: 'image/gif' });
fireEvent.change(fileInput, { target: { files: [file] } });
await waitFor(() => {
expect(screen.getByText(/上传失败/)).toBeInTheDocument();
});
});
});
describe('图标真实接口上传', () => {
it('选择图片后调用真实上传接口,multipart 包含 file 与 usage_type=agent_icon,成功后以 file_url 回填 icon_url', async () => {
const user = userEvent.setup();
const { saveAgentDisplayConfig, uploadOfficialSiteAsset } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(uploadOfficialSiteAsset).mockResolvedValueOnce({
file_id: 'file_icon_456',
file_url: 'https://cdn.real.example.com/icon.png',
file_type: 'png',
file_size: 50000,
});
vi.mocked(saveAgentDisplayConfig).mockResolvedValueOnce({
media_url: 'https://cdn.example.com/media.gif',
media_type: 'gif',
media_size: 0,
speech_title: '复盘 Agent',
speech_content: '智能复盘助手',
display_status: 'enable',
sort_order: 1,
});
const onSaveSuccess = vi.fn();
render(
<AgentDisplayConfigEditModal
open={true}
agent={mockAgent}
tabId={1}
onCancel={() => {}}
onSaveSuccess={onSaveSuccess}
/>
);
// 找图标的 FormItem 区域
const iconFormItem = screen.getByTestId('form-item-图标');
const fileInput = iconFormItem.querySelector('input[type="file"]') as HTMLInputElement;
// 使用 fireEvent.change 触发文件选择
const file = new File(['test icon content'], 'new-icon.png', { type: 'image/png' });
fireEvent.change(fileInput, { target: { files: [file] } });
await waitFor(() => {
// 验证上传接口被调用,FormData 包含 file 和 usage_type=agent_icon
expect(uploadOfficialSiteAsset).toHaveBeenCalled();
const formDataArg = vi.mocked(uploadOfficialSiteAsset).mock.calls[0][0] as FormData;
expect(formDataArg.get('usage_type')).toBe('agent_icon');
expect(formDataArg.get('file')).not.toBeNull();
});
// 验证 icon_url 使用真实上传结果
await waitFor(() => {
const iconImages = screen.getAllByRole('img');
const newIcon = iconImages.find(img => img.getAttribute('src') === 'https://cdn.real.example.com/icon.png');
expect(newIcon).toBeInTheDocument();
});
// 保存 payload 必须携带真实 icon_url
const saveButton = screen.getByRole('button', { name: '确定' });
await user.click(saveButton);
await waitFor(() => {
expect(saveAgentDisplayConfig).toHaveBeenCalledWith(1, 101, {
speech_title: '复盘 Agent',
speech_content: '智能复盘助手',
display_status: 'enable',
sort_order: 1,
media_url: 'https://cdn.example.com/media.gif',
media_type: 'gif',
media_size: 0,
icon_url: 'https://cdn.real.example.com/icon.png',
});
});
});
it('图标上传失败展示错误反馈', async () => {
const { uploadOfficialSiteAsset } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(uploadOfficialSiteAsset).mockRejectedValueOnce(new Error('上传失败:不支持的文件格式'));
render(
<AgentDisplayConfigEditModal
open={true}
agent={mockAgent}
tabId={1}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
const iconFormItem = screen.getByTestId('form-item-图标');
const fileInput = iconFormItem.querySelector('input[type="file"]') as HTMLInputElement;
const file = new File(['test'], 'invalid.bmp', { type: 'image/bmp' });
fireEvent.change(fileInput, { target: { files: [file] } });
await waitFor(() => {
expect(screen.getByText(/上传失败/)).toBeInTheDocument();
});
});
});
}); });
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,7 @@ import { useState, useEffect } from 'react'; ...@@ -3,6 +3,7 @@ import { useState, useEffect } from 'react';
import { Button, FormItem, Input, MediaWall, Modal, Select } from '../../../packages/ui/src'; import { Button, FormItem, Input, MediaWall, Modal, Select } from '../../../packages/ui/src';
import { import {
saveAgentDisplayConfig, saveAgentDisplayConfig,
uploadOfficialSiteAsset,
type OfficialSiteConfiguredAgent, type OfficialSiteConfiguredAgent,
type DisplayStatus, type DisplayStatus,
type MediaType, type MediaType,
...@@ -23,6 +24,7 @@ interface EditFormState { ...@@ -23,6 +24,7 @@ interface EditFormState {
display_status: DisplayStatus; display_status: DisplayStatus;
media_url: string; media_url: string;
media_type: MediaType; media_type: MediaType;
media_size: number;
icon_url: string; icon_url: string;
} }
...@@ -32,6 +34,8 @@ interface EditFormErrors { ...@@ -32,6 +34,8 @@ interface EditFormErrors {
speech_title?: string; speech_title?: string;
media_url?: string; media_url?: string;
icon_url?: string; icon_url?: string;
upload_media?: string;
upload_icon?: string;
} }
export function AgentDisplayConfigEditModal({ export function AgentDisplayConfigEditModal({
...@@ -48,11 +52,14 @@ export function AgentDisplayConfigEditModal({ ...@@ -48,11 +52,14 @@ export function AgentDisplayConfigEditModal({
display_status: 'disable', display_status: 'disable',
media_url: '', media_url: '',
media_type: 'gif', media_type: 'gif',
media_size: 0,
icon_url: '', icon_url: '',
}); });
const [errors, setErrors] = useState<EditFormErrors>({}); const [errors, setErrors] = useState<EditFormErrors>({});
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const [uploadingMedia, setUploadingMedia] = useState(false);
const [uploadingIcon, setUploadingIcon] = useState(false);
useEffect(() => { useEffect(() => {
if (agent) { if (agent) {
...@@ -63,6 +70,7 @@ export function AgentDisplayConfigEditModal({ ...@@ -63,6 +70,7 @@ export function AgentDisplayConfigEditModal({
display_status: agent.display_status ?? 'disable', display_status: agent.display_status ?? 'disable',
media_url: agent.media_url ?? '', media_url: agent.media_url ?? '',
media_type: agent.media_type ?? 'gif', media_type: agent.media_type ?? 'gif',
media_size: 0,
icon_url: agent.icon_url ?? '', icon_url: agent.icon_url ?? '',
}); });
setErrors({}); setErrors({});
...@@ -113,7 +121,7 @@ export function AgentDisplayConfigEditModal({ ...@@ -113,7 +121,7 @@ export function AgentDisplayConfigEditModal({
sort_order: form.sort_order, sort_order: form.sort_order,
media_url: form.media_url, media_url: form.media_url,
media_type: form.media_type, media_type: form.media_type,
media_size: 0, media_size: form.media_size,
icon_url: form.icon_url, icon_url: form.icon_url,
}); });
setSaving(false); setSaving(false);
...@@ -129,7 +137,9 @@ export function AgentDisplayConfigEditModal({ ...@@ -129,7 +137,9 @@ export function AgentDisplayConfigEditModal({
...current, ...current,
media_url: '', media_url: '',
media_type: 'gif', media_type: 'gif',
media_size: 0,
})); }));
setErrors((current) => ({ ...current, upload_media: undefined, media_url: undefined }));
}; };
const handleRemoveIcon = () => { const handleRemoveIcon = () => {
...@@ -137,6 +147,60 @@ export function AgentDisplayConfigEditModal({ ...@@ -137,6 +147,60 @@ export function AgentDisplayConfigEditModal({
...current, ...current,
icon_url: '', icon_url: '',
})); }));
setErrors((current) => ({ ...current, upload_icon: undefined, icon_url: undefined }));
};
const handleUploadMedia = async (files: File[]) => {
const file = files[0];
if (!file) return;
setUploadingMedia(true);
setErrors((current) => ({ ...current, upload_media: undefined }));
try {
const formData = new FormData();
formData.append('file', file);
formData.append('usage_type', 'agent_media');
const result = await uploadOfficialSiteAsset(formData);
const isVideo = file.type === 'video/mp4';
setForm((current) => ({
...current,
media_url: result.file_url,
media_type: isVideo ? 'mp4' : 'gif',
media_size: result.file_size,
}));
} catch (err) {
const message = err instanceof Error ? err.message : '上传失败';
setErrors((current) => ({ ...current, upload_media: `上传失败:${message}` }));
} finally {
setUploadingMedia(false);
}
};
const handleUploadIcon = async (files: File[]) => {
const file = files[0];
if (!file) return;
setUploadingIcon(true);
setErrors((current) => ({ ...current, upload_icon: undefined }));
try {
const formData = new FormData();
formData.append('file', file);
formData.append('usage_type', 'agent_icon');
const result = await uploadOfficialSiteAsset(formData);
setForm((current) => ({
...current,
icon_url: result.file_url,
}));
} catch (err) {
const message = err instanceof Error ? err.message : '上传失败';
setErrors((current) => ({ ...current, upload_icon: `上传失败:${message}` }));
} finally {
setUploadingIcon(false);
}
}; };
if (!agent) return null; if (!agent) return null;
...@@ -176,21 +240,14 @@ export function AgentDisplayConfigEditModal({ ...@@ -176,21 +240,14 @@ export function AgentDisplayConfigEditModal({
/> />
</FormItem> </FormItem>
<FormItem label="图标" layout="horizontal" required error={errors.icon_url}> <FormItem label="图标" layout="horizontal" required error={errors.icon_url || errors.upload_icon}>
<MediaWall <MediaWall
accept="image/png,image/jpeg,image/jpg,image/gif" accept="image/png,image/jpeg,image/jpg,image/gif"
maxCount={1} maxCount={1}
multiple={false} multiple={false}
items={iconItems} items={iconItems}
helperText="支持图片、GIF,推荐 1:1,最大 5MB" helperText="支持图片、GIF,推荐 1:1,最大 5MB"
onSelectFiles={(files) => { onSelectFiles={handleUploadIcon}
const file = files[0];
if (!file) return;
setForm((current) => ({
...current,
icon_url: `https://mock.assets.local/uploads/icon-${file.name}`,
}));
}}
onRemove={handleRemoveIcon} onRemove={handleRemoveIcon}
/> />
</FormItem> </FormItem>
...@@ -204,23 +261,14 @@ export function AgentDisplayConfigEditModal({ ...@@ -204,23 +261,14 @@ export function AgentDisplayConfigEditModal({
/> />
</FormItem> </FormItem>
<FormItem label="展示素材" layout="horizontal" required error={errors.media_url}> <FormItem label="展示素材" layout="horizontal" required error={errors.media_url || errors.upload_media}>
<MediaWall <MediaWall
accept="image/png,image/jpeg,image/jpg,image/gif,video/mp4" accept="image/png,image/jpeg,image/jpg,image/gif,video/mp4"
maxCount={1} maxCount={1}
multiple={false} multiple={false}
items={mediaItems} items={mediaItems}
helperText="支持图片、视频、GIF,推荐 1:1,最大 20MB" helperText="支持图片、视频、GIF,推荐 1:1,最大 20MB"
onSelectFiles={(files) => { onSelectFiles={handleUploadMedia}
const file = files[0];
if (!file) return;
const isVideo = file.type === 'video/mp4';
setForm((current) => ({
...current,
media_url: `https://mock.assets.local/uploads/${file.name}`,
media_type: isVideo ? 'mp4' : 'gif',
}));
}}
onRemove={handleRemoveMedia} onRemove={handleRemoveMedia}
/> />
</FormItem> </FormItem>
......
import { fireEvent, render, screen } from '@testing-library/react'; import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest'; import { beforeEach, describe, expect, it, vi } from 'vitest';
import { App } from '../../App'; import { App } from '../../App';
import { resetAgentDisplayConfigMockState } from '../../../packages/contracts/official-site-agent-display-config-mock'; import { getOfficialSiteTabDetail, getOfficialSiteTabList, type OfficialSiteTabDetail, type OfficialSiteTabListItem } from '../../api/officialSiteTab';
import { resetOfficialSiteJobTabMockState } from '../../../packages/contracts/official-site-job-tab-mock'; import { getConfiguredAgents, type OfficialSiteConfiguredAgentsResponse } from '../../api/officialSiteAgentDisplay';
vi.mock('../../api/officialSiteTab', () => ({
getOfficialSiteTabDetail: vi.fn(),
getOfficialSiteTabList: vi.fn(),
updateOfficialSiteTabStatus: vi.fn(),
deleteOfficialSiteTab: vi.fn(),
createOfficialSiteTab: vi.fn(),
updateOfficialSiteTab: vi.fn(),
getAvailableQRCodes: vi.fn(),
}));
vi.mock('../../api/officialSiteAgentDisplay', () => ({
getConfiguredAgents: vi.fn(),
saveAgentDisplayConfig: vi.fn(),
deleteAgentDisplayConfig: vi.fn(),
uploadOfficialSiteAsset: vi.fn(),
}));
const mockTabDetail: OfficialSiteTabDetail = {
tab_id: 1,
position_code: 'store_sales',
position_name: '店销顾问',
qrcode_id: 1,
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
main_title: 'AI 智能助手提升店销效率',
sub_title: '通过 AI 智能问答帮助店销顾问快速响应客户需求',
display_status: 'enable',
sort_order: 10,
};
const mockTabListItem: OfficialSiteTabListItem = {
tab_id: 1,
position_code: 'store_sales',
position_name: '店销顾问',
main_title: 'AI 智能助手提升店销效率',
sub_title: '通过 AI 智能问答帮助店销顾问快速响应客户需求',
qrcode_id: 1,
qrcode_name: '店销顾问渠道活码',
qrcode_url: 'https://cdn.example.com/qrcode.png',
qrcode_status: 'enable',
display_status: 'enable',
sort_order: 10,
agent_count: 3,
created_at: '2026-05-10 09:00:00',
operations: ['edit', 'disable', 'delete', 'configureAgent'],
};
const mockConfiguredAgents: OfficialSiteConfiguredAgentsResponse = {
tab_id: '1',
position_name: '店销顾问',
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
configured_agents: [
{
config_id: 'c1',
agent_id: '101',
agent_name: '复盘Agent',
media_url: 'https://cdn.example.com/media.gif',
media_type: 'gif',
speech_title: '复盘Agent',
speech_content: '帮助店销顾问完成每日复盘',
display_status: 'enable',
sort_order: 10,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icon.png',
},
{
config_id: 'c2',
agent_id: '102',
agent_name: '质检Agent',
media_url: '',
media_type: 'gif',
speech_title: '',
speech_content: '',
display_status: 'disable',
sort_order: 30,
agent_status: 'disable',
},
{
config_id: 'c3',
agent_id: '103',
agent_name: '销售助手Agent',
media_url: 'https://cdn.example.com/media2.gif',
media_type: 'gif',
speech_title: '销售助手Agent',
speech_content: '智能推荐话术',
display_status: 'disable',
sort_order: 20,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icon2.png',
},
],
};
function renderApp(path = '/official-site/job-tabs/1/agents') { function renderApp(path = '/official-site/job-tabs/1/agents') {
window.localStorage.setItem('agent-admin-local-login', 'true'); window.localStorage.setItem('agent-admin-local-login', 'true');
...@@ -18,13 +116,24 @@ function renderApp(path = '/official-site/job-tabs/1/agents') { ...@@ -18,13 +116,24 @@ function renderApp(path = '/official-site/job-tabs/1/agents') {
describe('official site agent display config routes and navigation', () => { describe('official site agent display config routes and navigation', () => {
beforeEach(() => { beforeEach(() => {
window.localStorage.clear(); window.localStorage.clear();
resetOfficialSiteJobTabMockState(); vi.clearAllMocks();
resetAgentDisplayConfigMockState(); // 默认 mock 成功响应
vi.mocked(getOfficialSiteTabDetail).mockResolvedValue(mockTabDetail);
vi.mocked(getConfiguredAgents).mockResolvedValue(mockConfiguredAgents);
vi.mocked(getOfficialSiteTabList).mockResolvedValue({
list: [mockTabListItem],
total: 1,
page: 1,
page_size: 10,
});
}); });
it('renders the agent display config page at /official-site/job-tabs/:tabId/agents', () => { it('renders the agent display config page at /official-site/job-tabs/:tabId/agents', async () => {
renderApp(); renderApp();
expect(screen.getByRole('heading', { name: '店销顾问 - 店销顾问渠道活码 - Agent展示配置' })).toBeInTheDocument(); // 等待加载完成,标题只展示岗位名称,不拼接渠道活码名称
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
}); });
it('shows navigation entry under 官网配置 group', () => { it('shows navigation entry under 官网配置 group', () => {
...@@ -47,33 +156,74 @@ describe('official site agent display config routes and navigation', () => { ...@@ -47,33 +156,74 @@ describe('official site agent display config routes and navigation', () => {
expect(screen.getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '返回' })).toBeInTheDocument();
}); });
it('shows position name in page title', () => { it('shows position name in page title', async () => {
renderApp(); renderApp();
expect(screen.getByRole('heading', { name: /店销顾问.*Agent展示配置/ })).toBeInTheDocument(); // 标题为 "{岗位名称} Agent展示配置页"
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
}); });
it('shows tab context info (qrcode, channel code, employee)', () => { it('shows tab context info (qrcode, channel code, employee)', async () => {
renderApp(); renderApp();
expect(screen.getByText('店销顾问渠道活码')).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByText('DSC-QR-001')).toBeInTheDocument(); expect(screen.getByText('店销顾问渠道活码')).toBeInTheDocument();
expect(screen.getByText((content) => content.includes('张小萌'))).toBeInTheDocument(); expect(screen.getByText('DSC-QR-001')).toBeInTheDocument();
expect(screen.getByText((content) => content.includes('张小萌'))).toBeInTheDocument();
});
}); });
it('returns to job tabs list when clicking return button', () => { it('calls getOfficialSiteTabDetail API with correct endpoint', async () => {
renderApp(); renderApp();
await waitFor(() => {
expect(getOfficialSiteTabDetail).toHaveBeenCalledWith(1);
});
});
it('returns to job tabs list when clicking return button', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
fireEvent.click(screen.getByRole('button', { name: '返回' })); fireEvent.click(screen.getByRole('button', { name: '返回' }));
expect(screen.getByRole('heading', { name: '岗位展示配置' })).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByRole('heading', { name: '岗位展示配置' })).toBeInTheDocument();
});
}); });
it('shows error state for non-existent tab', () => { it('shows error state when tab detail request fails', async () => {
vi.mocked(getOfficialSiteTabDetail).mockRejectedValueOnce(new Error('岗位展示配置不存在'));
renderApp();
await waitFor(() => {
expect(screen.getByText('加载失败')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重试' })).toBeInTheDocument();
});
});
it('shows error state for non-existent tab', async () => {
vi.mocked(getOfficialSiteTabDetail).mockRejectedValueOnce(new Error('岗位展示配置不存在'));
renderApp('/official-site/job-tabs/99999/agents'); renderApp('/official-site/job-tabs/99999/agents');
expect(screen.getByText('岗位展示配置不存在')).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByRole('button', { name: '返回列表' })).toBeInTheDocument(); expect(screen.getByText('加载失败')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重试' })).toBeInTheDocument();
});
}); });
it('can navigate to agent display config from job tabs list', () => { it('can retry after load error', async () => {
renderApp('/official-site/job-tabs'); vi.mocked(getOfficialSiteTabDetail).mockRejectedValueOnce(new Error('加载失败'));
fireEvent.click(screen.getByRole('button', { name: '配置Agent-店销顾问' })); vi.mocked(getOfficialSiteTabDetail).mockResolvedValueOnce(mockTabDetail);
expect(screen.getByRole('heading', { name: /店销顾问.*Agent展示配置/ })).toBeInTheDocument();
renderApp();
await waitFor(() => {
expect(screen.getByText('加载失败')).toBeInTheDocument();
});
fireEvent.click(screen.getByRole('button', { name: '重试' }));
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
}); });
}); });
\ No newline at end of file \ No newline at end of file
...@@ -32,15 +32,14 @@ function renderMethodology(path = '/official-site/methodology') { ...@@ -32,15 +32,14 @@ function renderMethodology(path = '/official-site/methodology') {
); );
} }
/** 点击 TDesign image-flow 主题的删除图标 */ /** 获取步骤图标的文件输入(第一个 MediaWall) */
function clickDeleteIcon(container: HTMLElement) { function getStepIconInput(card: HTMLElement): HTMLInputElement | null {
const maskItems = container.querySelectorAll('.t-upload__card-mask-item'); // 每个 card 有两个 MediaWall:步骤图标和内容图
// 第一个 mask-item 是预览图标,第二个是删除图标 // 步骤图标的 input 在第一个 .t-upload 容器中
const deleteMaskItem = maskItems[1] as HTMLElement; const uploadContainers = card.querySelectorAll('.t-upload');
const deleteIcon = deleteMaskItem?.querySelector('.t-icon-delete') as HTMLElement; if (uploadContainers.length < 1) return null;
if (deleteIcon) { const stepIconUpload = uploadContainers[0];
fireEvent.click(deleteIcon); return stepIconUpload.querySelector('input[type="file"]') as HTMLInputElement;
}
} }
/** 获取内容图的文件输入(第二个 MediaWall) */ /** 获取内容图的文件输入(第二个 MediaWall) */
...@@ -53,12 +52,15 @@ function getContentImageInput(card: HTMLElement): HTMLInputElement | null { ...@@ -53,12 +52,15 @@ function getContentImageInput(card: HTMLElement): HTMLInputElement | null {
return contentImageUpload.querySelector('input[type="file"]') as HTMLInputElement; return contentImageUpload.querySelector('input[type="file"]') as HTMLInputElement;
} }
/** 获取步骤图标的文件输入(第一个 MediaWall) */ /** 点击 TDesign image-flow 主题的删除图标 */
function getStepIconInput(card: HTMLElement): HTMLInputElement | null { function clickDeleteIcon(container: HTMLElement) {
const uploadContainers = card.querySelectorAll('.t-upload'); const maskItems = container.querySelectorAll('.t-upload__card-mask-item');
if (uploadContainers.length < 1) return null; // 第一个 mask-item 是预览图标,第二个是删除图标
const stepIconUpload = uploadContainers[0]; const deleteMaskItem = maskItems[1] as HTMLElement;
return stepIconUpload.querySelector('input[type="file"]') as HTMLInputElement; const deleteIcon = deleteMaskItem?.querySelector('.t-icon-delete') as HTMLElement;
if (deleteIcon) {
fireEvent.click(deleteIcon);
}
} }
describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
...@@ -244,4 +246,183 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -244,4 +246,183 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
{ timeout: 10000 }, { timeout: 10000 },
); );
}); });
describe('步骤图标校验', () => {
it('步骤图标仅支持 PNG/JPG/JPEG,不支持 BMP', async () => {
renderMethodology();
await waitFor(() => {
expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(2);
});
const firstCard = screen.getAllByTestId('methodology-step-card')[0];
// 删除已有步骤图标
const uploadContainers = firstCard.querySelectorAll('.t-upload__card');
if (uploadContainers.length >= 1) {
clickDeleteIcon(uploadContainers[0] as HTMLElement);
}
const stepIconInput = getStepIconInput(firstCard);
if (!stepIconInput) {
throw new Error('Step icon input not found');
}
// BMP 不支持
fireEvent.change(stepIconInput, {
target: { files: [new File(['demo'], 'icon.bmp', { type: 'image/bmp' })] },
});
await waitFor(() => {
expect(within(firstCard).getByText('步骤图标仅支持 PNG/JPG/JPEG')).toBeInTheDocument();
});
});
it('步骤图标大小不能超过 2MB', async () => {
renderMethodology();
await waitFor(() => {
expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(2);
});
const firstCard = screen.getAllByTestId('methodology-step-card')[0];
// 删除已有步骤图标
const uploadContainers = firstCard.querySelectorAll('.t-upload__card');
if (uploadContainers.length >= 1) {
clickDeleteIcon(uploadContainers[0] as HTMLElement);
}
const stepIconInput = getStepIconInput(firstCard);
if (!stepIconInput) {
throw new Error('Step icon input not found');
}
// 超过 2MB
const oversized = new File(['demo'], 'icon.png', { type: 'image/png' });
Object.defineProperty(oversized, 'size', { value: 2 * 1024 * 1024 + 1 });
fireEvent.change(stepIconInput, {
target: { files: [oversized] },
});
await waitFor(() => {
expect(within(firstCard).getByText('步骤图标大小不能超过 2MB')).toBeInTheDocument();
});
});
it('步骤图标上传成功后使用 file_url,不读取不存在的 file_id', async () => {
renderMethodology();
await waitFor(() => {
expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(2);
});
const firstCard = screen.getAllByTestId('methodology-step-card')[0];
// 删除已有步骤图标
const uploadContainers = firstCard.querySelectorAll('.t-upload__card');
if (uploadContainers.length >= 1) {
clickDeleteIcon(uploadContainers[0] as HTMLElement);
}
const stepIconInput = getStepIconInput(firstCard);
if (!stepIconInput) {
throw new Error('Step icon input not found');
}
// 上传成功
vi.mocked(uploadMethodologyAsset).mockResolvedValueOnce({
file_id: 'file_icon_new',
file_url: 'https://cdn.example.com/new-icon.png',
file_type: 'png',
file_size: 50000,
});
const validFile = new File(['icon content'], 'new-icon.png', { type: 'image/png' });
fireEvent.change(stepIconInput, {
target: { files: [validFile] },
});
await waitFor(() => {
expect(uploadMethodologyAsset).toHaveBeenCalled();
const formDataArg = vi.mocked(uploadMethodologyAsset).mock.calls[0][0] as FormData;
expect(formDataArg.get('usage_type')).toBe('methodology_icon');
expect(formDataArg.get('file')).not.toBeNull();
});
// 验证预览使用 file_url
await waitFor(() => {
const images = within(firstCard).getAllByRole('img');
const newIconImg = images.find(img => img.getAttribute('src') === 'https://cdn.example.com/new-icon.png');
expect(newIconImg).toBeInTheDocument();
});
// 保存时使用 file_url,不依赖 file_id
fireEvent.click(screen.getByRole('button', { name: '保存配置' }));
await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled();
const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0];
// 第一个步骤的 step_icon 应该是新的 file_url
expect(savePayload.steps[0].step_icon).toBe('https://cdn.example.com/new-icon.png');
});
});
});
describe('内容图上传成功状态', () => {
it('内容图上传成功后使用 file_url,不读取不存在的 file_id', async () => {
renderMethodology();
await waitFor(() => {
expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(2);
});
const firstCard = screen.getAllByTestId('methodology-step-card')[0];
// 删除已有内容图
const uploadContainers = firstCard.querySelectorAll('.t-upload__card');
if (uploadContainers.length >= 2) {
clickDeleteIcon(uploadContainers[1] as HTMLElement);
}
const contentImageInput = getContentImageInput(firstCard);
if (!contentImageInput) {
throw new Error('Content image input not found');
}
// 上传成功
vi.mocked(uploadMethodologyAsset).mockResolvedValueOnce({
file_id: 'file_content_new',
file_url: 'https://cdn.example.com/new-content.png',
file_type: 'png',
file_size: 500000,
});
const validFile = new File(['content'], 'new-content.png', { type: 'image/png' });
fireEvent.change(contentImageInput, {
target: { files: [validFile] },
});
await waitFor(() => {
expect(uploadMethodologyAsset).toHaveBeenCalled();
const formDataArg = vi.mocked(uploadMethodologyAsset).mock.calls[0][0] as FormData;
expect(formDataArg.get('usage_type')).toBe('methodology_image');
expect(formDataArg.get('file')).not.toBeNull();
});
// 验证预览使用 file_url
await waitFor(() => {
const images = within(firstCard).getAllByRole('img');
const newContentImg = images.find(img => img.getAttribute('src') === 'https://cdn.example.com/new-content.png');
expect(newContentImg).toBeInTheDocument();
});
// 保存时使用 file_url,不依赖 file_id
fireEvent.click(screen.getByRole('button', { name: '保存配置' }));
await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled();
const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0];
// 第一个步骤的 step_image 应该是新的 file_url
expect(savePayload.steps[0].step_image).toBe('https://cdn.example.com/new-content.png');
});
});
});
}); });
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!