刘光辉
9 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, expect, it } from 'vitest';
 
import { annotationAlias, annotationFields, annotationPlaceholder, annotationTag, displayFieldLabel, formAnnotationAlias, formAnnotationTag, stepKey, type WorkflowStep } from '../../src/domain/annotation';
 
const start: WorkflowStep = {
  key: 'start', label: '提交申请', role: 'START',
};
 
describe('签批页标注字段目录', () => {
  it('为发起和审核节点提供各自字段', () => {
    expect(annotationFields(start).map((item) => item.key)).toEqual([
      'applicant', 'applicantDepartment', 'applicantTime', 'stepName',
    ]);
    expect(annotationFields({ ...start, role: 'APPROVE' }).map((item) => item.key)).toEqual([
      'approver', 'approverDepartment', 'approveTime', 'stepName',
    ]);
  });
 
  it('生成稳定的内容控件标识,并显示中文占位文本', () => {
    const field = annotationFields(start)[0]!;
    const tag = annotationTag(start, field);
    expect(stepKey(start)).toBe('start');
    expect(tag).toBe('dms.qianpiye.flow.start.applicant');
    expect(annotationAlias(start, field)).toBe('提交申请-发起人');
    expect(annotationPlaceholder(annotationAlias(start, field))).toBe('{{提交申请-发起人}}');
  });
 
  it('为两个流程共有的表单字段生成独立标签', () => {
    const field = { key: 'recordDetails.recordType', label: '记录明细-记录类型' };
    expect(formAnnotationTag(field)).toBe('dms.qianpiye.form.recordDetails.recordType');
    expect(formAnnotationAlias(field)).toBe('记录明细-记录类型');
  });
 
  it('仅清理显示名称中的 H,不改变字段标签', () => {
    const field = { key: 'hCode', label: 'H文件编号' };
    expect(formAnnotationTag(field)).toBe('dms.qianpiye.form.hCode');
    expect(formAnnotationAlias(field)).toBe('文件编号');
  });
 
  it('插入表单字段时用空格连接中英文名称,不改变按钮名称和标签', () => {
    for (const label of ['文件编号\\nDocument Number ', '文件编号\nDocument Number ', '文件编号\r\nDocument Number ', '文件编号\rDocument Number ']) {
      const field = { key: 'name', label };
      expect(formAnnotationAlias(field)).toBe('文件编号 Document Number ');
      expect(annotationPlaceholder(formAnnotationAlias(field))).toBe('{{文件编号 Document Number }}');
      expect(displayFieldLabel(label)).toBe(label);
      expect(formAnnotationTag(field)).toBe('dms.qianpiye.form.name');
      expect(field.label).toBe(label);
    }
  });
});