Skip to content

Commit

Permalink
Up test TS
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jul 18, 2023
1 parent ca2eaee commit e114380
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 144 deletions.
4 changes: 2 additions & 2 deletions src/dom_components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export type ComponentEvent =
| 'component:resize';

export interface ComponentModelDefinition extends IComponent {
defaults?: ComponentDefinition;
defaults?: ComponentDefinition | (() => ComponentDefinition);
[key: string]: any;
}

Expand Down Expand Up @@ -410,7 +410,7 @@ export default class ComponentManager extends ItemManagerModule<DomComponentsCon
* attributes: { title: 'here' }
* });
*/
addComponent(component: ComponentAdd, opt: AddOptions = {}) {
addComponent(component: ComponentAdd, opt: AddOptions = {}): Component | Component[] {
return this.getComponents().add(component, opt);
}

Expand Down
7 changes: 4 additions & 3 deletions test/specs/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Backbone from 'backbone';
import Commands from '../../../src/commands';
import EditorModel from '../../../src/editor/model/Editor';
import { Command, CommandFunction } from '../../../src/commands/view/CommandAbstract';

describe('Commands', () => {
describe('Main', () => {
let em: EditorModel;
let obj: Commands;
let commSimple;
let commRunOnly;
let commFunc;
let commSimple: Command;
let commRunOnly: Command;
let commFunc: CommandFunction;
let commName = 'commandTest';
let commResultRun = 'Run executed';
let commResultStop = 'Stop executed';
Expand Down
4 changes: 2 additions & 2 deletions test/specs/css_composer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Css Composer', () => {
describe('Main', () => {
let obj: CssComposer;
let em: Editor;
let config;
let config: any;
let storagMock = utils.storageMock();
let editorModel = {
getCss() {
Expand All @@ -28,7 +28,7 @@ describe('Css Composer', () => {
config.em = editorModel;
};

const getCSS = obj =>
const getCSS = (obj: CssComposer) =>
obj
.getAll()
.map(r => r.toCSS())
Expand Down
17 changes: 9 additions & 8 deletions test/specs/dom_components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import Components from '../../../src/dom_components/model/Components';
import EditorModel from '../../../src/editor/model/Editor';
import Editor from '../../../src/editor';
import utils from './../../test_utils.js';
import { Component } from '../../../src';

describe('DOM Components', () => {
describe('Main', () => {
var em: EditorModel;
var obj: DomComponents;
var config;
var config: any;
var storagMock = utils.storageMock();
var editorModel = {
config: {
Expand Down Expand Up @@ -122,21 +123,21 @@ describe('DOM Components', () => {
});

test('Import propertly components and styles with the same ids', () => {
obj = em.get('DomComponents');
const cc = em.get('CssComposer');
obj = em.Components;
const cc = em.Css;
const id = 'idtest';
const component = obj.addComponent(`
<div id="${id}" style="color:red; padding: 50px 100px">Text</div>
<style>
#${id} { background-color: red }
</style>`);
</style>`) as Component;
expect(em.getHtml({ component })).toEqual(`<div id="${id}">Text</div>`);
expect(obj.getComponents().length).toEqual(1);
const firstComp = obj.getComponents().first();
firstComp.addStyle({ margin: '10px' });
firstComp.addStyle('width', '100px');
expect(cc.getAll().length).toEqual(1);
expect(cc.getIdRule(id).getStyle()).toEqual({
expect(cc.getIdRule(id)!.getStyle()).toEqual({
color: 'red',
'background-color': 'red',
padding: '50px 100px',
Expand Down Expand Up @@ -249,7 +250,7 @@ describe('DOM Components', () => {
<div id="${id}" style="color:red; padding: 50px 100px">Text</div>
<style>
#${id} { background-color: red }
</style>`);
</style>`) as Component;
obj.getComponents().first().addStyle({ margin: '10px' });
const rule = cc.getAll().at(0);
const css = `#${id}{background-color:red;margin:10px;color:red;padding:50px 100px;}`;
Expand Down Expand Up @@ -293,14 +294,14 @@ describe('DOM Components', () => {
});

test('Custom style properly added', () => {
const cmp = obj.addComponent({ type: cmpId });
const cmp = obj.addComponent({ type: cmpId }) as Component;
expect(cmp.is(cmpId)).toBe(true);
const rule = em.Css.getRule(`.${cmpId}`);
expect(rule?.getStyle()).toEqual({ color: 'red' });
});

test('Clean custom style when the related component is removed', () => {
const cmp = obj.addComponent({ type: cmpId });
const cmp = obj.addComponent({ type: cmpId }) as Component;
expect(obj.getComponents().length).toBe(1);
expect(em.Css.getAll().length).toBe(1);
cmp.remove();
Expand Down
Loading

0 comments on commit e114380

Please sign in to comment.