刘光辉
12 小时以前 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
34
35
36
37
38
39
import { createPinia, setActivePinia } from 'pinia';
import { beforeEach, describe, expect, it } from 'vitest';
 
import { usePluginContextStore } from '../../src/stores/plugin-context';
 
const validOptions = {
  apiBaseUrl: 'http://localhost:30000',
    documentId: 'file-1',
    bizDataId: 'record-1',
    bizModule: 'eln.template',
    bizScene: 'eln.template.annotate',
    pluginVersion: '0.1.0',
    canAnnotate: true,
};
 
describe('plugin context store', () => {
  beforeEach(() => setActivePinia(createPinia()));
 
  it('合法上下文进入 ready,reset 后恢复初始状态', () => {
    const store = usePluginContextStore();
 
    expect(store.initialize(validOptions)).toBe(true);
    expect(store.status).toBe('ready');
    expect(store.context?.documentId).toBe('file-1');
 
    store.reset();
    expect(store.$state).toEqual({ status: 'initializing', context: null, error: '' });
  });
 
  it('非法上下文进入 error 并清除旧上下文', () => {
    const store = usePluginContextStore();
    store.initialize(validOptions);
 
    expect(store.initialize({})).toBe(false);
    expect(store.status).toBe('error');
    expect(store.context).toBeNull();
    expect(store.error).toBe('插件运行上下文无效');
  });
});