GuDingZiChan/frontend/scripts/test-phase-two-presentation.ts

55 lines
2.8 KiB
TypeScript

import assert from 'node:assert/strict'
import {
getDashboardRoleActions,
getDashboardRoleTitle
} from '../src/views/dashboard/dashboardRoleConfig.ts'
import {
getNotificationActionLabel,
getNotificationRecordBadge,
isNotificationAttentionRequired
} from '../src/views/notifications/notificationPresentation.ts'
import { getUserPersonOptionAvailability } from '../src/utils/userPersonOption.ts'
const administrativeActions = getDashboardRoleActions('administrative')
assert.ok(administrativeActions.some((action) => action.id === 'asset-create'), '行政首页应突出资产入库')
assert.ok(administrativeActions.some((action) => action.id === 'inventory'), '行政首页应提供盘点入口')
assert.ok(administrativeActions.some((action) => action.id === 'disposal-approval'), '行政首页应提供报废审批入口')
const itActions = getDashboardRoleActions('it')
assert.ok(itActions.some((action) => action.id === 'borrow'), 'IT 首页应提供借出入口')
assert.ok(itActions.some((action) => action.id === 'transfer'), 'IT 首页应提供调拨入口')
assert.ok(itActions.some((action) => action.id === 'maintenance'), 'IT 首页应提供维修入口')
assert.equal(getDashboardRoleTitle('admin'), '管理总览')
const availablePerson = {
id: 1,
real_name: '测试员工',
nickname: '测试',
status: 'active' as const,
dingtalk_ready: true,
is_bound: false,
bound_user: null
}
assert.equal(getUserPersonOptionAvailability(availablePerson).selectable, true, '在职且钉钉就绪的未绑定员工应可选择')
const boundToOther = {
...availablePerson,
is_bound: true,
bound_user: { id: 9, username: 'other', name: '其他账号', role: 'it', status: 'active' as const }
}
assert.equal(getUserPersonOptionAvailability(boundToOther, 10).selectable, false, '已绑定其他账号的员工不可重复选择')
assert.equal(getUserPersonOptionAvailability(boundToOther, 9).selectable, true, '编辑当前账号时应保留自己的员工绑定')
assert.equal(getUserPersonOptionAvailability({ ...availablePerson, dingtalk_ready: false }).selectable, false)
const ordinaryRecord = { level: 'info', related_sync_job_id: null, action_url: '/workflows/disposals/1' }
assert.equal(getNotificationRecordBadge(ordinaryRecord).label, '系统记录', '普通流程记录不应强调未读')
assert.equal(isNotificationAttentionRequired(ordinaryRecord), false)
assert.equal(getNotificationActionLabel(ordinaryRecord), '查看相关记录')
const errorRecord = { level: 'error', related_sync_job_id: null, action_url: '/settings' }
assert.equal(getNotificationRecordBadge(errorRecord).label, '异常待处理')
assert.equal(isNotificationAttentionRequired(errorRecord), true)
assert.equal(getNotificationActionLabel(errorRecord), '前往处理')
console.log('phase two presentation tests: ok')