feat(phase-2): 京东数据库侧栏组件——商品目录树计数徽标/树外兜底+店铺分类双 Tab(additive,页面 Phase 5 接线)

This commit is contained in:
2026-11-21 03:56:11 +08:00
parent 380792aa82
commit 3702c83c60
2 changed files with 683 additions and 0 deletions
@@ -0,0 +1,450 @@
<script setup lang="ts">
/** 京东数据库页左侧栏(v1.6 蓝图 Phase 2,additive——页面接线随 Phase 5):
* 双 Tab=商品目录(京麦授权类目真树+计数徽标+展开折叠+树外兜底组)/
* 店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
*
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换、树展开/折叠与新建输入框。
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
* 「点节点 → 子树展开 IN 过滤」的命中集合同源),树上对不上的历史行归「树外兜底」组
* (点兜底行=单名等值旧形状,path 空数组交给页面回落)。 */
import { computed, ref, watch } from 'vue'
import {
jdCategoryCountTree,
type JdCategoryCountedNode,
} from './jd-category-tree.ts'
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
const props = defineProps<{
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
categoryOptions: JdProductCategoryOption[]
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标)。 */
categories: JdProductGroup[]
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行;
* 「分类管理」入口对所有人渲染(同组普通号只读可看,V203,写控件由对话框分档)。 */
editable: boolean
/** 当前类目选中(name+完整名称路径;树外历史名 path 为空数组;null=全部商品)。 */
selectedCategory?: { name: string; path: string[] } | null
/** 当前分类选中 id(null=全部分类)。 */
selectedGroupId?: number | null
}>()
const emit = defineEmits<{
/** 选类目:树内节点带完整路径(页面按子树展开类目名集合 IN 下发);树外兜底名
* path=[](序列化回落单名等值);null=「全部商品」清选重查。 */
(event: 'select-category', value: { name: string; path: string[] } | null): void
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
(event: 'select-group', id: number | null): void
/** 新建分类(可写档):页面调 createJdProductGroup 落当前分组,成功后刷新,
* 侧栏数据随 props 流回(本组件不感知成功/失败,输入框提交即清)。 */
(event: 'create-category', name: string): void
/** 打开分类管理对话框(建/改名/删+搜索,V204 并入的既有组件)。 */
(event: 'manage-categories'): void
}>()
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
const activeTab = ref<'catalog' | 'custom'>('catalog')
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
const totalCount = computed(() =>
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
/** 展开态:按路径串('/' 连接)记,含树外兜底组头。一级默认展开(二级可见)。 */
const expanded = ref<Set<string>>(new Set())
const expandKey = (path: string[]): string => path.join('/')
// 一级默认展开:init 时把每个一级的 key 放进集合。
for (const root of counted.value.roots) expanded.value.add(expandKey([root.name]))
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
interface FlatNode {
node: JdCategoryCountedNode
path: string[]
depth: number
}
const flatTree = computed<FlatNode[]>(() => {
const out: FlatNode[] = []
const walk = (nodes: JdCategoryCountedNode[], depth: number, prefix: string[]): void => {
for (const node of nodes) {
const path = [...prefix, node.name]
out.push({ node, path, depth })
if (node.children.length && expanded.value.has(expandKey(path))) {
walk(node.children, depth + 1, path)
}
}
}
walk(counted.value.roots, 0, [])
return out
})
function toggleExpand(path: string[]): void {
const key = expandKey(path)
const next = new Set(expanded.value)
if (next.has(key)) next.delete(key)
else next.add(key)
expanded.value = next
}
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
function pickNode(node: FlatNode): void {
if (node.node.children.length && !expanded.value.has(expandKey(node.path))) {
toggleExpand(node.path)
}
emit('select-category', { name: node.node.name, path: node.path })
}
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见。
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
watch(
() => props.selectedCategory,
(selected) => {
if (!selected || !selected.path.length) return
const next = new Set(expanded.value)
for (let i = 1; i < selected.path.length; i++) {
next.add(expandKey(selected.path.slice(0, i)))
}
expanded.value = next
},
{ immediate: true },
)
const isSelectedNode = (node: FlatNode): boolean => {
const selected = props.selectedCategory
if (!selected || selected.path.length !== node.path.length) return false
return selected.path.every((name, index) => name === node.path[index])
}
// ---------------- 树外兜底组(树上对不上的历史行,单名等值出口) ----------------
const extraOpen = ref(true)
function pickExtra(name: string): void {
// 树外名不进树:path 空数组=页面按「无路径」序列化(单名等值旧形状,不静默丢筛选)。
emit('select-category', { name, path: [] })
}
const isSelectedExtra = (name: string): boolean => {
const selected = props.selectedCategory
return !!selected && selected.path.length === 0 && selected.name === name
}
// ---------------- 店铺分类 Tab(当前分组分类平铺) ----------------
function pickGroup(group: JdProductGroup): void {
// 再点已选中的=清选(回全部分类),与旧「全部分类」下拉行的语义等价。
emit('select-group', props.selectedGroupId === group.id ? null : group.id)
}
const newCategoryName = ref('')
function submitCreate(): void {
const name = newCategoryName.value.trim()
if (!name) return
emit('create-category', name)
newCategoryName.value = ''
}
</script>
<template>
<aside class="jd-sidebar" aria-label="商品目录与店铺分类">
<div class="jd-sidebar-tabs" role="tablist">
<button
type="button"
role="tab"
:aria-selected="activeTab === 'catalog'"
class="jd-sidebar-tab"
:class="{ active: activeTab === 'catalog' }"
@click="activeTab = 'catalog'"
>商品目录</button>
<button
type="button"
role="tab"
:aria-selected="activeTab === 'custom'"
class="jd-sidebar-tab"
:class="{ active: activeTab === 'custom' }"
@click="activeTab = 'custom'"
>店铺分类</button>
</div>
<!-- 商品目录:全部商品 + 京麦授权类目树(计数徽标)+ 树外兜底组 -->
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
<button
type="button"
class="jd-side-row jd-side-all"
:class="{ selected: !selectedCategory }"
@click="emit('select-category', null)"
>
<span class="jd-side-name">全部商品</span>
<span class="jd-side-count">{{ totalCount }}</span>
</button>
<div class="jd-side-tree">
<button
v-for="flat in flatTree"
:key="flat.path.join('/')"
type="button"
class="jd-side-row"
:class="[`depth-${flat.depth}`, { selected: isSelectedNode(flat) }]"
:title="flat.path.join(' / ')"
@click="pickNode(flat)"
>
<span
v-if="flat.node.children.length"
class="jd-side-arrow"
:class="{ open: expanded.has(flat.path.join('/')) }"
role="button"
:aria-label="`展开或收起 ${flat.node.name}`"
@click.stop="toggleExpand(flat.path)"
>▸</span>
<span v-else class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ flat.node.name }}</span>
<span class="jd-side-count">{{ flat.node.count }}</span>
</button>
</div>
<div v-if="counted.extra.length" class="jd-side-extra">
<button
type="button"
class="jd-side-row jd-side-extra-head"
:aria-expanded="extraOpen"
@click="extraOpen = !extraOpen"
>
<span class="jd-side-name">树外兜底</span>
<span class="jd-side-count">{{ counted.extraTotal }}</span>
</button>
<template v-if="extraOpen">
<button
v-for="row in counted.extra"
:key="row.name"
type="button"
class="jd-side-row depth-1"
:class="{ selected: isSelectedExtra(row.name) }"
:title="row.name"
@click="pickExtra(row.name)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ row.name }}</span>
<span class="jd-side-count">{{ row.productCount }}</span>
</button>
</template>
</div>
</div>
<!-- 店铺分类:当前分组分类平铺 + 新建分类(可写档)+ 分类管理入口(所有人) -->
<div v-show="activeTab === 'custom'" class="jd-sidebar-body jd-side-custom">
<template v-if="categories.length">
<button
v-for="cat in categories"
:key="cat.id"
type="button"
class="jd-side-row"
:class="{ selected: selectedGroupId === cat.id }"
:title="cat.name"
@click="pickGroup(cat)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ cat.name }}</span>
<span class="jd-side-count">{{ cat.productCount }}</span>
</button>
</template>
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
<div v-if="editable" class="jd-side-create">
<input
v-model="newCategoryName"
type="text"
placeholder="新分类名称"
aria-label="新分类名称"
@keyup.enter="submitCreate"
/>
<button type="button" :disabled="!newCategoryName.trim()" @click="submitCreate">新建分类</button>
</div>
<button type="button" class="jd-side-manage" @click="emit('manage-categories')">分类管理</button>
</div>
</aside>
</template>
<style scoped>
.jd-sidebar {
width: 232px;
flex-shrink: 0;
background: #fff;
border: 1px solid #e4e7ed;
border-radius: 8px;
overflow: hidden;
align-self: flex-start;
}
.jd-sidebar-tabs {
display: flex;
border-bottom: 1px solid #e4e7ed;
}
.jd-sidebar-tab {
flex: 1;
padding: 10px 0;
border: none;
background: transparent;
cursor: pointer;
font-size: 14px;
color: #606266;
}
.jd-sidebar-tab.active {
color: #409eff;
font-weight: 600;
box-shadow: inset 0 -2px 0 #409eff;
}
.jd-sidebar-body {
display: flex;
flex-direction: column;
max-height: 640px;
overflow-y: auto;
padding: 6px;
}
.jd-side-row {
display: flex;
align-items: center;
gap: 6px;
width: 100%;
padding: 6px 8px;
border: none;
background: transparent;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
color: #303133;
text-align: left;
}
.jd-side-row:hover {
background: #f5f7fa;
}
.jd-side-row.selected {
background: #ecf5ff;
color: #409eff;
font-weight: 600;
}
.jd-side-row.depth-1 { padding-left: 22px; }
.jd-side-row.depth-2 { padding-left: 36px; }
.jd-side-row.depth-3 { padding-left: 50px; }
.jd-side-arrow {
width: 14px;
flex-shrink: 0;
color: #909399;
transition: transform 0.15s;
cursor: pointer;
}
.jd-side-arrow.open {
transform: rotate(90deg);
}
.jd-side-leaf-dot {
width: 14px;
flex-shrink: 0;
text-align: center;
color: #c0c4cc;
}
.jd-side-leaf-dot::before {
content: '·';
}
.jd-side-name {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-side-count {
flex-shrink: 0;
min-width: 24px;
text-align: right;
font-size: 12px;
color: #909399;
background: #f0f2f5;
border-radius: 10px;
padding: 1px 7px;
}
.jd-side-row.selected .jd-side-count {
color: #409eff;
background: #d9ecff;
}
.jd-side-extra {
margin-top: 4px;
border-top: 1px dashed #e4e7ed;
padding-top: 4px;
}
.jd-side-extra-head {
color: #909399;
}
.jd-side-empty {
margin: 8px 4px;
font-size: 13px;
color: #909399;
text-align: center;
}
.jd-side-create {
display: flex;
gap: 6px;
margin-top: 8px;
padding: 6px 4px;
border-top: 1px dashed #e4e7ed;
}
.jd-side-create input {
flex: 1;
min-width: 0;
padding: 5px 8px;
border: 1px solid #dcdfe6;
border-radius: 6px;
font-size: 13px;
}
.jd-side-create button {
padding: 5px 10px;
border: 1px solid #dcdfe6;
border-radius: 6px;
background: #fff;
cursor: pointer;
font-size: 13px;
color: #409eff;
}
.jd-side-create button:disabled {
color: #c0c4cc;
cursor: not-allowed;
}
.jd-side-manage {
margin-top: 8px;
padding: 6px 8px;
border: none;
border-top: 1px dashed #e4e7ed;
background: transparent;
color: #606266;
font-size: 13px;
cursor: pointer;
text-align: left;
}
.jd-side-manage:hover {
color: #409eff;
}
</style>
@@ -0,0 +1,233 @@
/**
* 京东数据库侧栏(JdCategorySidebar,v1.6 蓝图 Phase 2)的挂载契约。
*
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本文件零 api mock——
* 钉的是「徽标数=点节点后列表命中的行数」(jdCategoryCountTree 同源)、双 Tab 切换、
* 点节点 emit 形状(树内带路径/树外兜底 path 空/全部商品 null)、可写档分档入口。
*
* 跑法:`npx vitest run tests/mount/jd-category-sidebar.mount.test.ts`
*/
import { beforeEach, describe, expect, it } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import JdCategorySidebar from '@/pages/jd/JdCategorySidebar.vue'
import type { JdProductCategoryOption, JdProductGroup } from '@/pages/jd/jd-product-api.ts'
/** 类目计数夹具:树内名(连衣裙支+同名跨支短裤)+树外历史名,读数与 Phase 1
* 纯函数测试同源——服饰内衣根徽标 20(子树去重)、全部商品 37、兜底 12。 */
const CATEGORY_OPTIONS: JdProductCategoryOption[] = [
{ name: '连衣裙', productCount: 7 },
{ name: '短袖连衣裙', productCount: 4 },
{ name: '艺考形体服', productCount: 5 },
{ name: '短裤', productCount: 9 },
{ name: '已下架历史类目', productCount: 12 },
]
const CATEGORIES: JdProductGroup[] = [
{ id: 7, name: '裙装', ownerGroupId: 11, sortOrder: 0, productCount: 3 },
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
]
interface MountOptions {
editable?: boolean
selectedCategory?: { name: string; path: string[] } | null
selectedGroupId?: number | null
}
function mountSidebar(options: MountOptions = {}): VueWrapper<Element> {
return mount(JdCategorySidebar, {
props: {
categoryOptions: CATEGORY_OPTIONS,
categories: CATEGORIES,
editable: options.editable ?? true,
selectedCategory: options.selectedCategory ?? null,
selectedGroupId: options.selectedGroupId ?? null,
},
})
}
/** 在指定 Tab 体内按文案找行(两个 Tab 体 v-show 共存于 DOM,必须先圈定范围)。 */
function rowByText(scope: VueWrapper<Element>, text: string) {
const row = scope.findAll('.jd-side-row').find((node) => node.text().includes(text))
expect(row, `应存在文案含「${text}」的侧栏行`).toBeTruthy()
return row!
}
beforeEach(() => {
// 纯展示组件无副作用;占位保持与页面 mount 测试同构。
})
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
it('出厂停在商品目录 Tab;徽标与 Phase 1 聚合同源(根=子树去重和、全部商品=计数行总和)', () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const all = catalog.get('.jd-side-all')
expect(all.text()).toContain('全部商品')
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
expect(rowByText(catalog, '服饰内衣').text()).toContain('20',
'服饰内衣根徽标=子树去重和(连衣裙7+短袖4+短裤9,短裤跨支同名只记一次)')
expect(rowByText(catalog, '母婴').text()).toContain('0', '无词条一级归 0 不缺节点')
expect(rowByText(catalog, '运动户外').text()).toContain('5')
wrapper.unmount()
})
it('一级默认展开(二级首屏可见);逐级展开后末级行点行 emit {name, path}', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const women = rowByText(catalog, '女装')
expect(women.classes()).toContain('depth-1', '一级默认展开 ⇒ 二级行(depth-1 缩进)首屏可见')
// 末级艺考形体服在 depth-2:其父(舞蹈体操鞋服/装备)未展开时不可见。
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(false)
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
await flushPromises()
const yikao = rowByText(catalog, '艺考形体服')
expect(yikao.classes()).toContain('depth-2', '艺考形体服是 level 3(depth 2 缩进)')
await yikao.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '艺考形体服', path: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'] }]])
wrapper.unmount()
})
it('点二级节点 emit 完整路径(页面按子树展开 IN);箭头只折展不选中', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
// 女装行未展开时,其子行(连衣裙)不可见。
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false)
const women = rowByText(catalog, '女装')
await women.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '女装', path: ['服饰内衣', '女装'] }]],
'点行=选中即筛,emit 完整名称路径')
// 点行顺手展开(下钻感):子行现在可见。
expect(wrapper.emitted('select-category')).toHaveLength(1)
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(true,
'非末级行点行后展开子级')
// 箭头(role=button, aria-label)只折展:点它不得触发 select-category。
const before = wrapper.emitted('select-category')?.length ?? 0
await catalog.get('[aria-label="展开或收起 女装"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')?.length).toBe(before, '箭头点击不选中(click.stop 防冒泡)')
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false,
'再点箭头=收起(子行隐藏)')
wrapper.unmount()
})
it('「全部商品」行 emit null(页面清类目筛选重查);挂载即带选中态时祖先自动展开并高亮', async () => {
const wrapper = mountSidebar({ selectedCategory: { name: '连衣裙', path: ['服饰内衣', '女装', '连衣裙'] } })
const catalog = wrapper.get('.jd-side-catalog')
const dress = rowByText(catalog, '连衣裙')
expect(dress.classes()).toContain('selected', '外部选中态回显高亮')
expect(dress.classes()).toContain('depth-2', '挂载即带选中 ⇒ watch immediate 展开祖先(女装已展开,行可见)')
await wrapper.setProps({ selectedCategory: null })
expect(catalog.get('.jd-side-all').classes()).toContain('selected', 'null=全部商品高亮')
await catalog.get('.jd-side-all').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
wrapper.unmount()
})
})
describe('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
it('兜底组头渲染计数和=extraTotal;行点击 emit {name, path:[]}(页面按单名等值回落)', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const head = catalog.get('.jd-side-extra-head')
expect(head.text()).toContain('树外兜底')
expect(head.text()).toContain('12', '兜底组头徽标=extraTotal(历史行求和)')
const extra = rowByText(catalog, '已下架历史类目')
await extra.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '已下架历史类目', path: [] }]],
'树外名 path 空数组=无路径序列化(单名等值旧形状,不静默丢筛选)')
wrapper.unmount()
})
it('全部是树内名时兜底组整体不渲染(不占一条空组)', () => {
const wrapper = mount(JdCategorySidebar, {
props: {
categoryOptions: [{ name: '连衣裙', productCount: 7 }],
categories: CATEGORIES,
editable: true,
selectedCategory: null,
selectedGroupId: null,
},
})
expect(wrapper.find('.jd-side-extra').exists()).toBe(false)
wrapper.unmount()
})
})
describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () => {
it('点店铺分类切 Tab;分类行带计数;点行 emit id、再点已选中的 emit null(toggle 清选)', async () => {
const wrapper = mountSidebar()
const tabs = wrapper.findAll('.jd-sidebar-tab')
expect(tabs.map((tab) => tab.text())).toEqual(['商品目录', '店铺分类'])
await tabs[1]!.trigger('click')
await flushPromises()
expect(tabs[1]!.classes()).toContain('active')
const custom = wrapper.get('.jd-side-custom')
const skirt = rowByText(custom, '裙装')
expect(skirt.text()).toContain('3', '分类行计数徽标')
await skirt.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')).toEqual([[7]])
await wrapper.setProps({ selectedGroupId: 7 })
expect(rowByText(custom, '裙装').classes()).toContain('selected', '选中态回显')
await rowByText(custom, '裙装').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')?.at(-1)).toEqual([null], '再点已选中=清选回全部分类')
wrapper.unmount()
})
it('可写档出「新建分类」行:emit 分类名并清输入,空名按钮置灰;只读档不渲染该行', async () => {
const editable = mountSidebar({ editable: true })
const custom = editable.get('.jd-side-custom')
const input = custom.get('[aria-label="新分类名称"]')
const createBtn = custom.findAll('button').find((b) => b.text() === '新建分类')!
expect(createBtn.attributes('disabled')).toBeDefined()
await input.setValue('上新区')
await createBtn.trigger('click')
await flushPromises()
expect(editable.emitted('create-category')).toEqual([['上新区']],
'侧栏只 emit,建分类的 API 调用与刷新在页面(Phase 5 接线)')
expect((input.element as HTMLInputElement).value).toBe('', '提交即清输入')
await input.setValue(' ')
expect(createBtn.attributes('disabled')).toBeDefined(), '纯空白名按钮置灰'
editable.unmount()
const readonly = mountSidebar({ editable: false })
expect(readonly.get('.jd-side-custom').find('[aria-label="新分类名称"]').exists()).toBe(false,
'只读档不渲染新建行')
readonly.unmount()
})
it('「分类管理」入口对所有人渲染(同组普通号只读可看 V203),点击 emit manage-categories', async () => {
for (const editable of [true, false]) {
const wrapper = mountSidebar({ editable })
const manage = wrapper.get('.jd-side-custom').get('.jd-side-manage')
expect(manage.text()).toBe('分类管理')
await manage.trigger('click')
await flushPromises()
expect(wrapper.emitted('manage-categories')).toHaveLength(1)
wrapper.unmount()
}
})
it('空分类空态文案分档:可写档引导新建,只读档直说', () => {
const writable = mount(JdCategorySidebar, {
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
})
expect(writable.get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
writable.unmount()
const readonly = mount(JdCategorySidebar, {
props: { categoryOptions: [], categories: [], editable: false, selectedCategory: null, selectedGroupId: null },
})
expect(readonly.get('.jd-side-empty').text()).toBe('本组暂无分类')
readonly.unmount()
})
})