import { describe, expect, it } from 'vitest';
|
|
import { insertAnnotationControlCommand, parseInsertResult, stageFlowVersionPropertiesCommand } from '../../src/onlyoffice/commands';
|
|
describe('签批页标注 OnlyOffice 命令', () => {
|
it('命令只使用编辑器 Api 与 Asc.scope', () => {
|
const source = insertAnnotationControlCommand.toString();
|
expect(source).toContain('Asc.scope.dmsQianpiyeInsert');
|
expect(source).toContain('Api.GetDocument()');
|
expect(source).not.toContain('window.');
|
});
|
|
it('规范化无效编辑器返回值', () => {
|
expect(parseInsertResult('not-json')).toEqual({ ok: false, error: '签批页标注命令返回无效' });
|
expect(parseInsertResult(JSON.stringify({ ok: false, error: '无法插入' }))).toEqual({ ok: false, error: '无法插入' });
|
});
|
|
it('接受 AddInlineLvlSdt 的 void 返回值,允许重复插入同一字段并以写后校验确认成功', () => {
|
const controls: Array<{ GetTag: () => string; SetAlias: () => boolean; SetAppearance: () => void; SetLock: () => boolean; SetTag: (value: string) => boolean; AddElement: () => boolean }> = [];
|
const control = {
|
AddElement: () => true,
|
GetTag: () => tag,
|
SetAlias: () => true,
|
SetAppearance: () => undefined,
|
SetLock: () => true,
|
SetTag: (value: string) => {
|
tag = value;
|
return true;
|
},
|
};
|
let tag = '';
|
const paragraph: { AddInlineLvlSdt: (value: typeof control) => void; control?: typeof control } = {
|
AddInlineLvlSdt(value) {
|
this.control = value;
|
},
|
};
|
const originalAsc = (globalThis as any).Asc;
|
const originalApi = (globalThis as any).Api;
|
try {
|
(globalThis as any).Asc = { scope: { dmsQianpiyeInsert: { alias: '申请人', placeholder: '{{申请人}}', tag: 'dms.qianpiye.flow.start.applicant' } } };
|
(globalThis as any).Api = {
|
CreateInlineLvlSdt: () => control,
|
CreateParagraph: () => paragraph,
|
CreateRun: () => ({ AddText: () => true }),
|
GetDocument: () => ({
|
GetAllContentControls: () => controls,
|
InsertContent: () => {
|
controls.push(paragraph.control!);
|
return true;
|
},
|
}),
|
};
|
|
expect(JSON.parse(insertAnnotationControlCommand())).toEqual({ ok: true });
|
expect(JSON.parse(insertAnnotationControlCommand())).toEqual({ ok: true });
|
expect(controls).toHaveLength(2);
|
} finally {
|
(globalThis as any).Asc = originalAsc;
|
(globalThis as any).Api = originalApi;
|
}
|
});
|
|
it('暂存流程版本属性,并由服务端在保存时归一化重复属性', () => {
|
const properties = new Map<string, string>([
|
['DMS_NEW_FLOW_VERSION_ID', 'old-new'],
|
['DMS_EDIT_FLOW_VERSION_ID', 'old-revision'],
|
]);
|
const originalAsc = (globalThis as any).Asc;
|
const originalApi = (globalThis as any).Api;
|
try {
|
(globalThis as any).Asc = { scope: { dmsQianpiyeFlowVersionProperties: {
|
newFlowVersionId: 'new-version', revisionFlowVersionId: 'revision-version',
|
} } };
|
(globalThis as any).Api = { GetDocument: () => ({
|
GetCustomProperties: () => ({
|
Add: (key: string, value: string) => { properties.set(key, value); return true; },
|
Get: (key: string) => properties.get(key),
|
}),
|
}) };
|
|
expect(JSON.parse(stageFlowVersionPropertiesCommand())).toEqual({ ok: true });
|
expect(properties).toEqual(new Map([
|
['DMS_NEW_FLOW_VERSION_ID', 'new-version'],
|
['DMS_EDIT_FLOW_VERSION_ID', 'revision-version'],
|
]));
|
} finally {
|
(globalThis as any).Asc = originalAsc;
|
(globalThis as any).Api = originalApi;
|
}
|
});
|
});
|