From b88432d8a9a1c8619a5e4e023ef22ac1f1dd25db 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:00:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(phase-3):=20=E4=BA=AC=E4=B8=9C=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=8D=A1=E7=89=87=E7=BB=84=E4=BB=B6=E2=80=94=E2=80=94?= =?UTF-8?q?=E4=B8=BB=E5=9B=BE/=E5=BA=97=E9=93=BA=E5=BE=BD=E6=A0=87/?= =?UTF-8?q?=E6=A0=87=E9=A2=98/=E4=BB=B7=E6=A0=BC/=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=A4=8D=E5=88=B6/=E9=87=87=E9=9B=86=E6=97=A5=E6=9C=9F/?= =?UTF-8?q?=E5=8B=BE=E9=80=89=EF=BC=88additive=EF=BC=8C=E9=98=B2=E5=86=92?= =?UTF-8?q?=E6=B3=A1=E9=92=89=E6=AD=BB=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/jd/JdProductCard.vue | 204 ++++++++++++++++++ .../tests/mount/jd-product-card.mount.test.ts | 114 ++++++++++ 2 files changed, 318 insertions(+) create mode 100644 admin-frontend-vue/src/pages/jd/JdProductCard.vue create mode 100644 admin-frontend-vue/tests/mount/jd-product-card.mount.test.ts diff --git a/admin-frontend-vue/src/pages/jd/JdProductCard.vue b/admin-frontend-vue/src/pages/jd/JdProductCard.vue new file mode 100644 index 000000000..b3181c659 --- /dev/null +++ b/admin-frontend-vue/src/pages/jd/JdProductCard.vue @@ -0,0 +1,204 @@ + + + + + diff --git a/admin-frontend-vue/tests/mount/jd-product-card.mount.test.ts b/admin-frontend-vue/tests/mount/jd-product-card.mount.test.ts new file mode 100644 index 000000000..3b25ac838 --- /dev/null +++ b/admin-frontend-vue/tests/mount/jd-product-card.mount.test.ts @@ -0,0 +1,114 @@ +/** + * 京东商品卡片(JdProductCard,v1.6 蓝图 Phase 3)的挂载契约。 + * + * 纯展示组件(零 api 依赖):字段渲染与现表格「商品信息」列同源(价格走 jdPriceRange、 + * 日期走 formatDateTime);卡片点击=开详情,勾选/复制 @click.stop 防冒泡——这两处 + * 防冒泡是行为红线(点了复制却弹详情=误开弹窗),逐一钉死。 + * + * 跑法:`npx vitest run tests/mount/jd-product-card.mount.test.ts` + */ +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils' + +import JdProductCard from '@/pages/jd/JdProductCard.vue' +import type { JdProductItem } from '@/pages/jd/jd-product-model.ts' + +/** 行夹具:价格用 number 形状(2026-11-16 实录:BigDecimal 序列化成 JSON number, + * 字符串夹具会藏住「解析层丢数字形状」的真红);字段与页面 mount 测试同源。 */ +function item(over: Partial = {}): JdProductItem { + return { + id: 1, + shopId: 3, + shopName: '旗舰自营店', + productCode: 'JD-10086', + skuId: 'SKU-1', + itemNum: 'ITEM-1', + skuCount: 12, + healthScore: 81, + title: '304不锈钢保温杯大容量便携', + brand: '锅宝', + categoryPath: '家居 > 厨具 > 保温杯', + priceMin: '12.90', + priceMax: '15.90', + stockTotal: 500, + saleStatus: '上架中', + listTab: 'search', + jdCreatedAt: '2026-11-07 18:49:47', + jdOnlineAt: '2026-11-12 15:03:37', + jdUpdatedAt: '2026-11-13 14:06:07', + mainImageUrl: 'https://img.example/main-1.jpg', + attrCount: 6, + imageCount: 9, + groupId: 7, + groupName: '甲组', + syncedAt: '2026-11-12 09:00:00', + ...over, + } as JdProductItem +} + +describe('卡片字段渲染(与现表格「商品信息」列同源)', () => { + it('主图/店铺徽标/标题/价格区间/商品编码/采集日期逐字段上卡', () => { + const wrapper = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } }) + const img = wrapper.get('img.jd-card-thumb') + expect(img.attributes('src')).toBe('https://img.example/main-1.jpg') + expect(wrapper.get('.jd-card-shop').text()).toBe('旗舰自营店') + expect(wrapper.get('.jd-card-title').text()).toBe('304不锈钢保温杯大容量便携') + expect(wrapper.get('.jd-card-price').text()).toBe('12.9 ~ 15.9', '价格走 jdPriceRange(number/字符串都收、去尾零)') + expect(wrapper.get('.jd-card-code').text()).toContain('JD-10086') + expect(wrapper.get('.jd-card-date').text()).toContain('2026-11-12 09:00:00', '采集日期走 formatDateTime') + expect(wrapper.get('.jd-card-health').text()).toBe('信息分 81', 'healthScore 徽标随图渲染') + wrapper.unmount() + }) + + it('无图占位:缺 mainImageUrl 出「无图」占位不出 img 元素;缺价与缺码按占位符兜底', () => { + const wrapper = mount(JdProductCard, { + props: { item: item({ mainImageUrl: '', priceMin: '', priceMax: '', productCode: '', syncedAt: '', healthScore: null }) }, + }) + expect(wrapper.find('img.jd-card-thumb').exists()).toBe(false) + expect(wrapper.get('.jd-card-thumb-empty').text()).toBe('无图') + expect(wrapper.get('.jd-card-price').text()).toBe('-') + expect(wrapper.get('.jd-card-code').text()).toContain('-') + expect(wrapper.get('.jd-card-date').text()).toContain('—', 'formatDateTime 空值回 em dash 兜底') + expect(wrapper.find('.jd-card-copy').exists()).toBe(false, '缺编码不渲染复制按钮(现表格同形)') + expect(wrapper.find('.jd-card-health').exists()).toBe(false, 'healthScore null 不渲染徽标') + wrapper.unmount() + }) +}) + +describe('交互事件(防冒泡是行为红线)', () => { + it('点卡片整体 emit open(详情入口);点复制按钮只 emit copy 不冒泡开详情', async () => { + const wrapper = mount(JdProductCard, { props: { item: item() } }) + await wrapper.get('.jd-card').trigger('click') + expect(wrapper.emitted('open')).toHaveLength(1) + + await wrapper.get('.jd-card-copy').trigger('click') + expect(wrapper.emitted('copy')).toHaveLength(1, '复制按钮 emit copy(页面走剪贴板与回执)') + expect(wrapper.emitted('open')?.length).toBe(1, '@click.stop 防冒泡:复制不得误开详情') + wrapper.unmount() + }) + + it('可勾选档渲染勾选框:change emit toggle-select;点击勾选区不冒泡开详情', async () => { + const wrapper = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } }) + const box = wrapper.get('input[type="checkbox"]') + await box.setValue(true) + expect(wrapper.emitted('toggle-select')).toEqual([[true]]) + await box.setValue(false) + expect(wrapper.emitted('toggle-select')?.at(-1)).toEqual([false]) + // 勾选区(label @click.stop)点击不触发卡片 open。 + await wrapper.get('.jd-card-check').trigger('click') + expect(wrapper.emitted('open')).toBeFalsy() + wrapper.unmount() + }) + + it('不可勾选档不渲染勾选框(普通账号/纯只读行集);selected 高亮类由外部选中态控制', () => { + const plain = mount(JdProductCard, { props: { item: item() } }) + expect(plain.find('input[type="checkbox"]').exists()).toBe(false) + expect(plain.get('.jd-card').classes()).not.toContain('selected') + plain.unmount() + + const picked = mount(JdProductCard, { props: { item: item(), selected: true, selectable: true } }) + expect(picked.get('.jd-card').classes()).toContain('selected') + expect(picked.get('input[type="checkbox"]').element.checked).toBe(true) + picked.unmount() + }) +})