Browse Source

Up model view tests

pull/5321/head
Artur Arseniev 3 years ago
parent
commit
e9402bc76f
  1. 27
      test/specs/dom_components/view/ComponentsView.ts

27
test/specs/dom_components/view/ComponentsView.js → test/specs/dom_components/view/ComponentsView.ts

@ -1,29 +1,30 @@
import DomComponents from 'dom_components'; import Components from '../../../../src/dom_components/model/Components';
import ComponentsView from 'dom_components/view/ComponentsView'; import ComponentsView from '../../../../src/dom_components/view/ComponentsView';
import Components from 'dom_components/model/Components'; import Editor from '../../../../src/editor/model/Editor';
import Editor from 'editor/model/Editor';
describe('ComponentsView', () => { describe('ComponentsView', () => {
var model; let model: Components;
var view; let view: ComponentsView;
var dcomp; let dcomp: Editor['Components'];
var compOpts; let compOpts: any;
const em = new Editor(); let em: Editor;
beforeEach(() => { beforeEach(() => {
dcomp = new DomComponents(em); em = new Editor();
dcomp = em.Components;
compOpts = { compOpts = {
em, em,
componentTypes: dcomp.componentTypes, componentTypes: dcomp.componentTypes,
}; };
model = new Components([], compOpts); model = new Components([], compOpts);
view = new ComponentsView({ view = new ComponentsView({
// @ts-ignore
collection: model, collection: model,
componentTypes: dcomp.componentTypes, componentTypes: dcomp.componentTypes,
config: { em }, config: { em },
}); });
document.body.innerHTML = '<div id="fixtures"></div>'; document.body.innerHTML = '<div id="fixtures"></div>';
document.body.querySelector('#fixtures').appendChild(view.render().el); document.body.querySelector('#fixtures')!.appendChild(view.render().el);
}); });
afterEach(() => { afterEach(() => {
@ -35,9 +36,9 @@ describe('ComponentsView', () => {
}); });
test('Add new component', () => { test('Add new component', () => {
sinon.stub(view, 'addToCollection'); const addSpy = jest.spyOn(view, 'addToCollection');
view.collection.add({}); view.collection.add({});
expect(view.addToCollection.calledOnce).toEqual(true); expect(addSpy).toBeCalledTimes(1);
}); });
test('Render new component', () => { test('Render new component', () => {
Loading…
Cancel
Save