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');
|
});
|
});
|