unis-oa/frontend/src/utils/nodeConfig.oaLock.spec.ts

73 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 右栏「外部审批」那一格的摘要里,OA 按钮锁定这一句怎么说。
*
* 判据本体在后端 ``service/node_approve.py``(由 ``backend/scripts/check_node_approve.py``
* 钉死)。这里只钉前端这一侧最容易出事的两件:
*
* 1. **默认那一组与后端同一份**。勾了锁但没显式写 ``actions`` 时,右栏说的颗数必须
* 跟引擎锁住的颗数一致,否则改图的人看见「已锁 4 颗」而运行时锁的是另一组;
* 2. **不锁就别占一行**。关着的环节在右栏留一句「OA 已锁 0 颗钮」是纯噪音。
*/
import { describe, expect, it } from 'vitest'
import { groupDigest } from './nodeConfig'
import type { Activity } from '@/types'
function node(config: Record<string, unknown>): Activity {
return {
id: 'a1',
process: 'p1',
type: 'manual',
name: '财务复核',
alias: '',
description: '',
x: 0,
y: 0,
form: '',
order_number: 1,
config
} as unknown as Activity
}
/** 摘要是纯文案拼装,测试里把 i18n 换成「key:参数」这种可断言的形状。 */
const ctx = {
formName: () => '',
fmt: (key: string, params?: Record<string, string | number>) =>
params ? `${key}:${Object.values(params).join(',')}` : key
}
const digest = (config: Record<string, unknown>) => groupDigest('openApprove', node(config), ctx)
describe('外部审批摘要 · OA 按钮锁定', () => {
it('没开外部审批:这一格没话可说', () => {
expect(digest({}).text).toBe('')
expect(digest({ openApprove: { oaLock: { enabled: true } } }).text).toBe('')
})
it('开着但没锁:不占那一行', () => {
expect(digest({ openApprove: { enabled: true } }).text).toBe('openApproveDigestOn')
})
it('锁了但没显式写 actions:按后端默认那一组报颗数', () => {
expect(digest({ openApprove: { enabled: true, oaLock: { enabled: true } } }).text).toBe(
'openApproveDigestOn · openApproveDigestLocked:4'
)
})
it('显式勾了哪几颗就报哪几颗,认不出的词不计数', () => {
const text = digest({
openApprove: { enabled: true, oaLock: { enabled: true, actions: ['handle', 'recall', 'nope'] } }
}).text
expect(text).toContain('openApproveDigestLocked:2')
expect(text).not.toContain('Locked:4')
})
it('锁与出口钉配各说各话:两句都在,读得出是两件事', () => {
const text = digest({
openApprove: { enabled: true, apps: ['erp'], routes: { refuse: '退回修改' }, oaLock: { enabled: true } }
}).text
expect(text).toBe(
'openApproveDigestOn · openApproveDigestApps:1 · openApproveDigestRoutes:1 · openApproveDigestLocked:4'
)
})
})