mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
import DataSourceManager from '../../../src/data_sources';
|
|
import { DataSourceProps } from '../../../src/data_sources/types';
|
|
import { setupTestEditor } from '../../common';
|
|
import EditorModel from '../../../src/editor/model/Editor';
|
|
|
|
describe('DataSourceManager', () => {
|
|
let em: EditorModel;
|
|
let dsm: DataSourceManager;
|
|
const dsTest: DataSourceProps = {
|
|
id: 'ds1',
|
|
records: [
|
|
{ id: 'id1', name: 'Name1' },
|
|
{ id: 'id2', name: 'Name2' },
|
|
{ id: 'id3', name: 'Name3' },
|
|
],
|
|
};
|
|
|
|
const addDataSource = () => dsm.add(dsTest);
|
|
|
|
beforeEach(() => {
|
|
({ em, dsm } = setupTestEditor());
|
|
});
|
|
|
|
afterEach(() => {
|
|
em.destroy();
|
|
});
|
|
|
|
test('DataSourceManager exists', () => {
|
|
expect(dsm).toBeTruthy();
|
|
});
|
|
|
|
test('add DataSource with records', () => {
|
|
const eventAdd = jest.fn();
|
|
em.on(dsm.events.add, eventAdd);
|
|
const ds = addDataSource();
|
|
expect(dsm.getAll().length).toBe(1);
|
|
expect(eventAdd).toBeCalledTimes(1);
|
|
expect(ds.getRecords().length).toBe(3);
|
|
});
|
|
|
|
test('get added DataSource', () => {
|
|
const ds = addDataSource();
|
|
expect(dsm.get(dsTest.id)).toBe(ds);
|
|
});
|
|
|
|
test('remove DataSource', () => {
|
|
const event = jest.fn();
|
|
em.on(dsm.events.remove, event);
|
|
const ds = addDataSource();
|
|
dsm.remove('ds1');
|
|
expect(dsm.getAll().length).toBe(0);
|
|
expect(event).toBeCalledTimes(1);
|
|
expect(event).toBeCalledWith(ds, expect.any(Object));
|
|
});
|
|
});
|
|
|