Browse Source

Up ComponentTextView tests

pull/5649/head
Artur Arseniev 3 years ago
parent
commit
d3168ff4ba
  1. 1
      test/specs/dom_components/model/Component.ts
  2. 36
      test/specs/dom_components/view/ComponentTextView.ts

1
test/specs/dom_components/model/Component.ts

@ -21,7 +21,6 @@ describe('Component', () => {
em = new Editor({ avoidDefaults: true });
dcomp = em.get('DomComponents');
em.get('PageManager').onLoad();
// dcomp = new DomComponents(em);
compOpts = {
em,
componentTypes: dcomp.componentTypes,

36
test/specs/dom_components/view/ComponentTextView.js → test/specs/dom_components/view/ComponentTextView.ts

@ -1,16 +1,29 @@
import ComponentTextView from 'dom_components/view/ComponentTextView';
import Component from 'dom_components/model/Component';
import ComponentTextView from '../../../../src/dom_components/view/ComponentTextView';
import Component from '../../../../src/dom_components/model/Component';
import Editor from '../../../../src/editor/model/Editor';
describe('ComponentTextView', () => {
let fixtures;
let model;
let view;
let el;
let dcomp;
let compOpts;
let em: Editor;
beforeEach(() => {
model = new Component();
em = new Editor({ avoidDefaults: true });
dcomp = em.Components;
compOpts = {
em,
componentTypes: dcomp.componentTypes,
domc: dcomp,
};
model = new Component({}, compOpts);
view = new ComponentTextView({
model,
// @ts-ignore
config: { ...em.config, em },
});
document.body.innerHTML = '<div id="fixtures"></div>';
fixtures = document.body.querySelector('#fixtures');
@ -36,7 +49,7 @@ describe('ComponentTextView', () => {
});
test('Init with content', () => {
model = new Component({ content: 'test' });
model = new Component({ content: 'test' }, compOpts);
view = new ComponentTextView({ model });
fixtures.appendChild(view.render().el);
expect(view.el.innerHTML).toEqual('test');
@ -57,20 +70,21 @@ describe('ComponentTextView', () => {
};
spyOn(view, 'getChildrenContainer').and.returnValue(fakeChildContainer);
em.RichTextEditor.customRte = fakeRte;
});
it('should get content from active RTE if available', () => {
view.activeRte = fakeRte;
expect(view.getContent()).toEqual(fakeRteContent);
it('should get content from active RTE if available', async () => {
view.activeRte = {};
expect(await view.getContent()).toEqual(fakeRteContent);
expect(fakeRte.getContent).toHaveBeenCalled();
});
it("should get child container's `innerHTML` if active RTE is not available or if it has no `getContent` function", () => {
expect(view.getContent()).toEqual(fakeChildContainer.innerHTML);
it("should get child container's `innerHTML` if active RTE is not available or if it has no `getContent` function", async () => {
expect(await view.getContent()).toEqual(fakeChildContainer.innerHTML);
fakeRte.getContent = null;
view.activeRte = fakeRte;
expect(view.getContent()).toEqual(fakeChildContainer.innerHTML);
view.activeRte = {};
expect(await view.getContent()).toEqual(fakeChildContainer.innerHTML);
expect(view.getChildrenContainer).toHaveBeenCalledTimes(2);
});
Loading…
Cancel
Save