From a4744570e1fe284be91b28ac7fafc062936c78fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sat, 21 Nov 2026 04:26:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(phase-5):=20=E4=BA=AC=E4=B8=9C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=A1=B5=E9=87=8D=E5=86=99=E8=A3=85=E9=85=8D?= =?UTF-8?q?=E2=80=94=E2=80=94=E4=BE=A7=E6=A0=8F+=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=BD=91=E6=A0=BC+=E5=B1=85=E4=B8=AD=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=EF=BC=9B=E7=BA=A7=E8=81=94=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?/=E8=AF=A6=E6=83=85=E6=8A=BD=E5=B1=89=E9=80=80=E5=BD=B9?= =?UTF-8?q?=EF=BC=88AC-9=20=E5=8F=82=E6=95=B0=E9=80=90=E5=AD=97=E7=AD=89?= =?UTF-8?q?=E4=BB=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/jd/JdCategoryCascader.vue | 524 ------ .../src/pages/jd/JdDatabasePage.vue | 411 ++--- .../src/pages/jd/JdProductDetailDrawer.vue | 89 -- .../pages/jd/jd-category-cascader-position.ts | 29 - .../src/pages/jd/jd-database-page.css | 282 +--- .../jd-category-cascader-position.test.ts | 37 - .../mount/jd-category-cascader.mount.test.ts | 82 - .../mount/jd-database-page.mount.test.ts | 1417 ++++++++--------- 8 files changed, 964 insertions(+), 1907 deletions(-) delete mode 100644 admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue delete mode 100644 admin-frontend-vue/src/pages/jd/JdProductDetailDrawer.vue delete mode 100644 admin-frontend-vue/src/pages/jd/jd-category-cascader-position.ts delete mode 100644 admin-frontend-vue/tests/jd-category-cascader-position.test.ts delete mode 100644 admin-frontend-vue/tests/mount/jd-category-cascader.mount.test.ts diff --git a/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue b/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue deleted file mode 100644 index f43206507..000000000 --- a/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue +++ /dev/null @@ -1,524 +0,0 @@ - - - - - diff --git a/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue b/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue index eb9fe3fc3..f5b12e257 100644 --- a/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue +++ b/admin-frontend-vue/src/pages/jd/JdDatabasePage.vue @@ -1,13 +1,17 @@ - - - - diff --git a/admin-frontend-vue/src/pages/jd/jd-category-cascader-position.ts b/admin-frontend-vue/src/pages/jd/jd-category-cascader-position.ts deleted file mode 100644 index 6a688937d..000000000 --- a/admin-frontend-vue/src/pages/jd/jd-category-cascader-position.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** 类目级联面板的水平定位钳制(2026-11-16 客户截图「超出视窗了」:面板锚在触发框 - * left:0,下钻到 3~4 栏时宽 600~800px,而「类目」筛选框在 jd-filter-row 流式布局里 - * 常落在页面中部偏右 ⇒ 面板右半截伸出视窗,末栏被窗缘裁到只剩一列 radio 圆点)。 - * - * 本文件是**纯钳制数学**(零依赖,node --test 可直测):默认锚左(偏移 0);视口右缘 - * 装不下时整体左移到右缘贴齐(留 margin),左移后越出左缘则贴左缘为止。组件侧在面板 - * 打开与栏数/搜索态变化后用真实 rect 调它(JdCategoryCascader.vue),栏数随下钻动态 - * 1~4,宽度变了要重算——右贴齐后继续下钻即向左生长,不会再伸出右缘。 */ - -export interface PanelClampInput { - /** 触发框(.cat-cascader)的视口左缘 x。 */ - hostLeft: number - /** 面板当前实际渲染宽(含边框;栏数不同宽度不同)。 */ - panelWidth: number - /** 视口宽(window.innerWidth)。 */ - viewportWidth: number - /** 视口两侧最小留白,默认 8px。 */ - margin?: number -} - -/** 返回面板相对触发框左缘应加的 left 偏移(px;负=左移、0=默认锚左即可、正=触发框 - * 本身已贴近视口左缘时把面板推回 margin 内,物理上只在窄窗极端值出现)。 */ -export function clampPanelLeftX(input: PanelClampInput): number { - const margin = input.margin ?? 8 - const overflowRight = input.hostLeft + input.panelWidth - (input.viewportWidth - margin) - if (overflowRight <= 0) return 0 - const desiredLeft = Math.max(margin, input.hostLeft - overflowRight) - return desiredLeft - input.hostLeft -} diff --git a/admin-frontend-vue/src/pages/jd/jd-database-page.css b/admin-frontend-vue/src/pages/jd/jd-database-page.css index 09d1f4019..1b43885b4 100644 --- a/admin-frontend-vue/src/pages/jd/jd-database-page.css +++ b/admin-frontend-vue/src/pages/jd/jd-database-page.css @@ -1,10 +1,12 @@ -/* 像素复刻「外观专利数据库」页样式(panel-box + 自绘表格 + 旧式分页);列表只摆部分字段,全量属性在详情抽屉。 */ +/* 京东数据库页样式(v1.6 蓝图 Phase 5 重写装配):左侧栏(类目树/分类平铺)+主面板 + (筛选行+工具栏+卡片网格+旧式分页)。旧自绘表格样式随操作列/表格退役整体摘除; + 列表字段映射收进 JdProductCard scoped 样式,本文件只管页面装配层。 */ .jd-database-view { font-family: inherit; color: var(--c-text, #24384d); display: flex; - flex-direction: column; - gap: 18px; + align-items: flex-start; + gap: 16px; } .panel-box { width: 100%; @@ -15,6 +17,12 @@ background: linear-gradient(145deg, #ffffff, #f9fbfd); box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28); } +/* 主面板在「侧栏+主区」横排里吃掉剩余宽度;窄屏(侧栏 232px 起占位)允许整行折行 + 由 .jd-database-view 的 flex-wrap 兜住,面板自身保持弹性收缩。 */ +.jd-main-panel { + flex: 1 1 480px; + min-width: 0; +} h3 { margin: 0 0 16px; font-size: 15px; @@ -32,8 +40,8 @@ h3 { margin: 0; } .jd-filter-row { - /* 可换行流式布局:固定 6 列 minmax(140px) 的网格在窄面板下最小宽超出容器, - 把查询/重置挤出面板右缘(与「管理分组」重叠)。flex-wrap 让放不下的项自然折行。 */ + /* 可换行流式布局:固定网格在窄面板下最小宽超出容器,把查询/重置挤出面板右缘。 + flex-wrap 让放不下的项自然折行。 */ display: flex; flex-wrap: wrap; gap: 12px; @@ -84,8 +92,31 @@ h3 { border-color: #5f85ad; box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16); } -.form-group input[type="date"] { - color-scheme: light; +/* 归属三档下拉(分类状态快筛):42px 外壳、9px 圆角、#cbd9e6 描边与 focus ring 都由 + 全局 .el-select.admin-filter 皮肤(main.css)出——与亚马逊面同一套。只钉筛选行里的 + 下拉位宽(admin-filter 出厂 width:100%,进 flex 行会横涨);用直接子级选择器, + 别误伤「分组」表单组里嵌的同款下拉(那个跟 form-group 走宽)。 */ +.jd-filter-row > .el-select.admin-filter { + width: 200px; + flex-shrink: 0; +} +/* 工具栏(v1.6 重排):全选本页/取消本页|归入分类/取消归属|删除商品。旧「批量动作条 + 并入筛选行」的形状(2026-11-17)随卡片化重排收回独立一行——筛选行只留筛选与查询, + 批量动作贴着卡片网格,勾选的目标物(卡片)就在下一屏。 */ +.jd-toolbar { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 10px; + margin-bottom: 14px; +} +.jd-toolbar .btn { + min-height: 34px; + padding: 5px 14px; +} +/* 危险动作(删除商品)推到行尾:留在归类动作旁边会被读成同一组动作。 */ +.jd-delete-btn { + margin-left: auto; } .btn { display: inline-flex; @@ -122,27 +153,7 @@ h3 { border-color: #95b1cb; background: #edf5fb; } -/* 批量动作条(2026-11-17 用户口径「汇总删掉、工具栏整体上移」):并入 .jd-filter-row - 与查询/重置同排,不再有独立 .jd-toolbar 容器;放不下靠筛选行的 flex-wrap 折行。 */ -/* 分类筛选/状态快筛下拉(2026-11-17 用户口径「和亚马逊不统一」起换 el-select):42px 外壳、 - 9px 圆角、#cbd9e6 描边、#f8fbfd 浅底与 focus ring 都由全局 .el-select.admin-filter - 皮肤(main.css)出——与亚马逊面同一套,弹层不再是浏览器原生直角列表。 - 只钉动作条里的下拉位宽(admin-filter 出厂 width:100%,进 flex 行会横涨); - 用直接子级选择器,别误伤「分组」表单组里嵌的同款下拉(那个跟 form-group 走宽)。 */ -.jd-filter-row > .el-select.admin-filter { - width: 200px; - flex-shrink: 0; -} -/* 危险动作(批量删除)推到行尾:留在「批量编辑分类/分类筛选」旁边会被读成同一组动作。 */ -.jd-delete-btn { - margin-left: auto; -} -/* 分类管理(2026-11-17 独立分类管理页并入本页的对话框入口):贴着分类筛选下拉。 */ -.jd-manage-btn { - margin-left: 6px; -} -/* 危险动作(批量删除):与全站 .btn-danger 同形——实心红渐变+白字。 - 旧版是白底红字描边,落在工具栏里看着像「未激活的次要按钮」,与打卡/分组等页不统一。 */ +/* 危险动作(删除商品):与全站 .btn-danger 同形——实心红渐变+白字。 */ .btn-danger { background: linear-gradient(135deg, #c06d77, #b35f6a); border-color: #b35f6a; @@ -151,16 +162,15 @@ h3 { .btn-danger:hover:not(:disabled) { background: linear-gradient(135deg, #cb7c84, #b96570); } -/* 非超管只读提示(2026-11-16 写权限收窄):动作条里的一句话说明,不冒充可点按钮。 - (汇总「共 X 条京东商品」2026-11-17 用户口径删除,.jd-summary 样式随之摘除。) */ +/* 非超管只读提示(2026-11-16 写权限收窄):工具栏下方的一句话说明,不冒充可点按钮。 */ .jd-readonly-tip { + display: block; color: #8293a5; font-size: 12.5px; - white-space: nowrap; + margin-bottom: 12px; } -/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片(2026-11-16 用户口径 - 「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 el-select 同高同壳(42px/9px 圆角), - "一组锁定"和"多组下拉"两种形态占位一致;组名超宽省略号收口,不把筛选行撑破。 */ +/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片, + 与同排 el-select 同高同壳(42px/9px 圆角),"一组锁定"和"多组下拉"两种形态占位一致。 */ .jd-group-locked { display: flex; align-items: center; @@ -175,193 +185,29 @@ h3 { overflow: hidden; text-overflow: ellipsis; } -.table-scroll { - width: 100%; - min-width: 0; - overflow-x: auto; - border: 1px solid #dbe5ee; - border-radius: 10px; - background: #ffffff; +/* 卡片网格(v1.6):自适应列数的商城款式;窄屏最小 170px 保住编码行不折断。 */ +.jd-card-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); + gap: 14px; + margin-bottom: 16px; } -.table-scroll table { - width: 100%; - border-collapse: collapse; - table-layout: fixed; -} -/* 列宽收口(2026-11-16 用户口径「列表间距有点大」):1500px 的 min-width 让宽屏下 - 唯一的弹性列(商品信息)独吞剩余宽度,标题右侧留出近 800px 空白,价格/库存被推到最右。 - 商品信息改固定 520px 后各列按比例分摊余量,min-width 降到 1180px 即可无横向滚动。 */ -.jd-table-scroll > table { - min-width: 1180px; -} -/* 操作列(编辑/删除):双小按钮需 138px(ops-cell-must-wrap 实测口径:两字按钮 53×2+24 padding)。 - overflow 显式放开:td 全局是 overflow:hidden(611 行),压线时第二颗(删除)会被裁成 - 「编辑+…」的形状——2026-11-16 用户报「删除没了」的真因,列宽 120px < 实测 138px。 */ -.jd-ops-cell { - white-space: nowrap; - text-overflow: clip; - overflow: visible; -} -.btn-sm { - min-height: 28px; - padding: 3px 10px; - font-size: 12.5px; - margin-right: 6px; -} -.btn-sm:last-child { - margin-right: 0; -} -.table-scroll th, -.table-scroll td { - /* 单元格左右内距 12→10px(同上「间距有点大」):列与列之间少 4px,行内更紧凑。 */ - padding: 10px 10px; - text-align: left; - font-size: 13.5px; - line-height: 1.5; - border-bottom: 1px solid #e0e8ef; - vertical-align: middle; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -/* 首列勾选格:checkbox 的 UA 默认 margin(3px 3px 3px 4px)使其 margin-box 溢出 - 42px 格的内容盒(42−24 padding=18px),配合上面的 overflow:hidden,Chromium 在 - 首次渲染时会把被裁的 checkbox 碎片留在裁剪边缘,看起来像格子右边多出 ".."。 - margin 归零后 margin-box 收进内容盒,首渲染即干净(playwright 三次冷加载已验)。 */ -.table-scroll th:first-child input, -.table-scroll td:first-child input { - margin: 0; -} -.table-scroll th { - background: #edf4fa; - color: #4e6479; - border-bottom-color: #d5e1eb; - font-size: 12.5px; - font-weight: 600; - letter-spacing: 0.4px; -} -.table-scroll tbody tr:hover td { - background: #f1f7fb; -} -.table-scroll tbody tr:last-child td { - border-bottom: 0; -} -/* 点行开详情抽屉:行级 hover 已有底色反馈,光标再点一下提示可点。 */ -.jd-row { - cursor: pointer; -} -.jd-thumb { - display: block; - width: 48px; - height: 48px; - object-fit: cover; - border: 1px solid #d8e3ee; - border-radius: 6px; - background: #f2f7fb; -} -/* 商品信息列=京麦同款合并布局:td 的全局 nowrap/ellipsis 与多行内容冲突,本列放开换行, - 截断交给内部各行(标题两行 line-clamp、编码/货号单行 ellipsis)。 */ -.jd-info-cell { - white-space: normal; - text-overflow: clip; -} -.jd-info-wrap { - display: flex; - align-items: flex-start; - gap: 10px; - min-width: 0; -} -.jd-info-figure { - display: flex; - flex-direction: column; - align-items: center; - gap: 3px; - flex-shrink: 0; -} -.jd-thumb-empty { - display: flex; - align-items: center; - justify-content: center; - color: #8293a5; - font-size: 12px; -} -.jd-health { - color: #2e9e6b; - font-size: 11px; - line-height: 1.2; - white-space: nowrap; -} -.jd-info-body { - min-width: 0; - display: flex; - flex-direction: column; - gap: 3px; -} -.jd-info-title { - color: #24384d; - font-size: 13.5px; - font-weight: 500; - line-height: 1.45; - display: -webkit-box; - -webkit-line-clamp: 2; - -webkit-box-orient: vertical; - overflow: hidden; - word-break: break-all; -} -.jd-info-meta { - display: flex; - align-items: center; - gap: 4px; - color: #7b8a99; - font-size: 12px; - line-height: 1.4; - white-space: nowrap; - overflow: hidden; -} -.jd-info-code { - font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace; - color: #4e6479; - overflow: hidden; - text-overflow: ellipsis; -} -.jd-copy-btn { - flex-shrink: 0; - border: 0; - background: transparent; - color: #8aa5bf; - font-size: 12px; - cursor: pointer; - padding: 0 2px; - line-height: 1; -} -.jd-copy-btn:hover { - color: #3b82c4; -} -.jd-info-tags { - display: flex; - gap: 6px; - margin-top: 2px; -} -/* 品牌·类目行(京麦列表同款深色文字):信息 meta 是灰色,这行按京麦用主文字色。 */ -.jd-brand-cat { - color: #3d5368; - font-weight: 550; -} -.jd-tag { - display: inline-flex; - align-items: center; - height: 18px; - padding: 0 6px; - border: 1px solid #cfe3f5; - border-radius: 3px; - background: #eef5fc; - color: #3b82c4; - font-size: 11.5px; - white-space: nowrap; -} -.empty-tip { +.jd-empty-tip { + grid-column: 1 / -1; padding: 44px 24px; text-align: center; color: #8293a5; font-size: 13.5px; + border: 1px dashed #dbe5ee; + border-radius: 10px; + background: #ffffff; +} +/* 窄屏:侧栏收回顶部整行(树/分类平铺横向铺开高度可控),面板落在下面。 */ +@media (max-width: 980px) { + .jd-database-view { + flex-wrap: wrap; + } + .jd-database-view > :first-child { + width: 100%; + } } diff --git a/admin-frontend-vue/tests/jd-category-cascader-position.test.ts b/admin-frontend-vue/tests/jd-category-cascader-position.test.ts deleted file mode 100644 index 67cbfe52e..000000000 --- a/admin-frontend-vue/tests/jd-category-cascader-position.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { test } from 'node:test' -import assert from 'node:assert/strict' -import { clampPanelLeftX } from '../src/pages/jd/jd-category-cascader-position.ts' - -/** 类目面板水平钳制(2026-11-16 客户截图「超出视窗了」回归判据):面板锚 left:0 最宽 - * 4 栏 ×200px,触发框落在筛选行中部偏右时面板伸出视窗右缘。判据形状统一=「右缘装 - * 不下必须左移、左移过头贴左缘、装得下不动」三种写法一格定红;把组件改回无条件锚左 - * 即红(JdCategoryCascader.vue 的 reposition 必须经本函数算偏移)。 */ - -test('视口装得下=不偏移(默认锚左)', () => { - // 宽视口:触发框在 x=300,4 栏 800px,右缘 1100 < 1920-8。 - assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1920 }), 0) - // 恰好贴齐:右缘正好压在 viewport-margin 上=零偏移(≤0 分支)。 - assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1108 }), 0) -}) - -test('右缘越界=整体左移到右缘贴齐(客户截图形状:末栏被窗缘裁掉)', () => { - // 截图形状:触发框 x=250、3 栏 600px、窗宽 830 ⇒ 右缘 850 越界 28px ⇒ 左移 28。 - assert.equal(clampPanelLeftX({ hostLeft: 250, panelWidth: 600, viewportWidth: 830 }), -28) - // 宽视口下钻到 4 栈仍越界(触发框靠右):1920 窗、触发框 x=1200、800px 面板。 - assert.equal(clampPanelLeftX({ hostLeft: 1200, panelWidth: 800, viewportWidth: 1920 }), -88) -}) - -test('越界过头不得把面板推出左缘=钳在 margin', () => { - // 窄窗:触发框 x=100、面板 800、窗宽 830 ⇒ 直移要 -78,但那样左缘到 22>8 可行; - // 极端:触发框 x=4、面板 800、窗宽 500 ⇒ 直移 -312 ⇒ 左缘 -308 越左,钳到 margin=8。 - assert.equal(clampPanelLeftX({ hostLeft: 4, panelWidth: 800, viewportWidth: 500, margin: 8 }), 4) - // 钳制后面板左缘=margin:偏移=margin-hostLeft。 - assert.equal(clampPanelLeftX({ hostLeft: 2, panelWidth: 600, viewportWidth: 400, margin: 8 }), 6) -}) - -test('窄窗越界:直移后左缘仍够留白就正常左移;不够则钳在 margin(物理极限,不假装能塞下)', () => { - // 窗宽 400、margin 8:面板 380 ⇒ 直移 -138 后左缘 12 ≥ 8 可行; - // 面板 390 ⇒ 直移后左缘 2 < 8 ⇒ 钳到左缘 8(偏移 -142),右侧溢出是物理极限。 - assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 380, viewportWidth: 400, margin: 8 }), -138) - assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 390, viewportWidth: 400, margin: 8 }), -142) -}) diff --git a/admin-frontend-vue/tests/mount/jd-category-cascader.mount.test.ts b/admin-frontend-vue/tests/mount/jd-category-cascader.mount.test.ts deleted file mode 100644 index 5c814b82f..000000000 --- a/admin-frontend-vue/tests/mount/jd-category-cascader.mount.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 京东类目级联面板(JdCategoryCascader)圆点选中态的挂载契约。 - * - * 2026-11-19 用户口径「怎么就最后一个才实心圆点阿」⇒ 圆点填芯改成**整条选中链**: - * 选中末级时,路径上的祖先行(母婴/童装/家居服)圆点一并亮蓝芯;非路径行(兄弟、 - * 叔叔档)保持空心。把填芯改回「仅全路径等值」即红(祖先变空心),把兄弟也填上 - * 即红(非路径断言变绿不了)。搜索态扁平列表同一判据(前缀行也填芯)。 - * - * 跑法:`npx vitest run tests/mount/jd-category-cascader.mount.test.ts` - */ -import { describe, expect, it } from 'vitest' -import { mount, type VueWrapper } from '@vue/test-utils' - -import JdCategoryCascader from '@/pages/jd/JdCategoryCascader.vue' - -/** 真树路径(jd-category-tree.ts,京麦授权类目):母婴 > 童装 > 家居服 > 家居服套装。 */ -const LEAF_PATH = ['母婴', '童装', '家居服', '家居服套装'] - -type Wrapper = VueWrapper - -function mountCascader(props: { modelValue: string; selectedPath: string[] }): Wrapper { - return mount(JdCategoryCascader, { props: { ...props, options: [] } }) -} - -/** 按 .cat-name 精确文本找行,返回其圆点是否填芯;行不存在返回 null。 */ -function dotOn(wrapper: Wrapper, name: string): boolean | null { - const row = wrapper.findAll('.cat-row').find((item) => item.find('.cat-name').text() === name) - if (!row) return null - return row.find('.cat-dot').classes().includes('on') -} - -async function openPanel(wrapper: Wrapper): Promise { - await wrapper.find('.cat-trigger').trigger('click') -} - -describe('下钻态:选中末级 ⇒ 整条路径填芯', () => { - it('路径各级圆点全亮,兄弟/叔叔行空心', async () => { - const wrapper = mountCascader({ modelValue: '家居服套装', selectedPath: LEAF_PATH }) - // 重开面板自动按 selectedPath 铺栏(toggle 既有行为),路径四级同屏可见。 - await openPanel(wrapper) - for (const name of LEAF_PATH) { - expect(dotOn(wrapper, name), `路径行 ${name} 应填芯`).toBe(true) - } - // 非路径行:一级栏的兄弟(服饰内衣/运动户外)、童装栏的兄弟(礼服/演出服)、 - // 家居服栏的兄弟(家居服上装)都不得亮;清选行的「全部类目」在已选时也不亮。 - for (const name of ['服饰内衣', '运动户外', '礼服/演出服', '家居服上装', '全部类目']) { - expect(dotOn(wrapper, name), `非路径行 ${name} 应保持空心`).toBe(false) - } - }) - - it('选中父级 ⇒ 该级与祖先填芯,其子级空心', async () => { - const wrapper = mountCascader({ modelValue: '家居服', selectedPath: ['母婴', '童装', '家居服'] }) - await openPanel(wrapper) - for (const name of ['母婴', '童装', '家居服']) { - expect(dotOn(wrapper, name), `路径行 ${name} 应填芯`).toBe(true) - } - // activePath 只铺到童装,家居服套装不在屏上——栏算到选中级即止。 - expect(dotOn(wrapper, '家居服套装')).toBeNull() - expect(dotOn(wrapper, '儿童汉服/旗袍/唐装')).toBe(false) - }) - - it('未选(全部类目)⇒ 只有清选行填芯', async () => { - const wrapper = mountCascader({ modelValue: '', selectedPath: [] }) - await openPanel(wrapper) - expect(dotOn(wrapper, '全部类目')).toBe(true) - expect(dotOn(wrapper, '母婴')).toBe(false) - }) -}) - -describe('搜索态:扁平结果同一判据', () => { - it('关键词命中时,选中链(前缀行+末级行)填芯,其余空心', async () => { - const wrapper = mountCascader({ modelValue: '家居服套装', selectedPath: LEAF_PATH }) - await openPanel(wrapper) - await wrapper.find('input[placeholder="搜索类目"]').setValue('家居服') - // 家居服=路径前缀、家居服套装=全路径命中 ⇒ 都填芯。 - expect(dotOn(wrapper, '家居服')).toBe(true) - expect(dotOn(wrapper, '家居服套装')).toBe(true) - // 家居服上装=同关键词命中但不在选中链上;睡衣/家居服=服饰内衣支的同名近亲 ⇒ 空心。 - expect(dotOn(wrapper, '家居服上装')).toBe(false) - expect(dotOn(wrapper, '睡衣/家居服')).toBe(false) - }) -}) diff --git a/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts b/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts index 060cd6852..9d4312109 100644 --- a/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts +++ b/admin-frontend-vue/tests/mount/jd-database-page.mount.test.ts @@ -1,18 +1,15 @@ /** - * 京东数据库页(v1.4 Phase 5)的挂载契约。 + * 京东数据库页(v1.6 装配:侧栏+卡片网格+居中详情弹窗)的挂载契约。 * - * 形态:panel-box + 筛选行(商品编码/标题关键字/类目/分组/同步起止 date 对)+ - * 查询/重置 + 自绘明细表(点行开详情抽屉)+ OldPagination; - * 分组下拉 2026-11-16 用户口径「做成分组」上移进筛选行=带标签的表单控件(不再是工具栏裸下拉); - * 店铺分类弹窗 2026-11-17 用户口径下线:工具栏改「批量编辑分类」(勾选跨页累计+归入/移出); - * 同日第二刀「京东分类管理并到京东数据库分类编辑里」:V204 独立子菜单页下线 - * (jd-category-manager-page.mount.test.ts 随之删除),建/改名/删分类+搜索收进工具栏 - * 「分类管理」对话框(另见 jd-category-manage-dialog.mount.test.ts); - * 「清除勾选」按钮同日用户口径删除(勾选只在批量操作成功后自动清)。 + * 形态:左侧栏 JdCategorySidebar(商品目录=京麦授权类目树+计数徽标+树外兜底/ + * 店铺分类=当前分组分类平铺+新建+分类管理入口)+主面板(筛选行:编码/标题/分组/ + * 同步起止/归属三档 + 工具栏:全选本页/取消本页/归入分类/取消归属/删除商品(N) + + * 卡片网格 JdProductCard + OldPagination)+居中详情弹窗(编辑/删除入口收进弹窗顶部)。 + * 旧表格/类目级联面板/详情抽屉三件随 v1.6 Phase 5 退役(反向钉在本文件顶部用例)。 + * 批量归类对话框与分类管理对话框是 v1.6 之前的既有组件(另有专属 mount 契约文件), + * 本文件只钉页面接线(勾选累计/三参提交/打开路径/changed 重取)。 * 公司维度 2026-11-16 整页摘除(「删除掉公司 tab,参考品牌数据库」):页面不消费公司 tab - * store、列表/类目下拉不带 company_id(反向钉在 company-tab-wiring「公司维度不得回流」)。 - * 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留); - * 店铺筛选与店铺列同日客户口径「店铺不需要」下线(后端 shop_name 参数同窗撤,店铺仍收详情抽屉)。 + * store、列表不带 company_id(反向钉在 company-tab-wiring「公司维度不得回流」)。 * 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。 * * 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts` @@ -101,6 +98,20 @@ function singleGroupScope(editable = true) { } } +/** 类目计数夹具:与侧栏组件 mount 测试同源(树内连衣裙支+树外历史名), + * 树内路径以 jd-category-tree 真树为准:连衣裙=服饰内衣/女装/连衣裙、 + * 艺考形体服=运动户外/舞蹈体操鞋服/装备/艺考形体服。 */ +const CATEGORY_OPTIONS = [ + { name: '连衣裙', productCount: 7 }, + { name: '艺考形体服', productCount: 5 }, + { name: '已下架历史类目', productCount: 12 }, +] + +const GROUPS = [ + { id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3 }, + { id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 }, +] + beforeEach(() => { vi.clearAllMocks() pinia = createPinia() @@ -121,11 +132,40 @@ async function mountWith(payload: unknown): Promise> { return wrapper } -// ---------------- el-select 交互助手(2026-11-17 两颗下拉换 el-select,与亚马逊面统一) ---------------- +// ---------------- 侧栏助手(双 Tab 体 v-show 共存于 DOM,按文案圈定行) ---------------- + +/** 切到指定侧栏 Tab(商品目录/店铺分类)。 */ +async function pickSideTab(wrapper: VueWrapper, name: string): Promise { + const tab = wrapper.findAll('.jd-sidebar-tab').find((t) => t.text() === name) + expect(tab, `应存在「${name}」侧栏 Tab`).toBeTruthy() + await tab!.trigger('click') + await flushPromises() +} + +/** 在指定 Tab 体(.jd-side-catalog/.jd-side-custom)内按文案找侧栏行。 */ +function sideRowBy(scope: VueWrapper, text: string) { + const row = scope.findAll('.jd-side-row').find((node) => node.text().includes(text)) + expect(row, `侧栏应存在文案含「${text}」的行`).toBeTruthy() + return row! +} + +const sideCustom = (wrapper: VueWrapper) => wrapper.get('.jd-side-custom') + +/** 卡片勾选框(label.jd-card-check 内 input,aria-label=勾选商品)。 */ +const cardBoxes = (wrapper: VueWrapper) => wrapper.findAll('.jd-card input[type="checkbox"]') + +/** 工具栏按钮按文案找(全选本页/取消本页/归入分类/取消归属)。 */ +function toolbarBtn(wrapper: VueWrapper, text: string) { + const btn = wrapper.findAll('.jd-toolbar button').find((b) => b.text() === text) + expect(btn, `工具栏应存在「${text}」按钮`).toBeTruthy() + return btn! +} + +// ---------------- el-select 交互助手(归属三档/分组下拉仍是 el-select,与亚马逊面统一) ---------------- // aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;选项弹层 teleport 到 body, // 但 ElOption/ElSelect 组件仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。 -/** 按 aria-label 找对应的 ElSelect 组件实例(页面有两颗下拉,靠内层 input 的 aria-label 区分)。 */ +/** 按 aria-label 找对应的 ElSelect 组件实例(靠内层 input 的 aria-label 区分)。 */ function selectByLabel(wrapper: VueWrapper, label: string) { const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists()) expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy() @@ -153,200 +193,202 @@ async function pickSelectOption(wrapper: VueWrapper, label: string, opt await flushPromises() } -/** 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」): - * 勾选跨页累计记忆(翻页/重取不清)→ 对话框选目标分类归入或移出 → 按 (ids, groupId, - * ownerGroupId) 提交;成功后清勾选并重取。旧弹窗的「勾选翻页即清」口径同日废止。 */ -describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代入口)', () => { - it('勾选跨页记忆:第 1 页勾 1 行翻到第 2 页再勾 1 行,删除按累计 2 行提交;「清除勾选」按钮已删(2026-11-17 用户口径)', async () => { - jdApi.fetchJdProductList - .mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 40, page: 1, pageSize: 20 })) - .mockImplementation(() => Promise.resolve({ items: [item(2)], total: 40, page: 2, pageSize: 20 })) - const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } }) - await flushPromises() - await flushPromises() - const deleteBtn = () => wrapper.get('.jd-delete-btn') +/** 详情弹窗取数 mock(已由 parseJdProductDetail 归一的形状)。 */ +function detailPayload(id = 1) { + return { + item: item(id), + attrGroups: [{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] }], + images: [ + { id: 1, imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main-1.jpg', byteSize: null, width: 800, height: 800 }, + { id: 2, imageType: 'DETAIL', attrName: '', sortNo: 2, url: 'https://img.example/detail.jpg', byteSize: null, width: null, height: null }, + ], + skus: [ + { skuId: '10238877506570', skuName: '花屿巷… 上衣 S', skuSeq: '1', price: 162, stock: 200, sortNo: 0, + saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }] }, + ], + attrJsonRaw: '', + } +} - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - expect(deleteBtn().text()).toContain('批量删除(1)') - - // 翻页:勾选不清(2026-11-17 口径「支持勾选翻页也要记住」)。 - await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') - await flushPromises() - expect(deleteBtn().text()).toContain('批量删除(1)', '翻页后第 1 页的勾选仍在累计集里') - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - expect(deleteBtn().text()).toContain('批量删除(2)', '第 2 页再勾 1 行,累计 2 行') - expect(wrapper.findAll('button').some((b) => b.text() === '清除勾选')).toBe(false, - '「清除勾选」按钮 2026-11-17 用户口径删除(显式反悔口没了,勾选只在批量操作成功后自动清)') - - // 累计勾选直达删除:跨页的行一起删(确认弹窗点名总数)。 - jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 2, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 }) - await deleteBtn().trigger('click') - await flushPromises() - await flushPromises() - expect(confirmMock.mock.calls.at(-1)![0].message).toContain('确定批量删除选中的 2 个商品吗', '确认文案点名累计总数') - // 跨页累计的 id 一起提交。 - expect(jdApi.deleteJdProducts).toHaveBeenLastCalledWith([1, 2]) - expect(deleteBtn().text()).toContain('批量删除(0)', '批量删除成功后自动清勾选') - wrapper.unmount() +describe('京东数据库页(v1.6 装配:侧栏+卡片网格)', () => { + it('挂载后按首屏分页参数取列表(pageSize 默认 50、档位 20/50/100、不带公司维度),卡片数=本页条数', async () => { + const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 50 }) + expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1) + const firstCall = jdApi.fetchJdProductList.mock.calls[0][0] + expect(firstCall.page).toBe(1) + expect(firstCall.pageSize).toBe(50, 'v1.6 新契约:每页默认 50(Phase 1 常量)') + // 公司维度 2026-11-16 整页摘除:入参层不再有 companyId 键(单参 toHaveProperty 才是「键不存在」的真判据)。 + expect(firstCall).not.toHaveProperty('companyId') + expect(wrapper.findAll('.jd-card')).toHaveLength(3) + // 档位 20/50/100 收敛在 filter 层常量:分页条下拉按它出选项。 + expect(wrapper.findComponent(OldPagination).props('sizes')).toEqual([20, 50, 100]) }) - it('批量归入:未勾选时入口置灰,勾选后打开对话框选目标分类,按 (ids, groupId, ownerGroupId) 提交并清勾选重取', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([ - { id: 7, name: '甲组', sortOrder: 0, productCount: 3 }, - { id: 8, name: '乙组', sortOrder: 1, productCount: 1 }, - ]) - jdApi.batchAssignJdProductGroup.mockResolvedValue(2) - const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 }) - const editBtn = () => wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')! - - expect(editBtn().attributes('disabled')).toBeDefined('勾选 0 时置灰(与批量删除同款常显口径)') - const boxes = wrapper.findAll('tbody input[type="checkbox"]') - await boxes[0].setValue(true) - await boxes[1].setValue(true) - expect(editBtn().attributes('disabled')).toBeUndefined() - const callsBefore = jdApi.fetchJdProductList.mock.calls.length - await editBtn().trigger('click') - await flushPromises() - const modal = wrapper.get('.batch-modal') - expect(modal.text()).toContain('批量编辑分类') - expect(modal.text()).toContain('已勾选 2 个商品(翻页累计)', '对话框点名累计勾选数') - expect(modal.text()).toContain('甲组', '标题/上下文带当前分组名') - expect(modal.findAll('.option-row')).toHaveLength(3, '两个分类+一个移出选项') - - await modal.findAll('.option-row')[0].trigger('click') - const confirmBtn = modal.findAll('button').find((b) => b.text() === '归入「甲组」') - expect(confirmBtn, '确认按钮文案带目标分类名').toBeTruthy() - await confirmBtn!.trigger('click') - await flushPromises() - await flushPromises() - expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7, GROUP_A) - expect(document.body.textContent).toContain('已把 2 个商品归入「甲组」') - expect(wrapper.find('.batch-modal').exists()).toBe(false, '成功后对话框自动关闭') - expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore, '成功后重取列表(groupName 变了)') - expect(wrapper.get('.jd-delete-btn').text()).toContain('批量删除(0)', '成功后清勾选') - wrapper.unmount() - }) - - it('移出分类:选「移出分类」确认 → groupId 传 null(后端只解挂本组归属行)', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }]) - jdApi.batchAssignJdProductGroup.mockResolvedValue(1) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - await wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')!.trigger('click') - await flushPromises() - const modal = wrapper.get('.batch-modal') - await modal.find('.option-detach').trigger('click') - await modal.findAll('button').find((b) => b.text() === '移出分类')!.trigger('click') - await flushPromises() - await flushPromises() - expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A) - expect(document.body.textContent).toContain('已把 1 个商品移出分类') - wrapper.unmount() - }) - - it('本组暂无分类:对话框只留提示不给提交(移出对未分类行是无谓操作),引导去工具栏「分类管理」新建', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([]) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - await wrapper.findAll('button').find((b) => b.text() === '批量编辑分类')!.trigger('click') - await flushPromises() - const modal = wrapper.get('.batch-modal') - expect(modal.text()).toContain('本组暂无分类') - expect(modal.text()).toContain('分类管理', '空态把维护入口指向工具栏「分类管理」(独立页 2026-11-17 并入本页)') - expect(modal.findAll('button').some((b) => b.text() === '移出分类' && b.attributes('disabled') === undefined)).toBe(false, - '无分类时移出不可提交') - expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled() - wrapper.unmount() - }) - - it('店铺分类弹窗已下线(反向钉):入口按钮与 .group-modal 都不再存在,分类筛选照常', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }]) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.findAll('button').some((b) => b.text() === '店铺分类')).toBe(false, '「店铺分类」入口已删') + it('旧装配反钉:自绘表格/类目级联面板/详情抽屉三件已退役,批量入口改「归入分类」', async () => { + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(wrapper.find('table').exists()).toBe(false, '自绘明细表已退役(卡片网格替代)') + expect(wrapper.find('.cat-trigger').exists()).toBe(false, '类目级联面板已退役(侧栏商品目录替代)') + expect(wrapper.find('.drawer-mask').exists()).toBe(false, '详情抽屉已退役(居中弹窗替代)') + expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, + '工具栏批量入口改名「归入分类」(v1.6 蓝图措辞)') + // 侧栏双 Tab 的「店铺分类」是 Tab 名不是入口按钮:独立入口的反钉圈定在筛选行+工具栏。 + const actionButtons = [...wrapper.get('.jd-filter-row').findAll('button'), ...wrapper.findAll('.jd-toolbar button')] + expect(actionButtons.some((b) => b.text() === '店铺分类')).toBe(false, + '「店铺分类」独立入口不存在(侧栏店铺分类 Tab 替代)') expect(wrapper.find('.group-modal').exists()).toBe(false) - expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选下拉是读面,保留') + // 汇总条(共 X 条京东商品)2026-11-17 用户口径删除:不再渲染(反钉延续)。 + expect(wrapper.find('.jd-summary').exists()).toBe(false) + wrapper.unmount() + }) + + it('卡片字段映射(商城款式):主图/店铺徽标/标题/价格区间/编码/采集日期/信息分', async () => { + const wrapper = await mountWith({ items: [item(1), item(2, { mainImageUrl: '', healthScore: null })], total: 2, page: 1, pageSize: 50 }) + const cards = wrapper.findAll('.jd-card') + expect(cards).toHaveLength(2) + const first = cards[0] + expect(first.find('img.jd-card-thumb').exists()).toBe(true, '有自有桶 URL 的卡片出真图') + expect(first.get('.jd-card-shop').text()).toBe('旗舰自营店', '店铺徽标浮在图底') + expect(first.get('.jd-card-title').text()).toContain('304不锈钢保温杯大容量便携') + expect(first.get('.jd-card-price').text()).toBe('12.9 ~ 15.9', '价格走 jdPriceRange(number 形状不显示 -)') + expect(first.get('.jd-card-code').text()).toContain('JD-1001') + expect(first.get('.jd-card-date').text()).toContain('采集:') + expect(first.get('.jd-card-health').text()).toContain('信息分 81') + const second = cards[1] + expect(second.find('.jd-card-thumb-empty').text()).toBe('无图', '无图占位是 span,不冒充 img') + expect(second.find('.jd-card-health').exists()).toBe(false, 'healthScore 为空不出信息分徽标') + expect(second.findAll('img.jd-card-thumb')).toHaveLength(0) wrapper.unmount() }) }) -/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」+同日定默认卡未分类; - * 2026-11-18 用户口径「加个全部选项」恢复全量档):工具栏「筛选分类状态」下拉三档 - * (全部/已分类/未分类),出厂默认与「重置」仍卡未分类(11-17 口径不动); - * 「全部」(value='')选中即查当前分组全部商品——序列化不下发 classified 参数; - * 页面发的是筛选态字符串(''/classified/ungrouped),布尔换算收在 jd-product-filter - * 单一出口(纯测试钉形状)。 */ -describe('分类状态快筛(三档,默认卡未分类)', () => { - it('下拉三档且首屏就卡「未分类」(classified="ungrouped" 随首取下发)', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部', '已分类', '未分类']) - expect(jdApi.fetchJdProductList.mock.calls[0][0].classified).toBe('ungrouped', - '首屏默认档=未分类——用户口径「默认卡在未分类上就行」') - wrapper.unmount() - }) +describe('侧栏商品目录(类目筛选迁移自级联面板)', () => { + it('授权类目树逐级下钻:一级行点行=选中即查(path 下发),末级点行单名/路径口径与级联面板等价', async () => { + jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS) + const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) + expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith() - it('选「全部」下发不带 classified 键(查当前分组全部商品);选「已分类」下发 classified 态', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await pickSelectOption(wrapper, '筛选分类状态', '全部') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).not.toHaveProperty('classified', - 'value=\'\' 序列化不下发 classified 参数=后端跳过谓词查全部') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页') + const catalog = wrapper.get('.jd-side-catalog') + // 一级默认展开:二级「女装」首屏可见(侧栏与级联面板的关键差异——非末级也能直接选)。 + const women = sideRowBy(catalog, '女装') + expect(women.classes()).toContain('depth-1') - await pickSelectOption(wrapper, '筛选分类状态', '已分类') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified') - wrapper.unmount() - }) - - it('「重置」不放开筛选,而是回默认未分类档', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await pickSelectOption(wrapper, '筛选分类状态', '已分类') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified') - - await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click') + // 点二级=选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」的侧栏形状)。 + await women.trigger('click') await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped', - '重置回出厂默认档(未分类),「全部」只是可选项不接默认') + let last = jdApi.fetchJdProductList.mock.calls.at(-1)![0] + expect(last).toMatchObject({ category: '女装', categoryPath: ['服饰内衣', '女装'], page: 1 }, + '一级/二级点行=带完整路径下发(序列化按子树展开 IN)') + + // 展开到末级再点末级:艺考形体服(运动户外支)。 + await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click') + await flushPromises() + await sideRowBy(catalog, '艺考形体服').trigger('click') + await flushPromises() + last = jdApi.fetchJdProductList.mock.calls.at(-1)![0] + expect(last).toMatchObject({ + category: '艺考形体服', + categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'], + page: 1, + }, '末级点行带完整名称路径(同名跨支靠路径区分)') + wrapper.unmount() + }) + + it('树外兜底组(已落库但京麦树里没有的历史名):点行单名等值下发;「全部商品」行清选重查', async () => { + jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS) + const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) + + const catalog = wrapper.get('.jd-side-catalog') + // 树外兜底段:树外历史行从兜底组搜出可选(path 空数组=页面按无路径序列化单名等值)。 + const extra = catalog.get('.jd-side-extra') + expect(extra.text()).toContain('树外兜底') + await extra.findAll('.jd-side-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目', categoryPath: [] }) + + // 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。 + const callsBefore = jdApi.fetchJdProductList.mock.calls.length + await catalog.get('.jd-side-all').trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].categoryPath).toEqual([], + '清选后路径回空数组(api 序列化层对空 category 不下发参数)') wrapper.unmount() }) }) -/** 分类管理入口(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」): - * V204 独立子菜单页下线,工具栏「分类管理」打开 JdCategoryManageDialog(搜索+新建+ - * 改名+删除);入口对所有人渲染(同组普通号只读可看),写控件由对话框按 editable 分档; - * 对话框 CRUD 成功 emit changed ⇒ 父页刷分类筛选下拉。 */ -describe('分类管理入口(V204 独立页并入京东数据库页)', () => { - it('工具栏「分类管理」入口常显(勾选 0 也可用),点开渲染对话框且按当前分组取分类', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '裙装', sortOrder: 0, productCount: 3 }]) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - const manageBtn = () => wrapper.findAll('button').find((b) => b.text() === '分类管理') - expect(manageBtn(), '入口常显(不等勾选)').toBeTruthy() - expect(wrapper.find('.manage-modal').exists()).toBe(false, '未点开时不渲染对话框') +describe('侧栏店铺分类(分类筛选迁移自下拉)', () => { + it('点分类行 → groupId 下发回第一页;再点已选行=清选(与旧「全部分类」行同语义)', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + const custom = sideCustom(wrapper) + expect(sideRowBy(custom, '裙装').text()).toContain('3', '分类行带商品数徽标') + + await sideRowBy(custom, '裙装').trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 }) + expect(sideRowBy(custom, '裙装').classes()).toContain('selected', '选中态高亮') + + await sideRowBy(custom, '裙装').trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('', '再点已选=清选重查') + expect(sideRowBy(custom, '裙装').classes()).not.toContain('selected') + wrapper.unmount() + }) + + it('新建分类(可写档):createJdProductGroup 落当前分组并刷新侧栏分类', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + jdApi.createJdProductGroup.mockResolvedValue({ id: 9, name: '新分类', ownerGroupId: GROUP_A, sortOrder: 2, productCount: 0 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') const callsBefore = jdApi.fetchJdProductGroups.mock.calls.length - await manageBtn()!.trigger('click') + await sideCustom(wrapper).get('[aria-label="新分类名称"]').setValue('新分类') + await sideCustom(wrapper).findAll('button').find((b) => b.text() === '新建分类')!.trigger('click') + await flushPromises() + await flushPromises() + expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0, ownerGroupId: GROUP_A }) + expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(callsBefore, '成功后刷新侧栏分类') + expect(document.body.textContent).toContain('已创建分类「新分类」') + wrapper.unmount() + }) + + it('普通员工(editable=false)无新建分类行,但分类管理入口仍在(读面,写控件由对话框分档)', async () => { + useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' } + jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false)) + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + const custom = sideCustom(wrapper) + expect(custom.find('[aria-label="新分类名称"]').exists()).toBe(false, '不可写档没有新建行') + expect(custom.get('.jd-side-manage').exists()).toBe(true, '分类管理入口对所有人渲染(V203)') + + const callsBefore = jdApi.fetchJdProductGroups.mock.calls.length + await custom.get('.jd-side-manage').trigger('click') await flushPromises() const modal = wrapper.get('.manage-modal') expect(modal.text()).toContain('分类管理') - expect(modal.text()).not.toContain('甲组', '标题不带分组名后缀(ea9dca3f 用户口径「不要显示周丽娥」)') - expect(modal.get('.search-input').exists()).toBe(true, '搜索框是本对话框新能力') - expect(modal.text()).toContain('裙装') - expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(callsBefore, - '对话框打开时按当前分组自取列表') + expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(callsBefore, '对话框打开时按当前分组自取列表') wrapper.unmount() }) +}) - it('对话框内删分类成功(emit changed)后父页重取分类下拉(筛选选项与商品数徽标同步刷新)', async () => { +describe('分类管理入口(V204 独立页并入侧栏「分类管理」对话框)', () => { + it('对话框内删分类成功(emit changed)后父页重取分类(侧栏行与商品数徽标同步刷新)', async () => { // 取数按次序变形:页面首屏=裙装;对话框打开与 changed 后的重取=删后列表(只剩裤装)。 let groupFetchCount = 0 jdApi.fetchJdProductGroups.mockImplementation(() => { groupFetchCount += 1 return groupFetchCount === 1 - ? Promise.resolve([{ id: 7, name: '裙装', sortOrder: 0, productCount: 3 }]) - : Promise.resolve([{ id: 8, name: '裤装', sortOrder: 1, productCount: 1 }]) + ? Promise.resolve([{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3 }]) + : Promise.resolve([{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 }]) }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裙装', '首屏下拉含首取分类') + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + expect(sideRowBy(sideCustom(wrapper), '裙装').exists()).toBe(true) - await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click') + await sideCustom(wrapper).get('.jd-side-manage').trigger('click') await flushPromises() const modal = wrapper.get('.manage-modal') confirmMock.mockResolvedValue(true) @@ -355,19 +397,14 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () => await flushPromises() await flushPromises() expect(jdApi.deleteJdProductGroup, '删除按钮属于当前列表行').toHaveBeenCalledWith(8) - // changed → 父页 loadGroupOptions:下拉按新列表重取(最后一次调用拿到删后列表)。 - expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裤装', '下拉刷新出新一轮分类') - expect(optionLabels(wrapper, '筛选店铺分类')).not.toContain('裙装', '删掉的分类不再出现在筛选下拉') + // changed → 父页 loadGroupOptions:侧栏按新列表重取(最后一次调用拿到删后列表)。 + expect(sideRowBy(sideCustom(wrapper), '裤装').exists()).toBe(true, '侧栏刷新出新一轮分类') + expect(sideCustom(wrapper).findAll('.jd-side-row').some((node) => node.text().includes('裙装'))).toBe(false, + '删掉的分类不再出现在侧栏') wrapper.unmount() }) -}) -/** 平台超管空态直建分组(2026-11-17 用户口径「admin 权限最大」):京东侧还没有任何 - * 数据权限分组时,分类管理弹窗给平台超管开直建口子;建完 group-created ⇒ 父页整条 - * 作用域重取,当前分组翻到新组、分类下拉与弹窗列表随新组走——从「死路」到「接着建 - * 分类」一气呵成。scope.platformSuperAdmin 是这条链的唯一开关,非超管维持空态文案。 */ -describe('平台超管空态直建分组(页面级链路)', () => { - it('超管 + 京东侧零分组:弹窗出直建表单,建组走 POST(jd 档) 且作用域重取翻到新组', async () => { + it('平台超管空态直建分组:弹窗出直建表单,建组走 POST(jd 档) 且作用域重取翻到新组', async () => { let scopeFetchCount = 0 jdApi.fetchJdCategoryScope.mockImplementation(() => { scopeFetchCount += 1 @@ -379,8 +416,9 @@ describe('平台超管空态直建分组(页面级链路)', () => { groups: [{ id: 21, name: '京东-团队', label: '京东-团队', editable: true }], }) }) - const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click') + const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + await sideCustom(wrapper).get('.jd-side-manage').trigger('click') await flushPromises() const modal = wrapper.get('.manage-modal') expect(modal.get('[aria-label="新分组名称"]').exists()).toBe(true, '超管空态不是死路文案') @@ -400,8 +438,9 @@ describe('平台超管空态直建分组(页面级链路)', () => { it('非超管 + 京东侧零分组:弹窗维持空态文案,无直建表单(口子不开给组长/公司超管)', async () => { jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click') + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + await sideCustom(wrapper).get('.jd-side-manage').trigger('click') await flushPromises() const modal = wrapper.get('.manage-modal') expect(modal.text()).toContain('你还不属于任何数据权限分组') @@ -411,143 +450,396 @@ describe('平台超管空态直建分组(页面级链路)', () => { }) }) -describe('京东数据库页(v1.4 Phase 5)', () => { - it('挂载后按首屏分页参数取列表(pageSize 默认 20、不带公司维度),行数=本页条数', async () => { - const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 20 }) - expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1) - const firstCall = jdApi.fetchJdProductList.mock.calls[0][0] - expect(firstCall.page).toBe(1) - expect(firstCall.pageSize).toBe(20) - // 公司维度 2026-11-16 整页摘除:入参层不再有 companyId 键(单参 toHaveProperty 才是「键不存在」的真判据)。 - expect(firstCall).not.toHaveProperty('companyId') - expect(wrapper.findAll('tbody tr')).toHaveLength(3) - // 汇总条(共 X 条京东商品)2026-11-17 用户口径删除:不再渲染(反钉)。 - expect(wrapper.find('.jd-summary').exists()).toBe(false, '汇总条已按 2026-11-17 用户口径删除') +describe('归属三档快筛(三档,默认卡未分类)', () => { + it('下拉三档且首屏就卡「未分类」(classified="ungrouped" 随首取下发)', async () => { + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部', '已分类', '未分类']) + expect(jdApi.fetchJdProductList.mock.calls[0][0].classified).toBe('ungrouped', + '首屏默认档=未分类——用户口径「默认卡在未分类上就行」') + wrapper.unmount() }) - it('行列字段与顺序(2026-11-15 用户口径;状态列+创建/修改两列 2026-11-16 客户口径「不需要采集/不要」下线仍收详情抽屉;操作置末「操作放最后一列」):勾选/分组/商品信息(图+标题+编码+货号+品牌·类目+SKU/信息分)/总库存/价格/同步/操作(7 列;店铺列 2026-11-15 下线)', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - const cells = wrapper.findAll('tbody tr')[0].findAll('td') - expect(cells).toHaveLength(7) - expect(cells[0].find('input[type="checkbox"]').exists()).toBe(true, '第 1 列是勾选框') - expect(cells[1].text()).toBe('甲组', '第 2 列=分组(admin 专属)') - // 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+品牌·类目行+SKU 标签。 - const info = cells[2] - expect(info.find('.jd-thumb').exists()).toBe(true, '商品信息列含主图') - expect(info.text()).toContain('304不锈钢保温杯') - expect(info.text()).toContain('JD-1001', '商品编码并入商品信息列') - expect(info.text()).toContain('ITEM-1', '货号并入商品信息列') - expect(info.text()).toContain('锅宝', '品牌并入商品信息列(京麦品牌·类目行)') - expect(info.text()).toContain('家居 > 厨具 > 保温杯', '类目随品牌·类目行上列表(京麦同款)') - expect(info.text()).toContain('12个SKU') - expect(info.text()).toContain('信息分 81') - expect(cells[3].text()).toBe('500', '第 3 数据列=总库存(京麦第 2 列)') - expect(cells[4].text()).toBe('12.9 ~ 15.9', '第 4 数据列=价格(京麦第 3 列;number 形状价格不许显示 -)') - expect(cells[5].text()).not.toBe('-', '第 5 数据列=同步时间(创建/修改两列 2026-11-16 下线,时间列只剩同步)') - expect(cells[6].text()).toContain('编辑', '第 6 数据列=操作(编辑/删除;2026-11-16「操作放最后一列」置末)') - expect(cells[6].text()).toContain('删除', '操作列含删除按钮') - // 表头字段名与顺序与京麦一致;品牌/类目不再是独立列(收进商品信息);店铺/状态/创建/修改列已下线。 - const headerText = wrapper.find('thead').text() - for (const gone of ['品牌', '类目', '店铺', '上架时间 / 商品状态', '创建时间', '修改时间']) { - expect(headerText).not.toContain(gone, `${gone}不再是独立列(品牌/类目收进商品信息;店铺 2026-11-15 下线;状态列+创建/修改 2026-11-16 下线)`) - } - for (const head of ['商品信息', '总库存', '价格', '同步时间', '操作']) { - expect(headerText).toContain(head, `表头必须有「${head}」(京麦字段名)`) - } - expect(wrapper.find('.jd-thumb').exists()).toBe(true, '商品信息列渲染缩略图') + it('选「全部」下发不带 classified 键(查当前分组全部商品);选「已分类」下发 classified 态', async () => { + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSelectOption(wrapper, '筛选分类状态', '全部') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).not.toHaveProperty('classified', + 'value=\'\' 序列化不下发 classified 参数=后端跳过谓词查全部') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页') + + await pickSelectOption(wrapper, '筛选分类状态', '已分类') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified') + wrapper.unmount() }) - it('操作列删除按钮防冒泡且走确认弹窗:确认后调 deleteJdProducts,取消不动(2026-11-15 行级删除)', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - // beforeEach 默认 confirm=true;本例先翻回 false 验「取消不动」。 - confirmMock.mockResolvedValue(false) - const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[6] - await opsCell.findAll('button').find((b) => b.text() === '删除')!.trigger('click') + it('「重置」不放开筛选,而是回默认未分类档', async () => { + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSelectOption(wrapper, '筛选分类状态', '已分类') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified') + + await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click') await flushPromises() - // 防冒泡:点删除不得顺手打开详情抽屉(抽屉的可视判据=.drawer 出现)。 - expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉') + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped', + '重置回出厂默认档(未分类),「全部」只是可选项不接默认') + wrapper.unmount() + }) +}) + +describe('批量操作(勾选跨页累计+工具栏)', () => { + it('勾选跨页记忆:第 1 页勾 1 张卡片翻到第 2 页再勾 1 张,删除按累计 2 张提交;「清除勾选」按钮已删', async () => { + // total=80(50/页下两页):默认档从 20 改 50 后,翻页夹具的 total 必须跟着放大。 + jdApi.fetchJdProductList + .mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 80, page: 1, pageSize: 50 })) + .mockImplementation(() => Promise.resolve({ items: [item(2)], total: 80, page: 2, pageSize: 50 })) + const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } }) + await flushPromises() + await flushPromises() + const deleteBtn = () => wrapper.get('.jd-delete-btn') + + await cardBoxes(wrapper)[0].setValue(true) + expect(deleteBtn().text()).toContain('删除商品(1)') + + // 翻页:勾选不清(2026-11-17 口径「支持勾选翻页也要记住」)。 + await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') + await flushPromises() + expect(deleteBtn().text()).toContain('删除商品(1)', '翻页后第 1 页的勾选仍在累计集里') + await cardBoxes(wrapper)[0].setValue(true) + expect(deleteBtn().text()).toContain('删除商品(2)', '第 2 页再勾 1 张,累计 2 张') + expect(wrapper.findAll('button').some((b) => b.text() === '清除勾选')).toBe(false, + '「清除勾选」按钮 2026-11-17 用户口径删除(显式反悔口没了,勾选只在批量操作成功后自动清)') + + // 累计勾选直达删除:跨页的行一起删(确认弹窗点名总数)。 + jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 2, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 }) + await deleteBtn().trigger('click') + await flushPromises() + await flushPromises() + expect(confirmMock.mock.calls.at(-1)![0].message).toContain('确定批量删除选中的 2 个商品吗', '确认文案点名累计总数') + // 跨页累计的 id 一起提交。 + expect(jdApi.deleteJdProducts).toHaveBeenLastCalledWith([1, 2]) + expect(deleteBtn().text()).toContain('删除商品(0)', '批量删除成功后自动清勾选') + wrapper.unmount() + }) + + it('全选本页/取消本页:只动当前页行集(跨页累计集里其他页的勾选不动)', async () => { + jdApi.fetchJdProductList + .mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 80, page: 1, pageSize: 50 })) + .mockImplementation(() => Promise.resolve({ items: [item(2)], total: 80, page: 2, pageSize: 50 })) + const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } }) + await flushPromises() + await flushPromises() + const deleteBtn = () => wrapper.get('.jd-delete-btn') + + // 第 1 页先手动勾 1 张,再翻页「全选本页」:第 2 页整页进累计集,第 1 页的勾选保留。 + await cardBoxes(wrapper)[0].setValue(true) + await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') + await flushPromises() + await toolbarBtn(wrapper, '全选本页').trigger('click') + expect(deleteBtn().text()).toContain('删除商品(2)', '全选本页=第 2 页 1 张+第 1 页累计 1 张') + + await toolbarBtn(wrapper, '取消本页').trigger('click') + expect(deleteBtn().text()).toContain('删除商品(1)', '取消本页只清当前页,第 1 页的勾选保留') + wrapper.unmount() + }) + + it('归入分类:未勾选时入口置灰,勾选后打开对话框选目标分类,按 (ids, groupId, ownerGroupId) 三参提交并清勾选重取', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + jdApi.batchAssignJdProductGroup.mockResolvedValue(2) + const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 }) + const editBtn = () => toolbarBtn(wrapper, '归入分类') + + expect(editBtn().attributes('disabled')).toBeDefined('勾选 0 时置灰(常显口径)') + const boxes = cardBoxes(wrapper) + await boxes[0].setValue(true) + await boxes[1].setValue(true) + expect(editBtn().attributes('disabled')).toBeUndefined() + const callsBefore = jdApi.fetchJdProductList.mock.calls.length + await editBtn().trigger('click') + await flushPromises() + const modal = wrapper.get('.batch-modal') + expect(modal.text()).toContain('批量编辑分类') + expect(modal.text()).toContain('已勾选 2 个商品(翻页累计)', '对话框点名累计勾选数') + expect(modal.text()).toContain('甲组', '标题/上下文带当前分组名') + expect(modal.findAll('.option-row')).toHaveLength(3, '两个分类+一个移出选项') + + await modal.findAll('.option-row')[0].trigger('click') + const confirmBtn = modal.findAll('button').find((b) => b.text() === '归入「裙装」') + expect(confirmBtn, '确认按钮文案带目标分类名').toBeTruthy() + await confirmBtn!.trigger('click') + await flushPromises() + await flushPromises() + // 铁律 33 判据③:归类必须带第三个参数 ownerGroupId(归属表写入按当前分组落)。 + expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7, GROUP_A) + expect(document.body.textContent).toContain('已把 2 个商品归入「裙装」') + expect(wrapper.find('.batch-modal').exists()).toBe(false, '成功后对话框自动关闭') + expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore, '成功后重取列表') + expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(0)', '成功后清勾选') + wrapper.unmount() + }) + + it('工具栏「取消归属」=groupId null 三参直解挂(与对话框「移出分类」同端点同语义)', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + jdApi.batchAssignJdProductGroup.mockResolvedValue(1) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await cardBoxes(wrapper)[0].setValue(true) + await toolbarBtn(wrapper, '取消归属').trigger('click') + await flushPromises() + await flushPromises() + expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A) + expect(document.body.textContent).toContain('已把 1 个商品移出分类') + expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(0)', '成功后清勾选') + wrapper.unmount() + }) + + it('本组暂无分类:对话框只留提示不给提交(移出对未分类行是无谓操作),引导去侧栏「分类管理」新建', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue([]) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await cardBoxes(wrapper)[0].setValue(true) + await toolbarBtn(wrapper, '归入分类').trigger('click') + await flushPromises() + const modal = wrapper.get('.batch-modal') + expect(modal.text()).toContain('本组暂无分类') + expect(modal.text()).toContain('分类管理', '空态把维护入口指向侧栏「分类管理」') + expect(modal.findAll('button').some((b) => b.text() === '移出分类' && b.attributes('disabled') === undefined)).toBe(false, + '无分类时移出不可提交') + expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled() + wrapper.unmount() + }) + + it('删除二次确认点名桶清理;取消不发请求(防误删的第一道闸)', async () => { + jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 }) + const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 }) + + // 批量删除常显:未勾选时就在,只是置灰。 + expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) + expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined() + const boxes = cardBoxes(wrapper) + await boxes[0].setValue(true) + await boxes[1].setValue(true) + expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeUndefined('勾选后按钮可点') + await wrapper.find('.jd-delete-btn').trigger('click') + await flushPromises() + await flushPromises() + + expect(confirmMock).toHaveBeenCalledTimes(1) + const options = confirmMock.mock.calls[0][0] + expect(options.title).toBe('删除京东商品') + expect(options.message).toContain('确定批量删除选中的 2 个商品吗') + expect(options.message).toContain('jd-products 桶内图片文件一并删除', '确认弹窗必须点名「桶文件也会删」') + expect(options.danger).toBe(true) + + expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1) + expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2]) + expect(document.body.textContent).toContain('已删除 2 个商品') + expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈') + // 成功后重取列表并清勾选:常显按钮回到置灰。 + expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1) + expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined() + wrapper.unmount() + }) + + it('删除:确认弹窗点取消就不发请求', async () => { + confirmMock.mockResolvedValue(false) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await cardBoxes(wrapper)[0].setValue(true) + await wrapper.find('.jd-delete-btn').trigger('click') + await flushPromises() + + expect(confirmMock).toHaveBeenCalledTimes(1) + expect(jdApi.deleteJdProducts).not.toHaveBeenCalled() + wrapper.unmount() + }) + + it('删除失败把后端「本次未删除任何数据」文案弹出来(整批拒绝的语义必须到界面),失败后勾选保留', async () => { + jdApi.deleteJdProducts.mockRejectedValue(new Error('桶内对象删除失败,本次未删除任何数据(jd-products/5/a.jpg):oss 5xx')) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await cardBoxes(wrapper)[0].setValue(true) + await wrapper.find('.jd-delete-btn').trigger('click') + await flushPromises() + await flushPromises() + + expect(document.body.textContent).toContain('本次未删除任何数据') + expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) + expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(1)', '失败后勾选保留,用户可重试') + wrapper.unmount() + }) + + it('末页删空页码回退:第 2 页只剩 1 行删掉后回第 1 页重取(Phase 0 黄金测试 ⑤)', async () => { + // total=51 让分页条出「下一页」;第 1 页夹具从简(2 张卡片),语义落在「末页删空回退」上。 + jdApi.fetchJdProductList + .mockImplementationOnce(() => Promise.resolve({ items: [item(1), item(2)], total: 51, page: 1, pageSize: 50 })) + .mockImplementationOnce(() => Promise.resolve({ items: [item(21)], total: 51, page: 2, pageSize: 50 })) + .mockImplementation(() => Promise.resolve({ items: [], total: 50, page: 1, pageSize: 50 })) + const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } }) + await flushPromises() + await flushPromises() + await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(2, '先到第 2 页(该页只剩 1 张)') + + // 工具栏批量删除(全选本页 → 删除商品(1))替代旧行级删除按钮。 + await toolbarBtn(wrapper, '全选本页').trigger('click') + jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 }) + await wrapper.get('.jd-delete-btn').trigger('click') + await flushPromises() + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, pageSize: 50 }, + '末页删空后页码回退重取(停在空页会让用户误以为库空了)') + wrapper.unmount() + }) +}) + +describe('详情弹窗(抽屉退役后的详情入口)', () => { + it('点卡片打开居中弹窗:按 id 取详情,hero/属性分组/SKU 矩阵断言与旧抽屉逐字等价', async () => { + jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload())) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '初始不显示弹窗') + + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + + expect(wrapper.find('.jd-modal-mask').exists()).toBe(true) + expect(jdApi.fetchJdProductDetail).toHaveBeenCalledTimes(1) + expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1) + // 2026-11-16 客户口径「详情页的样式要和京麦商品详情一样」:hero 左图右信息布局, + // 断言随弹窗形状从 .drawer-mask 迁到 .jd-modal-mask(Phase 4 内容块逐字同源)。 + expect(wrapper.find('.detail-hero').exists()).toBe(true, '顶部左图右信息 hero 布局') + expect(wrapper.find('.hero-main').exists()).toBe(true, '左侧主图大图') + expect(wrapper.find('.hero-info').text()).toContain('价格区间') + expect(wrapper.find('.hero-info').text()).toContain('12.9 ~ 15.9', '价格走 decimalText(number/字符串都收)') + expect(wrapper.find('.jd-modal-mask').text()).toContain('规格') + expect(wrapper.find('.jd-modal-mask').text()).toContain('容量') + expect(wrapper.find('.jd-modal-mask').text()).toContain('500ml') + expect(wrapper.find('.jd-modal-mask').text()).toContain('主图') + const modalText = wrapper.find('.jd-modal-mask').text() + expect(modalText).toContain('货号') + expect(modalText).toContain('ITEM-1') + expect(modalText).toContain('信息分') + expect(modalText).toContain('上架时间') + // B104:详情里全量可见(店铺/分组也上详情,卡片不带这些字段)。 + expect(modalText).toContain('家居 > 厨具 > 保温杯') + expect(modalText).toContain('SKU 数') + expect(modalText).toContain('京东创建时间') + expect(modalText).toContain('京东修改时间') + expect(modalText).toContain('旗舰自营店') + expect(modalText).toContain('甲组') + wrapper.unmount() + }) + + it('弹窗内的销售属性=京麦 SKU 矩阵:维度列从 saleAttrs 派生;旧行没有矩阵时给可解释的空态', async () => { + jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload())) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + + expect(wrapper.find('.jd-modal-mask').text()).toContain('销售属性 / SKU 矩阵') + const headers = wrapper.findAll('.sku-table thead th').map((th) => th.text()) + expect(headers).toEqual(['序号', '颜色', '尺码', '京东价', '库存', 'SKU ID', 'SKU 名称'], + '维度列从各 SKU 的 saleAttrs 派生(京麦「颜色/尺码」两列)') + const firstRow = wrapper.findAll('.sku-table tbody tr')[0].findAll('td').map((td) => td.text()) + expect(firstRow).toEqual(['1', '上衣', 'S', '¥162', '200', '10238877506570', '花屿巷… 上衣 S']) + expect(wrapper.find('.jd-modal-mask').text()).toContain('1 个 SKU') + expect(wrapper.find('.jd-modal-mask').text()).toContain('库存 200') + wrapper.unmount() + + // 旧行没有 SKU 矩阵:给可解释的空态(不渲染空表、不静默吞)。 + jdApi.fetchJdProductDetail.mockImplementation(() => + Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' })) + const empty = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await empty.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + expect(empty.find('.sku-table').exists()).toBe(false) + expect(empty.find('.jd-modal-mask').text()).toContain('暂无 SKU 矩阵') + empty.unmount() + }) + + it('弹窗顶部「编辑」防冒泡:关详情开编辑抽屉(抽屉自取回填),保存成功(saved)→ 列表重取(黄金⑥)', async () => { + jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload())) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + + const callsBefore = jdApi.fetchJdProductList.mock.calls.length + await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '编辑')!.trigger('click') + await flushPromises() + expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点编辑先关详情弹窗') + const drawer = wrapper.findComponent(JdProductEditDrawer) + expect(drawer.exists()).toBe(true, '编辑抽屉已打开(真实路径点弹窗「编辑」)') + expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)') + // saved 是抽屉的对外契约(保存成功由抽屉内部流发出),页面消费它刷新列表。 + drawer.vm.$emit('saved') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, + '保存成功后重取列表(人工编辑锁置位与最新字段即时可见)') + wrapper.unmount() + }) + + it('弹窗顶部「删除」防冒泡:确认后调 deleteJdProducts(与旧操作列删除同一条链)', async () => { + jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload())) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + + // 先验「取消不动」:beforeEach 默认 confirm=true,本例先翻回 false。 + confirmMock.mockResolvedValue(false) + await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '删除')!.trigger('click') + await flushPromises() + expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点删除先关详情弹窗') expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认') expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求') - // 确认后:deleteJdProducts 按 id 直删(公共库写侧无公司维度,2026-11-15 公共化)。 + + // 确认后:deleteJdProducts 按 id 直删(公共库写侧无公司维度)。 confirmMock.mockResolvedValue(true) jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 }) - await wrapper.findAll('tbody tr')[0].findAll('td')[6].findAll('button').find((b) => b.text() === '删除')!.trigger('click') + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '删除')!.trigger('click') + await flushPromises() await flushPromises() expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1]) + wrapper.unmount() }) - it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => { - // fetchJdProductDetail 的返回已由 parseJdProductDetail 归一成 {item, attrGroups, images, skus, attrJsonRaw}。 - jdApi.fetchJdProductDetail.mockResolvedValue({ - item: { - id: 1, - title: '304不锈钢保温杯大容量便携', - brand: '锅宝', - categoryPath: '家居 > 厨具 > 保温杯', - itemNum: 'ITEM-1', - priceMin: 12.9, - priceMax: 15.9, - stockTotal: 500, - saleStatus: '上架中', - groupId: 7, - groupName: '甲组', - productCode: 'JD-1001', - shopName: '旗舰自营店', - }, - attrGroups: [], - images: [], - skus: [], - attrJsonRaw: '', - }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[6] - await opsCell.findAll('button').find((b) => b.text() === '编辑')!.trigger('click') - await flushPromises() - await flushPromises() - expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开') - expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品') - // 抽屉按 id 自取详情回填(公共库详情无公司维度)。 - expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1) - // 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。 - expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)') - }) - - it('商品信息列:主图无 URL 显示「无图」占位、healthScore 为空不出信息分行、skuCount 为空不出 SKU 标签', async () => { - const wrapper = await mountWith({ - items: [item(1), item(2, { mainImageUrl: '', healthScore: null, skuCount: null })], - total: 2, page: 1, pageSize: 20, - }) - const rowTexts = wrapper.findAll('tbody tr').map((tr) => tr.text()) - expect(wrapper.findAll('img.jd-thumb')).toHaveLength(1, '只有有自有桶 URL 的行出真图(无图占位是 span,不冒充 img)') - expect(rowTexts[1]).toContain('无图') - expect(rowTexts[1]).not.toContain('信息分') - expect(rowTexts[1]).not.toContain('个SKU') - }) - - it('商品编码旁复制按钮:写入剪贴板且不冒泡开抽屉', async () => { + it('商品编码旁复制按钮:写入剪贴板且不冒泡开弹窗', async () => { const writeText = vi.fn().mockResolvedValue(undefined) Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.find('.drawer-mask').exists()).toBe(false, '复制前抽屉未开') - await wrapper.findAll('.jd-copy-btn')[0].trigger('click') + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '复制前弹窗未开') + await wrapper.get('.jd-card-copy').trigger('click') expect(writeText).toHaveBeenCalledWith('JD-1001') - expect(wrapper.find('.drawer-mask').exists()).toBe(false, '点复制按钮不冒泡开抽屉') + expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点复制按钮不冒泡开弹窗') + wrapper.unmount() }) - it('分类读不到的那行展示「未分类」(不猜名字;2026-11-15「分组管理」改「店铺分类」只换措辞)', async () => { - const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类') + it('分组读不到的那行详情里展示「未分类」(不猜名字;表格分类列退役后语义收进 hero)', async () => { + jdApi.fetchJdProductDetail.mockImplementation(() => + Promise.resolve({ ...detailPayload(), item: item(1, { groupId: null, groupName: '' }) })) + const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 }) + await wrapper.findAll('.jd-card')[0].trigger('click') + await flushPromises() + await flushPromises() + expect(wrapper.find('.jd-modal-mask').text()).toContain('未分类') + wrapper.unmount() }) +}) - it('筛选生效:编码/关键字/分组/起止日期,查询回第一页重发(店铺筛选 2026-11-15 下线)', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }]) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) +describe('筛选与分页(AC-9:列表 HTTP 参数与 v1.4 逐字等价)', () => { + it('筛选生效:编码/关键字/分组分类/起止日期,查询回第一页重发(店铺/商品状态/导出已下线)', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) const textInputs = wrapper.findAll('.form-group input[type="text"]') - expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)') + expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(类目进侧栏、店铺/商品状态已下线)') await textInputs[0].setValue('JD-1001') await textInputs[1].setValue('保温杯') - await pickSelectOption(wrapper, '筛选店铺分类', '甲组') + // 分类筛选现在从侧栏店铺分类 Tab 来(旧「筛选店铺分类」下拉退役)。 + await pickSideTab(wrapper, '店铺分类') + await sideRowBy(sideCustom(wrapper), '裙装').trigger('click') + await flushPromises() const dateInputs = wrapper.findAll('input[type="date"]') await dateInputs[0].setValue('2026-11-01') await dateInputs[1].setValue('2026-11-09') @@ -568,348 +860,64 @@ describe('京东数据库页(v1.4 Phase 5)', () => { expect(last).not.toHaveProperty('shopName') expect(last).not.toHaveProperty('saleStatus') expect(last).not.toHaveProperty('companyId') + wrapper.unmount() }) - it('类目京麦同款级联面板(2026-11-16 真树重做):授权一级 3 个逐级下钻,点末级即查回第一页', async () => { - jdApi.fetchJdProductCategories.mockResolvedValue([ - { name: '艺考形体服', productCount: 120 }, - { name: '啦啦队服', productCount: 8 }, - ]) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith() - - const trigger = wrapper.find('.cat-trigger') - expect(trigger.text()).toContain('全部类目', '未选时触发框显示占位「全部类目」') - expect(wrapper.find('.cat-panel').exists()).toBe(false, '面板初始不展开') - - await trigger.trigger('click') - expect(wrapper.find('.cat-panel').exists()).toBe(true) - // 第一栏=京麦授权一级真树(2026-11-16 真机取证就 3 个:服饰内衣/母婴/运动户外)。 - const firstCol = wrapper.findAll('.cat-col')[0] - expect(firstCol.text()).toContain('服饰内衣') - expect(firstCol.text()).toContain('母婴') - expect(firstCol.text()).toContain('运动户外') - // 点一级展开第二栏(非末级行点击=下钻)。 - await firstCol.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!.trigger('click') - let cols = wrapper.findAll('.cat-col') - expect(cols).toHaveLength(2, '点亮一级后第二栏出现(树内逐级下钻)') - expect(cols[1].text()).toContain('服饰配件') - expect(cols[1].text()).toContain('女装') - // 点二级展开第三栏(京麦同款三级末级,取证快照:服饰配件 13 个)。 - await cols[1].findAll('.cat-row').find((row) => row.text().includes('服饰配件'))!.trigger('click') - cols = wrapper.findAll('.cat-col') - expect(cols).toHaveLength(3, '三级栏出现(末级行不再下钻)') - expect(cols[2].text()).toContain('腰带/腰链') - - // 点末级=选中即查(按 category_path 等值过滤口径不变)、面板收起、触发框显示已选名。 - await cols[2].findAll('.cat-row').find((row) => row.text().includes('腰带/腰链'))!.trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '腰带/腰链', page: 1 }) - expect(wrapper.find('.cat-panel').exists()).toBe(false, '选中后面板收起') - expect(wrapper.find('.cat-trigger').text()).toContain('腰带/腰链') - }) - - it('一级/二级类目点圆点可选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」):入参带节点路径、行体仍下钻', async () => { - jdApi.fetchJdProductCategories.mockResolvedValue([]) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - await wrapper.find('.cat-trigger').trigger('click') - - // 一级行体点击=仍下钻(旧语义不动);一级圆点点击=选中整棵一级子树。 - const firstCol = wrapper.findAll('.cat-col')[0] - const apparelRow = firstCol.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))! - await apparelRow.find('.cat-dot').trigger('click') - await flushPromises() - expect(wrapper.find('.cat-panel').exists()).toBe(false, '点圆点选中后面板收起') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ - category: '服饰内衣', - categoryPath: ['服饰内衣'], - page: 1, - }, '一级选中=带路径下发(序列化侧展开子树类目名集合)') - expect(wrapper.find('.cat-trigger').text()).toContain('服饰内衣') - - // 下钻两级后点二级圆点:路径带全前缀,同名跨支靠路径区分。 - await wrapper.find('.cat-trigger').trigger('click') - const col1 = wrapper.findAll('.cat-col')[0] - await col1.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!.trigger('click') - const col2 = wrapper.findAll('.cat-col')[1] - await col2.findAll('.cat-row').find((row) => row.text().includes('女装'))!.find('.cat-dot').trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ - category: '女装', - categoryPath: ['服饰内衣', '女装'], - page: 1, - }) - - // 选中态回显:重开面板自动按已选路径展开(2026-11-19 客户「选中没实心」——旧形状 - // 重开只铺第一栏,实心圆点要手动下钻两级才看得见),女装圆点直接蓝芯(.cat-dot.on), - // 同栏未选中行空心。 - await wrapper.find('.cat-trigger').trigger('click') - const reopenedCols = wrapper.findAll('.cat-col') - expect(reopenedCols).toHaveLength(2, '重开面板按已选路径自动展开到末级所在栏') - const womenRow = reopenedCols[1].findAll('.cat-row').find((row) => row.text().includes('女装'))! - expect(womenRow.find('.cat-dot').classes()).toContain('on', '二级选中态圆点回显') - const menRow = reopenedCols[1].findAll('.cat-row').find((row) => row.text().includes('男装'))! - expect(menRow.find('.cat-dot').classes()).not.toContain('on', '未选中行保持空心圆') - }) - - it('类目级联搜索与清选(2026-11-16 真树重做):树内末级命中+树外兜底段;「全部类目」行/触发框 × 都能清选重查', async () => { - jdApi.fetchJdProductCategories.mockResolvedValue([ - { name: '艺考形体服', productCount: 120 }, - { name: '已下架历史类目', productCount: 3 }, - ]) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - - await wrapper.find('.cat-trigger').trigger('click') - // 搜索态:树内末级按名称/路径命中(艺考形体服在树内=女装支末级)。 - await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考') - const searchCol = wrapper.find('.cat-col-search') - const visibleRows = searchCol.findAll('.cat-row') - expect(visibleRows).toHaveLength(1, '搜索「艺考」只命中树内末级「艺考形体服」') - expect(searchCol.text()).toContain('艺考形体服') - expect(searchCol.text()).not.toContain('已下架历史类目', '不匹配项不出现') - await visibleRows[0].trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '艺考形体服', page: 1 }) - - // 树外兜底:已落库但京麦树里已没有的名字(历史行)从兜底段搜出可选。 - await wrapper.find('.cat-trigger').trigger('click') - await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('已下架历史') - const fallbackCol = wrapper.find('.cat-col-search') - expect(fallbackCol.text()).toContain('已落库类目(树外历史)') - expect(fallbackCol.text()).toContain('已下架历史类目') - await fallbackCol.findAll('.cat-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目' }) - - // 点「全部类目」行=清选重查(category 入参回空串、query 层不下发,回第一页)。 - await wrapper.find('.cat-trigger').trigger('click') - const callsBefore = jdApi.fetchJdProductList.mock.calls.length - await wrapper.find('.cat-row-all').trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('') - - // 触发框已选时出 × 清除按钮:点了同样清选。 - await wrapper.find('.cat-trigger').trigger('click') - await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考') - await wrapper.find('.cat-col-search').findAll('.cat-row')[0].trigger('click') - await flushPromises() - expect(wrapper.find('.cat-trigger').text()).toContain('艺考形体服') - const callsBeforeClear = jdApi.fetchJdProductList.mock.calls.length - await wrapper.find('.cat-clear').trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeClear + 1, '× 清除同样触发重查') - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('') - }) - - it('不再显示独立分类与分类状态筛选;工具栏入口是「批量编辑分类」(弹窗 2026-11-17 下线)', async () => { - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - expect(wrapper.find('.jd-filter-row').text()).not.toContain('分类状态') - expect(wrapper.find('.jd-filter-row select').exists()).toBe(false) - expect(wrapper.findAll('button').some(button => button.text() === '批量编辑分类')).toBe(true) - expect(wrapper.findAll('button').some(button => button.text() === '店铺分类')).toBe(false, '「店铺分类」入口已删') - }) - - it('重置把筛选面回空并回第一页重取', async () => { - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }]) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - expect(optionLabels(wrapper, '筛选店铺分类')[0]).toBe('全部分类', '「全部分类」常驻列表首位(与旧原生下拉同语义)') - await pickSelectOption(wrapper, '筛选店铺分类', '甲组') - await wrapper.get('.cat-trigger').trigger('click') - await wrapper.get('.cat-search').setValue('艺考') - await wrapper.get('.cat-col-search .cat-row').trigger('click') + it('重置把筛选面回空并回第一页重取(归属三档回未分类档、侧栏选中态清空)', async () => { + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) const textInputs = wrapper.findAll('.form-group input[type="text"]') await textInputs[0].setValue('JD-1001') await textInputs[1].setValue('保温杯') - const callsBefore = jdApi.fetchJdProductList.mock.calls.length + await pickSideTab(wrapper, '店铺分类') + await sideRowBy(sideCustom(wrapper), '裙装').trigger('click') + await flushPromises() + expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7' }) + const callsBefore = jdApi.fetchJdProductList.mock.calls.length await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click') await flushPromises() expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore) const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0] expect(last).toMatchObject({ productCode: '', titleKeyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页') - expect(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '重置后分类筛选回「全部分类」') + expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随重置清空') + expect(sideCustom(wrapper).findAll('.jd-side-row')).toHaveLength(2, + '重置只清筛选面:侧栏分类清单(当前组)保留,清选语义=再点已选行') + wrapper.unmount() }) it('翻页与改每页条数都重发请求,改条数回第一页', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 42, page: 2, pageSize: 20 }) + // total=120(50/页下三页):第 2 页的「下一页」要有第 3 页可去。 + const wrapper = await mountWith({ items: [item(1)], total: 120, page: 2, pageSize: 50 }) await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') await flushPromises() expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(2) expect(jdApi.fetchJdProductList.mock.calls[1][0].page).toBe(3) - // 每页条数下拉 2026-11-17 随分页条一起换 el-select(OldPagination 内局部注册): - // 点开→点选项,不再走原生 setValue。 + // 每页条数下拉随分页条换 el-select(OldPagination 内局部注册): + // 点开→点选项,不再走原生 setValue;档位 20/50/100(v1.6 契约)。 expect(wrapper.find('.page-size-select').exists()).toBe(true, '分页条下拉保留 .page-size-select 定位类') - await pickSelectOption(wrapper, '每页条数', '50条/页') + await pickSelectOption(wrapper, '每页条数', '20条/页') await flushPromises() const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0] - expect(last.pageSize).toBe(50) + expect(last.pageSize).toBe(20) expect(last.page).toBe(1, '改每页条数后回第一页') + wrapper.unmount() }) it('导出按钮已下线:筛选行不再出现「导出」(2026-11-15 客户口径「导出也不用」)', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) const btn = wrapper.findAll('button').find((b) => b.text() === '导出') expect(btn, '导出按钮必须已从前端移除').toBeUndefined() expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏') - }) - - it('点行打开详情抽屉:按 id 取详情(公共库无公司维度),attrGroups 分块渲染', async () => { - jdApi.fetchJdProductDetail.mockImplementation(() => - Promise.resolve({ - item: item(1), - attrGroups: [{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] }], - images: [{ imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main-1.jpg', byteSize: null, width: 800, height: 800 }], - skus: [], - attrJsonRaw: '', - }), - ) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.find('.drawer-mask').exists()).toBe(false, '初始不显示抽屉') - - await wrapper.findAll('tbody tr')[0].trigger('click') - await flushPromises() - await flushPromises() - - expect(wrapper.find('.drawer-mask').exists()).toBe(true) - expect(jdApi.fetchJdProductDetail).toHaveBeenCalledTimes(1) - expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1) - // 2026-11-16 客户口径「详情页的样式要和京麦商品详情一样」:顶部改「左图右信息」hero - // 布局(左侧主图大图+缩略图,右侧关键信息),「基本信息」块标题随 hero 化下线。 - expect(wrapper.find('.detail-hero').exists()).toBe(true, '顶部左图右信息 hero 布局') - expect(wrapper.find('.hero-main').exists()).toBe(true, '左侧主图大图') - expect(wrapper.find('.hero-info').text()).toContain('价格区间') - expect(wrapper.find('.hero-info').text()).toContain('12.9 ~ 15.9', '价格走 decimalText(number/字符串都收)') - expect(wrapper.find('.drawer-mask').text()).toContain('规格') - expect(wrapper.find('.drawer-mask').text()).toContain('容量') - expect(wrapper.find('.drawer-mask').text()).toContain('500ml') - expect(wrapper.find('.drawer-mask').text()).toContain('主图') - const drawerText = wrapper.find('.drawer-mask').text() - expect(drawerText).toContain('货号') - expect(drawerText).toContain('ITEM-1') - expect(drawerText).toContain('信息分') - expect(drawerText).toContain('上架时间') - // B104:详情里全量可见(店铺/分组 2026-11-15 起也上了列表,抽屉仍保留)。 - expect(drawerText).toContain('家居 > 厨具 > 保温杯') - expect(drawerText).toContain('SKU 数') - expect(drawerText).toContain('京东创建时间') - expect(drawerText).toContain('京东修改时间') - expect(drawerText).toContain('旗舰自营店') - expect(drawerText).toContain('甲组') - }) - - it('详情抽屉的销售属性=京麦那 12 行 SKU 矩阵:颜色/尺码两列维度 + 京东价 + 库存 + skuId', async () => { - const skuRows = [ - { skuId: '10238877506570', skuName: '花屿巷… 上衣 S', skuSeq: '1', price: 162, stock: 200, sortNo: 0, - saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }] }, - { skuId: '10238877506574', skuName: '花屿巷… 上衣 M', skuSeq: '2', price: 168, stock: 150, sortNo: 1, - saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'M' }] }, - { skuId: '10238877506580', skuName: '花屿巷… 半裙 S', skuSeq: '3', price: 162, stock: 80, sortNo: 2, - saleAttrs: [{ name: '颜色', value: '半裙' }, { name: '尺码', value: 'S' }] }, - ] - jdApi.fetchJdProductDetail.mockImplementation(() => - Promise.resolve({ - item: item(1), - attrGroups: [], - images: [], - skus: skuRows, - attrJsonRaw: '', - }), - ) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody tr')[0].trigger('click') - await flushPromises() - await flushPromises() - - expect(wrapper.find('.drawer-mask').text()).toContain('销售属性 / SKU 矩阵') - const headers = wrapper.findAll('.sku-table thead th').map((th) => th.text()) - expect(headers).toEqual(['序号', '颜色', '尺码', '京东价', '库存', 'SKU ID', 'SKU 名称'], - '维度列从各 SKU 的 saleAttrs 派生(京麦「颜色/尺码」两列)') - - const rows = wrapper.findAll('.sku-table tbody tr') - expect(rows).toHaveLength(3, '12 行矩阵按入库行数渲染') - const first = rows[0].findAll('td').map((td) => td.text()) - expect(first).toEqual(['1', '上衣', 'S', '¥162', '200', '10238877506570', '花屿巷… 上衣 S']) - expect(rows[1].findAll('td').map((td) => td.text())[3]).toBe('¥168', '每行自己的京东价') - expect(wrapper.find('.drawer-mask').text()).toContain('3 个 SKU') - expect(wrapper.find('.drawer-mask').text()).toContain('库存 430', '汇总=各行库存之和') - }) - - it('旧行没有 SKU 矩阵时给可解释的空态(不渲染空表、不静默吞)', async () => { - jdApi.fetchJdProductDetail.mockImplementation(() => - Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' }), - ) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody tr')[0].trigger('click') - await flushPromises() - await flushPromises() - - expect(wrapper.find('.sku-table').exists()).toBe(false) - expect(wrapper.find('.drawer-mask').text()).toContain('暂无 SKU 矩阵') - }) - - it('删除:勾选两行点删除 → 二次确认点名数量与桶清理 → 批量端点按 id 直删(公共库无公司维度),成功后刷新并清勾选', async () => { - jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 }) - const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 }) - - // 批量删除常显(2026-11-16 客户口径「不要勾选后才显示」):未勾选时就在,只是置灰。 - expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '「批量删除」常显') - expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined() - const boxes = wrapper.findAll('tbody input[type="checkbox"]') - await boxes[0].setValue(true) - await boxes[1].setValue(true) - expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeUndefined('勾选后按钮可点') - await wrapper.find('.jd-delete-btn').trigger('click') - await flushPromises() - await flushPromises() - - expect(confirmMock).toHaveBeenCalledTimes(1) - const options = confirmMock.mock.calls[0][0] - expect(options.title).toBe('删除京东商品') - expect(options.message).toContain('确定批量删除选中的 2 个商品吗') - expect(options.message).toContain('jd-products 桶内图片文件一并删除', '确认弹窗必须点名「桶文件也会删」') - expect(options.danger).toBe(true) - - expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1) - expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2]) - expect(document.body.textContent).toContain('已删除 2 个商品') - expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈') - // 成功后重取列表并清勾选:常显按钮回到置灰(不再消失)。 - expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1) - expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) - expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined() - }) - - it('删除:确认弹窗点取消就不发请求(防误删的第一道闸)', async () => { - confirmMock.mockResolvedValue(false) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - await wrapper.find('.jd-delete-btn').trigger('click') - await flushPromises() - - expect(confirmMock).toHaveBeenCalledTimes(1) - expect(jdApi.deleteJdProducts).not.toHaveBeenCalled() - }) - - it('删除失败把后端「本次未删除任何数据」文案弹出来(整批拒绝的语义必须到界面)', async () => { - jdApi.deleteJdProducts.mockRejectedValue(new Error('桶内对象删除失败,本次未删除任何数据(jd-products/5/a.jpg):oss 5xx')) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - await wrapper.find('.jd-delete-btn').trigger('click') - await flushPromises() - await flushPromises() - - expect(document.body.textContent).toContain('本次未删除任何数据') - // 失败后勾选保留,用户可重试。 - expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) + wrapper.unmount() }) it('空态与加载失败条(失败给重试,不把整页打死)', async () => { - const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) - const tip = empty.find('.empty-tip') + const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) + const tip = empty.find('.jd-empty-tip') expect(tip.exists()).toBe(true) expect(tip.text()).toContain('暂无京东商品数据') empty.unmount() @@ -920,97 +928,52 @@ describe('京东数据库页(v1.4 Phase 5)', () => { await flushPromises() expect(failed.find('.load-failure-bar').exists()).toBe(true) expect(failed.find('.load-failure-bar').text()).toContain('京东商品列表加载失败') - }) - - it('末页删空页码回退:第 2 页只剩 1 行删掉后回第 1 页重取(Phase 0 黄金测试 ⑤)', async () => { - // total=21 让分页条出「下一页」;第 1 页夹具从简(2 行),语义落在「末页删空回退」上。 - jdApi.fetchJdProductList - .mockImplementationOnce(() => Promise.resolve({ items: [item(1), item(2)], total: 21, page: 1, pageSize: 20 })) - .mockImplementationOnce(() => Promise.resolve({ items: [item(21)], total: 21, page: 2, pageSize: 20 })) - .mockImplementation(() => Promise.resolve({ items: [], total: 20, page: 1, pageSize: 20 })) - const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } }) - await flushPromises() - await flushPromises() - await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(2, '先到第 2 页(该页只剩 1 行)') - - jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 }) - await wrapper.findAll('tbody tr')[0].findAll('td')[6].findAll('button').find((b) => b.text() === '删除')!.trigger('click') - await flushPromises() - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, pageSize: 20 }, - '末页删空后页码回退重取(停在空页会让用户误以为库空了)') - wrapper.unmount() - }) - - it('编辑保存成功(抽屉 emit saved)→ 列表重取(Phase 0 黄金测试 ⑥)', async () => { - jdApi.fetchJdProductDetail.mockResolvedValue({ - item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '', - }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - const callsBefore = jdApi.fetchJdProductList.mock.calls.length - await wrapper.findAll('tbody tr')[0].findAll('td')[6].findAll('button').find((b) => b.text() === '编辑')!.trigger('click') - await flushPromises() - const drawer = wrapper.findComponent(JdProductEditDrawer) - expect(drawer.exists()).toBe(true, '编辑抽屉已打开(真实路径点「编辑」)') - // saved 是抽屉的对外契约(保存成功由抽屉内部流发出),页面消费它刷新列表。 - drawer.vm.$emit('saved') - await flushPromises() - expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, - '保存成功后重取列表(人工编辑锁置位与最新字段即时可见)') - wrapper.unmount() + failed.unmount() }) }) -/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,推翻 - * 2026-11-16 的平台超管单档):商品行写(编辑/删除/勾选批量删)对管理员级(超管/admin 档) - * 渲染,普通账号只读;分类写(批量编辑分类、分类管理)由 scope 的每组 editable 决定 - * (本组管理员/公司超管/平台超管)。同日口径「超管可以有分组筛选,管理员及以下则没有」: - * 筛选行「分组」控件整块只对超管档(超级管理员/公司超级管理员)渲染。 */ +/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,铁律 33 + * 判据②语义等价迁移:操作列/勾选列的档位判定原样落到「卡片勾选框+工具栏+详情弹窗 + * 动作区」三种新 DOM 上;分组筛选=超管档专属口径不动)。 */ describe('京东数据库写权限分档(商品行写=超管+管理员;分组筛选=超管档;分类写=本组 editable)', () => { - it('普通员工且本组不可写:无勾选列、无操作列、无批量删除、无批量编辑分类、无分组控件;列表/筛选/详情照常', async () => { + it('普通员工且本组不可写:无勾选框、无工具栏写按钮、无删除商品、无归入分类、无分组控件;列表/筛选/详情照常', async () => { useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' } // 普通员工:可见但不可写(editable=false)。 jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false)) - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }]) - jdApi.fetchJdProductDetail.mockImplementation(() => - Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' }), - ) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload())) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) - expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(0, '不可写分类的普通员工没有勾选列') - expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '批量删除按钮不渲染') - expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '分类写入口不渲染(本组不可写)') - expect(wrapper.findAll('button').some((b) => b.text() === '分类管理')).toBe(true, - '分类管理入口是读面,普通员工也能打开看(写控件由对话框按 editable 分档)') - expect(wrapper.find('thead').text()).not.toContain('操作', '操作列(编辑/删除)不渲染') - expect(wrapper.text()).toContain('只读:编辑/删除需超级管理员或管理员', '只读提示必须看得见并区分两类写权限') - expect(wrapper.text()).toContain('分类在本页「分类管理」查看与维护', '提示把分类维护入口指向本页「分类管理」(独立页已并入)') - // 分组筛选=超管档专属(2026-11-17 口径):普通员工连单组锁定芯片都不出。 + expect(cardBoxes(wrapper)).toHaveLength(0, '不可写分类的普通员工没有勾选框') + expect(wrapper.find('.jd-toolbar').exists()).toBe(false, '工具栏(全选/归类/删除)整块不渲染') + expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '删除商品按钮不渲染') expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '普通员工不出分组下拉') expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '普通员工不出分组锁定芯片') + expect(wrapper.text()).toContain('只读:编辑/删除需超级管理员或管理员', '只读提示必须看得见并区分两类写权限') + expect(wrapper.text()).toContain('分类在左侧「分类管理」查看与维护', '提示把分类维护入口指向侧栏「分类管理」') - // 读面不受影响:筛选下拉、列表行、点行开详情都还在。 - expect(wrapper.get('[aria-label="筛选店铺分类"]').exists()).toBe(true, '分类筛选是读面,保留') - expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(5, '普通员工列表 5 列:分类/商品信息/总库存/价格/同步时间') - await wrapper.findAll('tbody tr')[0].trigger('click') + // 读面不受影响:筛选、侧栏分类行、点卡片开只读详情都还在。 + expect(wrapper.findAll('.jd-card')).toHaveLength(1) + await wrapper.findAll('.jd-card')[0].trigger('click') await flushPromises() await flushPromises() - expect(wrapper.find('.drawer-mask').exists()).toBe(true, '点行仍可开只读详情抽屉') + expect(wrapper.find('.jd-modal-mask').exists()).toBe(true, '点卡片仍可开只读详情弹窗') expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1) + expect(wrapper.find('.jd-modal-actions').exists()).toBe(false, '只读档详情弹窗无动作区(普通账号只读)') wrapper.unmount() }) - it('超管保留全部写入口(勾选列+操作列+批量删除+批量编辑分类),且不显示只读提示', async () => { + it('超管保留全部写入口(勾选框+工具栏整排+删除商品),且不显示只读提示', async () => { // beforeEach 默认 super_admin;这里显式再钉一次,防默认值漂移把这条闸门变成恒绿。 useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' } - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) - expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(1) - expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7) + expect(cardBoxes(wrapper)).toHaveLength(1) + expect(toolbarBtn(wrapper, '全选本页').exists()).toBe(true) + expect(toolbarBtn(wrapper, '取消本页').exists()).toBe(true) + expect(toolbarBtn(wrapper, '归入分类').exists()).toBe(true) + expect(toolbarBtn(wrapper, '取消归属').exists()).toBe(true) expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) - expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(true) expect(wrapper.text()).not.toContain('只读:') expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '超管档保留分组控件(单组=锁定芯片)') wrapper.unmount() @@ -1018,41 +981,37 @@ describe('京东数据库写权限分档(商品行写=超管+管理员; it('公司超级管理员属超管档:写入口齐+分组控件在(单组=锁定芯片)', async () => { useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' } - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) - expect(wrapper.findAll('tbody input[type="checkbox"]')).toHaveLength(1) - expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7, '公司超管 7 列:含操作列') - expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '批量删除对公司超管渲染') + expect(cardBoxes(wrapper)).toHaveLength(1) + expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '删除商品对公司超管渲染') + expect(toolbarBtn(wrapper, '取消归属').exists()).toBe(true) expect(wrapper.text()).not.toContain('只读:') expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '公司超管保留分组控件') wrapper.unmount() }) - it('管理员(admin 档):商品行写全放开(7 列+批量删除),分组控件整块不渲染', async () => { + it('管理员(admin 档):商品行写全放开(勾选框+工具栏整排),分组控件整块不渲染;归类带三参', async () => { useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' } // 组长档形状:可见组可写 ⇒ editable=true;商品行写按管理员档判(2026-11-17 口径)。 jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(true)) - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }]) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.findAll('tbody tr')[0].findAll('td')).toHaveLength(7, '管理员 7 列:勾选/分类/商品信息/总库存/价格/同步/操作') - expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '批量删除(商品行写)对管理员渲染') - expect(wrapper.find('thead').text()).toContain('操作', '操作列(编辑/删除)对管理员渲染') + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(cardBoxes(wrapper)).toHaveLength(1, '管理员有勾选框(服务批量删除与归类)') + expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '删除商品(商品行写)对管理员渲染') expect(wrapper.text()).not.toContain('只读:') // 分组筛选=超管档专属:管理员即使本组可写分类,也不出下拉/锁定芯片。 expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '管理员不出分组下拉') expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '管理员不出分组锁定芯片') - const editBtn = wrapper.findAll('button').find((b) => b.text() === '批量编辑分类') - expect(editBtn, '本组管理员有批量编辑分类入口').toBeTruthy() - // 管理员可勾选并走一遍归类(2026-11-17 弹窗下线后唯一的归类路径)。 + // 管理员可勾选并走一遍归类(2026-11-17 弹窗下线后唯一的归类路径;铁律 33 判据③)。 jdApi.batchAssignJdProductGroup.mockResolvedValue(1) - await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true) - expect(editBtn!.attributes('disabled')).toBeUndefined('勾选后可点') - await editBtn!.trigger('click') + await cardBoxes(wrapper)[0].setValue(true) + await toolbarBtn(wrapper, '归入分类').trigger('click') await flushPromises() const modal = wrapper.get('.batch-modal') await modal.findAll('.option-row')[0].trigger('click') - await modal.findAll('button').find((b) => b.text() === '归入「甲组」')!.trigger('click') + await modal.findAll('button').find((b) => b.text() === '归入「裙装」')!.trigger('click') await flushPromises() await flushPromises() expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A) @@ -1069,19 +1028,18 @@ describe('京东数据库写权限分档(商品行写=超管+管理员; { id: 12, name: 'B组', label: '甲公司 / B组', editable: false }, ], }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) // 多组对管理员也不渲染切换下拉(作用域静默落在默认组)。 expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '多组也不给管理员出分组下拉') - // 写入口不受影响:操作列+批量删除都在,列表按默认组取。 - expect(wrapper.find('thead').text()).toContain('操作') + // 写入口不受影响:工具栏整排都在,列表按默认组取。 expect(wrapper.find('.jd-delete-btn').exists()).toBe(true) expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11) expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 }) wrapper.unmount() }) - it('公司超级管理员多组可见:分组下拉在(超管档专属),可切组取数', async () => { + it('公司超级管理员多组可见:分组下拉在(超管档专属),可切组取数(铁律 33 判据①)', async () => { useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' } jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, @@ -1091,7 +1049,7 @@ describe('京东数据库写权限分档(商品行写=超管+管理员; { id: 12, name: 'B组', label: '甲公司 / B组', editable: true }, ], }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(true, '公司超管保留分组下拉') await pickSelectOption(wrapper, '当前分组', '甲公司 / B组') @@ -1103,7 +1061,7 @@ describe('京东数据库写权限分档(商品行写=超管+管理员; }) describe('京东数据库分类按数据权限分组隔离(V203)', () => { - it('多组可见:筛选行出带标签的「分组」下拉,切换后分类下拉与列表一并用新组取', async () => { + it('多组可见:筛选行出带标签的「分组」下拉,切换后侧栏分类与列表一并用新组取', async () => { jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: true, defaultGroupId: 11, @@ -1112,14 +1070,13 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { { id: 12, name: 'B组', label: '甲公司 / B组', editable: true }, ], }) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) // 首屏就按默认组取(不是先不带 ownerGroupId 再补一次)。 expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11) expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 }) const picker = wrapper.get('[aria-label="当前分组"]') - // 2026-11-16 用户口径「做成分组」:分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角), - // 不再是工具栏裸下拉——钉住形状,防止搬回工具栏或丢标签。 + // 分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角),不再是工具栏裸下拉。 const groupField = picker.element.closest('.form-group') expect(groupField?.querySelector('label')?.textContent).toBe('分组') expect(optionLabels(wrapper, '当前分组')).toEqual(['甲公司 / A组', '甲公司 / B组'], @@ -1134,9 +1091,9 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { }) it('只有一组:不出下拉(锁定显示组名),分类与行集仍按该组取', async () => { - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '单组不渲染切换下拉') - expect(wrapper.get('.jd-group-locked').text()).toBe('甲组', '锁定芯片只放组名,「分组」二字在上方标签里(2026-11-16 口径)') + expect(wrapper.get('.jd-group-locked').text()).toBe('甲组', '锁定芯片只放组名,「分组」二字在上方标签里') expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: GROUP_A }) wrapper.unmount() }) @@ -1150,7 +1107,7 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { { id: 12, name: 'B组', label: '甲公司 / B组', editable: true }, ], }) - const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 }) await pickSelectOption(wrapper, '当前分组', '甲公司 / B组') await flushPromises() expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 }) @@ -1162,14 +1119,16 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { wrapper.unmount() }) - it('不属于任何数据权限分组:分类全空、不给切换也不给批量归类入口', async () => { + it('不属于任何数据权限分组:侧栏分类全空、不给切换也不给批量归类入口', async () => { jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] }) - const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 }) + const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 }) expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false) expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名') - expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类筛选只剩「全部分类」') - expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类') - expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '没有分组就没有可写的分类面') + await pickSideTab(wrapper, '店铺分类') + expect(sideCustom(wrapper).text()).toContain('本组暂无分类', '侧栏分类面空态') + expect(sideCustom(wrapper).find('[aria-label="新分类名称"]').exists()).toBe(false) + expect(wrapper.findAll('.jd-toolbar button').some((b) => b.text() === '归入分类')).toBe(false, + '没有分组就没有可写的分类面') expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled() wrapper.unmount() }) @@ -1183,9 +1142,10 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { { id: 12, name: 'B组', label: '甲公司 / B组', editable: true }, ], }) - jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '裙装', sortOrder: 0, productCount: 3 }]) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - await pickSelectOption(wrapper, '筛选店铺分类', '裙装') + jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS) + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + await pickSideTab(wrapper, '店铺分类') + await sideRowBy(sideCustom(wrapper), '裙装').trigger('click') await flushPromises() expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 }, '先选中本组分类(带 groupId 查)') @@ -1195,7 +1155,7 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0] expect(last).toMatchObject({ ownerGroupId: 12, page: 1 }, '切组后回第一页按新组重取') expect(last.groupId).toBe('', '上一组的分类 id 不能带进新组(changeOwnerGroup 清 filter.groupId)') - expect(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '分类筛选下拉回显回「全部分类」') + expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随切组清空') wrapper.unmount() }) }) @@ -1203,13 +1163,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => { /** 首屏作用域同源与静默降级(Phase 0 黄金测试,2026-11-21 蓝图缺口清单 ①②): * 铁律 30 同形——「先解析作用域再取列表」是首屏顺序契约:scope 未回前列表不发请求, * 首调即带默认组 owner_group_id(两请求落在同一组上,不得先发一条不带分组的列表再补); - * scope 拉取失败静默降级——分类面回空(分类下拉只剩「全部分类」、无分组控件与锁定芯片) - * 而商品行集照常渲染(分类只是筛选/归类面,不拦首屏行集)。Phase 5 重写页面装配层时 - * 这两条是装配顺序与降级语义的安全网。 */ + * scope 拉取失败静默降级——分类面回空(侧栏分类空态、无分组控件与锁定芯片) + * 而商品行集照常渲染(分类只是筛选/归类面,不拦首屏行集)。 */ describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () => { it('首屏先作用域后列表:scope 未回前列表不发请求,首调即带默认组(铁律 30 同源)', async () => { jdApi.fetchJdProductList.mockImplementation(() => - Promise.resolve({ items: [item(1)], total: 1, page: 1, pageSize: 20 })) + Promise.resolve({ items: [item(1)], total: 1, page: 1, pageSize: 50 })) let resolveScope!: (value: unknown) => void jdApi.fetchJdCategoryScope.mockImplementation(() => new Promise((resolve) => { resolveScope = resolve })) @@ -1223,18 +1182,18 @@ describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () => await flushPromises() expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1) expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: GROUP_A, page: 1 }, - '列表首调即带作用域默认组(与分类下拉同一个组)') + '列表首调即带作用域默认组(与侧栏分类同一个组)') expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(GROUP_A) wrapper.unmount() }) it('scope 拉取失败静默降级:分类面回空而商品行集照常渲染(不拦首屏)', async () => { jdApi.fetchJdCategoryScope.mockRejectedValue(new Error('scope 上游 502')) - const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 }) - expect(wrapper.findAll('tbody tr')).toHaveLength(1, '商品行集不受 scope 失败影响') - expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类下拉只剩「全部分类」') + const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 }) + expect(wrapper.findAll('.jd-card')).toHaveLength(1, '商品行集不受 scope 失败影响') expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '没有作用域就没有分组切换') expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有作用域就没有锁定芯片') + expect(sideCustom(wrapper).text()).toContain('本组暂无分类', '侧栏分类面空态(降级不冒充有数据)') wrapper.unmount() }) })