|
|
@@ -0,0 +1,219 @@
|
|
|
+import { readFileSync } from 'fs'
|
|
|
+import { resolve } from 'path'
|
|
|
+import { shallowMount, createLocalVue } from '@vue/test-utils'
|
|
|
+import FamilyWorkbench from '@/views/FamilyWorkbench.vue'
|
|
|
+import { getFamilyWorkbench } from '@/api/familyWorkbench'
|
|
|
+
|
|
|
+// 契约键:admin.family.workbenchRedesign(TDD RED 阶段,实现未落地)
|
|
|
+// 溯源·需求:docs/design/2026-11-27-family-workbench-redesign-v2.md
|
|
|
+// §1 方向声明(方向 A · 左竖向导航工作台)、§7 IA 与需求溯源(新增管理能力 + 信息架构重组)
|
|
|
+// 溯源·设计:同文档 §10 手术清单(删 8 张大卡 / 列表抽屉分发,新增 .wb-shell/.wb-kpi/.wb-nav/.wb-panel、
|
|
|
+// activeModule 取代 activeTab、keep-alive 包裹 11 模块);§2-§6 色彩/字阶/间距/六态契约;
|
|
|
+// cfc-web/src/styles/family-workbench.tokens.css(令牌层已交付,组件消费未落地)
|
|
|
+// 风格参照:cfc-web/src/views/admin/review/__tests__/ActivityAudit.spec.js
|
|
|
+// (@vue/test-utils shallowMount + ElementUI stubs + jest.mock API,纯组件级无后端依赖)
|
|
|
+// 说明:本套件断言的是「设计已定稿、实现尚未落地」的行为,当前预期全红;GREEN 阶段实现后转绿。
|
|
|
+
|
|
|
+jest.mock('@/api/familyWorkbench', () => ({
|
|
|
+ getFamilyWorkbench: jest.fn(() => Promise.resolve({ data: {} })),
|
|
|
+ getFamilyMessages: jest.fn(() => Promise.resolve({ data: { records: [], total: 0 } })),
|
|
|
+ getConversationMessages: jest.fn(() => Promise.resolve({ data: { records: [] } })),
|
|
|
+ createFamilyTask: jest.fn(() => Promise.resolve({ code: 200 })),
|
|
|
+ updateFamilyTask: jest.fn(() => Promise.resolve({ code: 200 })),
|
|
|
+ createFamilyPlan: jest.fn(() => Promise.resolve({ code: 200 })),
|
|
|
+ updateFamilyPlan: jest.fn(() => Promise.resolve({ code: 200 })),
|
|
|
+ getFamilyCfLogs: jest.fn(() => Promise.resolve({ data: { records: [], total: 0 } }))
|
|
|
+}))
|
|
|
+jest.mock('@/api/admin', () => ({
|
|
|
+ getFamilyTasks: jest.fn(() => Promise.resolve({ data: { records: [], total: 0 } })),
|
|
|
+ getFamilyOverview: jest.fn(() => Promise.resolve({ data: {} })),
|
|
|
+ getFamilyMemberList: jest.fn(() => Promise.resolve({ data: [] })),
|
|
|
+ proxyParseReport: jest.fn(() => Promise.resolve({ code: 200, data: null })),
|
|
|
+ proxyConfirmReport: jest.fn(() => Promise.resolve({ code: 200 }))
|
|
|
+}))
|
|
|
+jest.mock('@/api/coupon', () => ({
|
|
|
+ getCouponList: jest.fn(),
|
|
|
+ issueFamilyCoupon: jest.fn(),
|
|
|
+ getFamilyCoupons: jest.fn(),
|
|
|
+ getFamilyCouponUsage: jest.fn()
|
|
|
+}))
|
|
|
+jest.mock('echarts', () => ({
|
|
|
+ init: jest.fn(() => ({ setOption: jest.fn(), dispose: jest.fn(), resize: jest.fn() }))
|
|
|
+}))
|
|
|
+
|
|
|
+const localVue = createLocalVue()
|
|
|
+localVue.directive('loading', {})
|
|
|
+
|
|
|
+const stubs = [
|
|
|
+ 'el-row', 'el-col', 'el-button', 'el-input', 'el-tag', 'el-form', 'el-form-item',
|
|
|
+ 'el-select', 'el-option', 'el-table', 'el-table-column', 'el-pagination',
|
|
|
+ 'el-card', 'el-upload', 'el-descriptions', 'el-descriptions-item', 'el-empty',
|
|
|
+ 'el-tabs', 'el-tab-pane', 'el-dialog', 'el-drawer'
|
|
|
+]
|
|
|
+
|
|
|
+const mockCards = [
|
|
|
+ { key: 'reports', label: '报告', total: 12, series: [] },
|
|
|
+ { key: 'plans', label: '方案', total: 3, series: [] },
|
|
|
+ { key: 'tasks', label: '任务', total: 28, series: [] },
|
|
|
+ { key: 'cf', label: 'CF值', total: 1280, series: [] },
|
|
|
+ { key: 'messages', label: '消息', total: 5, series: [] },
|
|
|
+ { key: 'coupons', label: '优惠券', total: 6, series: [] }
|
|
|
+]
|
|
|
+
|
|
|
+function mountPage() {
|
|
|
+ return shallowMount(FamilyWorkbench, {
|
|
|
+ localVue,
|
|
|
+ stubs,
|
|
|
+ mocks: {
|
|
|
+ $route: { params: { id: '5' } },
|
|
|
+ $router: { push: jest.fn() },
|
|
|
+ $message: { error: jest.fn(), success: jest.fn(), warning: jest.fn() }
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+async function flush(wrapper) {
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+}
|
|
|
+
|
|
|
+describe('admin.family.workbenchRedesign 契约(TDD RED:实现未落地)', () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ jest.clearAllMocks()
|
|
|
+ getFamilyWorkbench.mockResolvedValue({
|
|
|
+ data: { family: { id: 5, name: '测试家庭', inviteCode: 'T5' }, cards: mockCards }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('§1 / §10 单一导航轴与骨架重组', () => {
|
|
|
+ it('渲染 .wb-shell 骨架(页头 + KPI 条 + 左导航 + 右内容区)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.find('.wb-shell').exists()).toBe(true)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('删除 8 张大统计卡与 statsCollapsed/stats-toggle 收起开关', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.findAll('.wb-card').length).toBe(0)
|
|
|
+ expect(wrapper.find('.stats-toggle').exists()).toBe(false)
|
|
|
+ expect(wrapper.vm.statsCollapsed).toBeUndefined()
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('activeModule 取代 activeTab 成为唯一导航状态源,默认选中首模块', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.vm.activeTab).toBeUndefined()
|
|
|
+ expect(wrapper.vm.activeModule).toBe('children')
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('左竖导航渲染 11 个模块入口(§7.1),不再用 el-tabs 双导航', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.findAll('.wb-nav-item').length).toBe(11)
|
|
|
+ expect(wrapper.find('.wb-tabs').exists()).toBe(false)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('KPI 点击 = 切换导航选中项,不再打开列表抽屉(§10 删除 5 个列表抽屉)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ wrapper.vm.openModule('tasks')
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+ expect(wrapper.vm.activeModule).toBe('tasks')
|
|
|
+ expect(wrapper.vm.taskDrawerVisible).toBeUndefined()
|
|
|
+ expect(wrapper.vm.cfDrawerVisible).toBeUndefined()
|
|
|
+ expect(wrapper.vm.messageDrawerVisible).toBeUndefined()
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('右内容区用 keep-alive 包裹模块面板,保留各模块翻页/筛选态(§7.4 L2)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.find('.wb-panel').exists()).toBe(true)
|
|
|
+ expect(wrapper.find('keep-alive').exists()).toBe(true)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('§6.1 KPI 条六态(52px 纯数字)', () => {
|
|
|
+ it('KPI 条渲染 6 项纯数字(label + value),不再渲染卡片内图表', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.findAll('.wb-kpi-item').length).toBe(6)
|
|
|
+ expect(wrapper.find('.wb-kpi-chart').exists()).toBe(false)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('空数据 KPI 显示 "-" 且不可点击', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ wrapper.vm.cards = [{ key: 'reports', label: '报告', total: null, series: [] }]
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+ const item = wrapper.find('.wb-kpi-item')
|
|
|
+ expect(item.exists()).toBe(true)
|
|
|
+ expect(item.text()).toContain('-')
|
|
|
+ expect(item.classes()).toContain('is-empty')
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('加载中 KPI value 位显示骨架块(76×20),label 保持不变', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ wrapper.vm.loading = true
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+ expect(wrapper.findAll('.wb-kpi-skeleton').length).toBe(6)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('待办模块渲染 6px 圆点角标(非数字红点)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ wrapper.vm.planSummary = { byStatus: { pending_review: 2 } }
|
|
|
+ wrapper.vm.taskSummary = { pending: 3 }
|
|
|
+ await wrapper.vm.$nextTick()
|
|
|
+ expect(wrapper.findAll('.wb-nav-badge').length).toBeGreaterThan(0)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('§6.3 / §6.6 模块面板与指标曲线', () => {
|
|
|
+ it('面板含 120px 曲线区,曲线数据取自 card.series(后端已下发)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.find('.wb-curve').exists()).toBe(true)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('模块切换时 dispose 旧图表实例(watch activeModule,而非仅 beforeDestroy)', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ const watch = wrapper.vm.$options.watch
|
|
|
+ expect(watch && watch.activeModule).toBeDefined()
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('§6.4 表单抽屉(仅新增/编辑,520px)', () => {
|
|
|
+ it('任务/方案表单不再用 el-dialog,改为 520px 表单抽屉', async () => {
|
|
|
+ const wrapper = mountPage()
|
|
|
+ await flush(wrapper)
|
|
|
+ expect(wrapper.findAll('el-dialog-stub').length).toBe(0)
|
|
|
+ expect(wrapper.findAll('el-drawer-stub').length).toBeGreaterThan(0)
|
|
|
+ wrapper.destroy()
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('§9 / §14 令牌接入契约', () => {
|
|
|
+ it('main.js 在 admin-tokens.css 之后引入 family-workbench.tokens.css', () => {
|
|
|
+ const main = readFileSync(resolve(__dirname, '../../../src/main.js'), 'utf8')
|
|
|
+ const adminAt = main.indexOf('admin-tokens.css')
|
|
|
+ const wbAt = main.indexOf('family-workbench.tokens.css')
|
|
|
+ expect(wbAt).toBeGreaterThan(-1)
|
|
|
+ expect(wbAt).toBeGreaterThan(adminAt)
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|