Skip to content

Commit

Permalink
Update tests for commands and css composer
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jun 5, 2017
1 parent dd439a7 commit 1ae9192
Show file tree
Hide file tree
Showing 16 changed files with 689 additions and 708 deletions.
30 changes: 6 additions & 24 deletions src/editor/model/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,10 @@ require('block_manager'),
require('trait_manager'),
];

require('backbone');
require('backbone-undo');
var Backbone = require('backbone');
var UndoManager = require('backbone-undo');
var key = require('keymaster');
/*
require('Utils');
require('StorageManager');
require('DeviceManager');
require('Parser');
require('SelectorManager');
require('ModalDialog');
require('CodeManager');
require('Panels');
require('RichTextEditor');
require('StyleManager');
require('AssetManager');
require('CssComposer');
require('DomComponents');
require('Canvas');
require('Commands');
require('BlockManager');
require('TraitManager');
*/

module.exports = Backbone.Model.extend({

defaults: {
Expand Down Expand Up @@ -187,7 +169,7 @@ module.exports = Backbone.Model.extend({
var cmp = this.get('DomComponents');
if(cmp && this.config.undoManager){
var that = this;
this.um = new Backbone.UndoManager({
this.um = new UndoManager({
register: [cmp.getComponents(), this.get('CssComposer').getAll()],
track: true
});
Expand All @@ -202,9 +184,9 @@ module.exports = Backbone.Model.extend({
that.trigger('component:update');
});

Backbone.UndoManager.removeUndoType("change");
UndoManager.removeUndoType("change");
var beforeCache;
Backbone.UndoManager.addUndoType("change:style", {
UndoManager.addUndoType("change:style", {
"on": function (model, value, opts) {
var opt = opts || {};
if(!beforeCache){
Expand Down
2 changes: 0 additions & 2 deletions src/grapesjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Editor = require('editor'),
PluginManager = require('plugin_manager');

window['_'] = require('underscore');

var plugins = new PluginManager();
var editors = [];

Expand Down
2 changes: 0 additions & 2 deletions src/rich_text_editor/view/TextEditorView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var $ = require('jquery');

var readFileIntoDataUrl = fileInfo => {
var loader = $.Deferred(),
fReader = new FileReader();
Expand Down
29 changes: 24 additions & 5 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import _ from 'underscore';
import expect from 'expect';
import sinon from 'sinon';
import jquery from 'jquery';
import Backbone from 'backbone';
import grapesjs from './../src';
import { JSDOM } from 'jsdom';
import jquery from 'jquery';

const dom = new JSDOM('<!doctype html><html><body></body></html>');
global.window = dom.window;
global.document = dom.window.document;
const window = dom.window;
const $ = jquery(window);

//https://www.npmjs.com/package/proxyquire

// Fix for the spectrum lib
var Module = require('module');
var originalRequire = Module.prototype.require;

Module.prototype.require = function(name) {
if (name == 'jquery') {
return $;
}
return originalRequire.apply(this, arguments);
};

global.window = window;
global.document = window.document;
global.$ = $;
global._ = _;
global.expect = expect;
global.sinon = sinon;
dom.window.$ = jquery(dom.window);
Backbone.$ = dom.window.$;
global.grapesjs = grapesjs;
window.$ = $;
Backbone.$ = $;

Object.keys(window).forEach((key) => {
if (!(key in global)) {
Expand Down
7 changes: 3 additions & 4 deletions test/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import grapesjs from './../src';
//import AssetManager from './specs/asset_manager';
//import grapesjs from './../src';

describe('Main', () => {

describe('Startup', () => {
it('Main object should be loaded', () => {
//Grapes = require('editor/main');
expect(grapesjs).toExist();
});
});
Expand All @@ -14,5 +12,6 @@ describe('Main', () => {
require(`${path}asset_manager`);
require(`${path}block_manager`);
require(`${path}code_manager`);

require(`${path}commands`);
require(`${path}css_composer`);
});
41 changes: 41 additions & 0 deletions test/specs/commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var Commands = require('commands');
var Models = require('./model/CommandModels');

describe('Commands', () => {

describe('Main', () => {

let obj;

beforeEach(() => {
obj = new Commands().init();
});

afterEach(() => {
obj = null;
});

it('No commands inside', () => {
expect(obj.get('test')).toEqual(null);
});

it('Push new command', () => {
var comm = { test: 'test'};
obj.add('test', comm);
expect(obj.get('test').test).toEqual('test');
});

it('No default commands at init', () => {
expect(obj.get('select-comp')).toEqual(null);
});

it('Default commands after loadDefaultCommands', () => {
obj.loadDefaultCommands();
expect(obj.get('select-comp')).toNotEqual(null);
});

});

});

Models.run();
44 changes: 0 additions & 44 deletions test/specs/commands/main.js

This file was deleted.

63 changes: 30 additions & 33 deletions test/specs/commands/model/CommandModels.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
define(function(require, exports, module){
'use strict';
var Commands = require('undefined');
const Command = require('commands/model/Command');
const Commands = require('commands');

module.exports = {
run : function(){
describe('Command', function() {
var obj;
module.exports = {
run() {
describe('Command', () => {
let obj;

beforeEach(function () {
obj = new Command();
});
beforeEach(() => {
obj = new Command();
});

afterEach(function () {
delete obj;
});
afterEach(() => {
obj = null;
});

it('Has id property', function() {
obj.has('id').should.equal(true);
});
it('Has id property', () => {
expect(obj.has('id')).toEqual(true);
});

});
});

describe('Commands', function() {
var obj;
describe('Commands', () => {
var obj;

beforeEach(function () {
obj = new Commands();
});
beforeEach(() => {
obj = new Commands();
});

afterEach(function () {
delete obj;
});
afterEach(() => {
obj = null;
});

it('Object is ok', function() {
obj.should.be.ok;
});
it('Object is ok', () => {
expect(obj).toExist();
});

});
});

}
};

});
}
};
Loading

0 comments on commit 1ae9192

Please sign in to comment.