刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { describe, expect, it } from 'vitest';
 
import { formatFormLabel } from './formLabel';
 
describe('formatFormLabel', () => {
  it('converts both configured line-break markers', () => {
    expect(formatFormLabel(String.raw`部门\nDepartment<\n>名称`)).toBe('部门\nDepartment\n名称');
  });
 
  it('converts escaped newlines and br tags without interpreting other markup', () => {
    expect(formatFormLabel(String.raw`中文\\nEnglish`)).toBe('中文\nEnglish');
    expect(formatFormLabel(String.raw`中文\\\nEnglish`)).toBe('中文\nEnglish');
    expect(formatFormLabel(String.raw`中文<br>English`)).toBe('中文\nEnglish');
    expect(formatFormLabel(String.raw`中文\<BR />English`)).toBe('中文\nEnglish');
    expect(formatFormLabel(String.raw`中文<b>English</b>`)).toBe('中文<b>English</b>');
  });
 
  it('preserves actual line breaks and renders other markup as text', () => {
    expect(formatFormLabel('申请人\n<b>Applicant</b>')).toBe('申请人\n<b>Applicant</b>');
    expect(formatFormLabel(undefined)).toBe('');
  });
});