刘光辉
14 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
26
27
28
29
30
31
32
33
import { afterEach, describe, expect, it, vi } from 'vitest';
 
import { createOnlyOfficeBridge } from '../../src/onlyoffice/bridge';
 
describe('filler bridge', () => {
  afterEach(() => vi.unstubAllGlobals());
 
  it('binds init and executes inspect command', async () => {
    vi.stubGlobal('Api', { GetDocument: () => ({ GetAllContentControls: () => [] }) });
    const asc: any = { scope: {}, plugin: { info: { options: { ticket: 'x' } }, callCommand: vi.fn((command, _a, _b, callback) => callback(command())), executeCommand: vi.fn(), executeMethod: vi.fn(), onThemeChangedBase: vi.fn() } };
    const bridge = createOnlyOfficeBridge(asc);
    const ready = vi.fn();
    bridge.bindLifecycle({ onReady: ready, onThemeChanged: vi.fn() });
    asc.plugin.init();
    expect(ready).toHaveBeenCalled();
    await expect(bridge.inspectFields()).resolves.toEqual([]);
  });
 
  it('reports an invalid editor command result when the SDK callback has no value', async () => {
    const asc: any = {
      scope: {},
      plugin: {
        callCommand: vi.fn((_command, _a, _b, callback) => callback(undefined)),
        executeCommand: vi.fn(),
        executeMethod: vi.fn(),
        onThemeChangedBase: vi.fn(),
      },
    };
 
    await expect(createOnlyOfficeBridge(asc).inspectFields()).rejects.toThrow('编辑器命令返回无效结果');
    expect(asc.scope.elnTemplateFillInspect).toBeUndefined();
  });
});