刘光辉
6 小时以前 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
import { describe, expect, it } from 'vitest';
 
import { getWatermarkContent, getWatermarkIdentity, isGlobalWatermarkEnabled } from '../watermark';
 
describe('global page watermark', () => {
  it('only enables the watermark for the numeric switch value 1', () => {
    expect(isGlobalWatermarkEnabled(1)).toBe(true);
    expect(isGlobalWatermarkEnabled('1')).toBe(true);
    expect(isGlobalWatermarkEnabled(0)).toBe(false);
    expect(isGlobalWatermarkEnabled(undefined)).toBe(false);
    expect(isGlobalWatermarkEnabled('enabled')).toBe(false);
  });
 
  it('joins available identity fields and falls back to the account', () => {
    expect(getWatermarkIdentity({ mobilePhone: '13800000000', userAccount: 'zhangsan', userName: '张三' })).toBe('张三 13800000000');
    expect(getWatermarkIdentity({ mobilePhone: '', userAccount: 'zhangsan', userName: '张三' })).toBe('张三');
    expect(getWatermarkIdentity({ mobilePhone: null, userAccount: 'zhangsan', userName: null })).toBe('zhangsan');
  });
 
  it('renders the current time on a separate line', () => {
    const content = getWatermarkContent({ mobilePhone: '13800000000', userName: '张三' }, new Date(2026, 8, 10, 14, 30, 20));
 
    expect(content).toBe('张三 13800000000\n2026-09-10 14:30:20');
  });
});