import { describe, expect, it } from 'vitest';
|
|
import {
|
filePropertyLifecycle,
|
filePropertyName,
|
filePropertyPreparer,
|
filePropertyReview,
|
filePropertyReviewers,
|
filePropertyVersion,
|
} from '../fileProperties';
|
|
describe('dMS file properties', () => {
|
it('shows stored personnel names for both current and historical versions without resolving IDs', () => {
|
const item = {
|
preparedBy: 'user-id',
|
extendedProperties: {
|
prepared_by_name: '登记时制定人',
|
reviewers: [
|
{ user_id: 'r1', name: '审核甲' },
|
{ user_id: 'r2', name: '审核乙' },
|
],
|
},
|
};
|
expect(filePropertyPreparer(item)).toBe('登记时制定人');
|
expect(filePropertyReviewers(item)).toBe('审核甲、审核乙');
|
expect(filePropertyPreparer({ preparedBy: 'user-id' })).toBe('user-id');
|
expect(filePropertyReviewers()).toBe('未记录');
|
});
|
|
it('falls back to stored IDs when names are unavailable and marks only missing identities as unrecorded', () => {
|
expect(filePropertyPreparer({ preparedBy: 'author-id', extendedProperties: { prepared_by_name: ' ' } })).toBe('author-id');
|
expect(filePropertyPreparer()).toBe('未记录');
|
expect(
|
filePropertyReviewers({
|
extendedProperties: {
|
reviewers: [
|
{ user_id: 'r1', name: '审核甲' },
|
{ user_id: '878193794397329605', name: '' },
|
{ user_id: 'r3', name: ' ' },
|
{ user_id: '', name: '' },
|
],
|
},
|
}),
|
).toBe('审核甲、878193794397329605、r3、未记录');
|
});
|
|
it('uses the stable document name and version metadata', () => {
|
expect(filePropertyName({ documentName: '清洁消毒记录', fileName: '清洁消毒记录.docx', name: 'fallback' })).toBe('清洁消毒记录');
|
expect(filePropertyVersion({ versionLabel: 'D(02)', versionNo: 2 })).toBe('D(02)');
|
expect(filePropertyVersion({ versionNo: 2 })).toBe('v2');
|
});
|
|
it('combines the next review date with its configured interval', () => {
|
expect(filePropertyReview({ nextReviewOn: '2028-06-19', reviewCycleMonths: 36 })).toBe('2028-06-19(每 36 个月)');
|
expect(filePropertyReview({ reviewCycleMonths: 24 })).toBe('每 24 个月');
|
expect(filePropertyReview()).toBe('—');
|
});
|
|
it('maps lifecycle states to user-facing labels', () => {
|
expect(filePropertyLifecycle('EFFECTIVE')).toEqual({ color: 'success', label: '已生效/执行中' });
|
expect(filePropertyLifecycle('SUPERSEDED').label).toBe('已被替代');
|
expect(filePropertyLifecycle().label).toBe('—');
|
});
|
});
|