mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-05 19:41:40 +08:00
* feat(editor,core,data-source,dep,schema,ui,utils,vue-runtime-help): 完善迭代器 * test: 完善测试用例 * chore: 构建 * feat: 迭代器嵌套事件传递数据 --------- Co-authored-by: roymondchen <roymondchen@tencent.com>
93 lines
2.0 KiB
TypeScript
93 lines
2.0 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import App from '@tmagic/core';
|
|
import { NodeType } from '@tmagic/schema';
|
|
|
|
import { DataSource, DataSourceManager } from '@data-source/index';
|
|
|
|
const app = new App({
|
|
config: {
|
|
type: NodeType.ROOT,
|
|
id: '1',
|
|
items: [],
|
|
dataSources: [
|
|
{
|
|
type: 'base',
|
|
id: '1',
|
|
fields: [{ name: 'name' }],
|
|
methods: [],
|
|
events: [],
|
|
},
|
|
{
|
|
type: 'http',
|
|
id: '2',
|
|
fields: [{ name: 'name' }],
|
|
methods: [],
|
|
events: [],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
describe('DataSourceManager', () => {
|
|
const dsm = new DataSourceManager({
|
|
app,
|
|
});
|
|
|
|
test('instance', () => {
|
|
expect(dsm).toBeInstanceOf(DataSourceManager);
|
|
expect(dsm.dataSourceMap.get('1')).toBeInstanceOf(DataSource);
|
|
expect(dsm.dataSourceMap.get('2')?.type).toBe('http');
|
|
});
|
|
|
|
test('register', () => {
|
|
class TestDataSource extends DataSource {}
|
|
|
|
DataSourceManager.register('test', TestDataSource as any);
|
|
expect(DataSourceManager.getDataSourceClass('test')).toBe(TestDataSource);
|
|
});
|
|
|
|
test('get', () => {
|
|
const ds = dsm.get('1');
|
|
expect(ds).toBeInstanceOf(DataSource);
|
|
});
|
|
|
|
test('removeDataSource', () => {
|
|
dsm.removeDataSource('1');
|
|
const ds = dsm.get('1');
|
|
expect(ds).toBeUndefined();
|
|
});
|
|
|
|
test('updateSchema', () => {
|
|
const dsm = new DataSourceManager({ app });
|
|
|
|
dsm.updateSchema([
|
|
{
|
|
type: 'base',
|
|
id: '1',
|
|
fields: [{ name: 'name1' }],
|
|
methods: [],
|
|
events: [],
|
|
},
|
|
]);
|
|
const ds = dsm.get('1');
|
|
expect(ds).toBeInstanceOf(DataSource);
|
|
});
|
|
|
|
test('destroy', () => {
|
|
dsm.destroy();
|
|
expect(dsm.dataSourceMap.size).toBe(0);
|
|
});
|
|
|
|
test('addDataSource error', async () => {
|
|
await dsm.addDataSource({
|
|
type: 'base',
|
|
id: '1',
|
|
fields: [{ name: 'name' }],
|
|
methods: [],
|
|
events: [],
|
|
});
|
|
expect(dsm.get('1')).toBeInstanceOf(DataSource);
|
|
});
|
|
});
|