import assert from 'node:assert/strict' import test from 'node:test' import { buildAdjacentProgressSteps, buildWorkbenchSummary } from '../src/utils/workbenchSummary.js' const currentUser = { name: '张三', username: 'zhangsan' } function buildStep(label, index, currentIndex) { return { label, done: index < currentIndex, active: index <= currentIndex, current: index === currentIndex, time: index === currentIndex ? '进行中' : '待处理' } } test('workbench expense progress keeps only nearby four expense steps', () => { const steps = ['创建单据', '待提交', '直属领导审批', '财务审批', '待付款', '归档入账'] .map((label, index) => buildStep(label, index, 3)) const visibleSteps = buildAdjacentProgressSteps(steps, 4) assert.deepEqual( visibleSteps.map((step) => step.label), ['直属领导审批', '财务审批', '待付款', '归档入账'] ) assert.equal(visibleSteps[1].current, true) }) test('workbench summary builds real user notifications and progress from requests', () => { const summary = buildWorkbenchSummary( [ { id: 'BX-001', claimId: 'claim-1', claimNo: 'BX-001', person: '张三', title: '差旅报销', approvalKey: 'draft', approvalStatus: '草稿', status: 'draft', amount: 1280, createdAt: '2026-06-01T10:00:00+08:00', updatedAt: '2026-06-01T10:10:00+08:00', progressSteps: [ buildStep('创建单据', 0, 1), buildStep('待提交', 1, 1), buildStep('直属领导审批', 2, 1), buildStep('财务审批', 3, 1), buildStep('待付款', 4, 1) ] }, { id: 'BX-002', claimId: 'claim-2', claimNo: 'BX-002', person: '李四', title: '他人单据', approvalKey: 'draft', amount: 800, progressSteps: [] } ], currentUser ) assert.equal(summary.todoItems.length, 1) assert.equal(summary.todoItems[0].target.id, 'claim-1') assert.equal(summary.progressItems.length, 1) assert.deepEqual( summary.progressItems[0].steps.map((step) => step.label), ['创建单据', '待提交', '直属领导审批', '财务审批'] ) assert.equal(summary.notifications.length, 1) assert.equal(summary.unreadNotificationCount, 1) })