From 707dbd13079775f4382ffc672ad5511e1829e9b3 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 26 Apr 2016 14:39:33 +0200 Subject: [PATCH] More Commands tests --- src/commands/view/CommandAbstract.js | 15 ++++---- test/specs/commands/main.js | 28 ++++++++++++-- test/specs/commands/model/CommandModels.js | 44 ++++++++++++++++++++++ 3 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 test/specs/commands/model/CommandModels.js diff --git a/src/commands/view/CommandAbstract.js b/src/commands/view/CommandAbstract.js index 5aefdb833..577028dad 100644 --- a/src/commands/view/CommandAbstract.js +++ b/src/commands/view/CommandAbstract.js @@ -12,18 +12,19 @@ define(['backbone'], * @private * */ initialize: function(o) { - this.config = o; - this.editorModel = this.em = o.em || {}; - this.canvasId = o.canvasId || ''; - this.wrapperId = o.wrapperId || 'wrapper'; - this.pfx = o.stylePrefix; + this.config = o || {}; + this.editorModel = this.em = this.config.em || {}; + this.canvasId = this.config.canvasId || ''; + this.wrapperId = this.config.wrapperId || 'wrapper'; + this.pfx = this.config.stylePrefix; this.hoverClass = this.pfx + 'hover'; this.badgeClass = this.pfx + 'badge'; this.plhClass = this.pfx + 'placeholder'; - this.setElement(this.editorModel.get('$editor').find('#'+this.canvasId)); + if(this.editorModel.get) + this.setElement(this.editorModel.get('$editor').find('#'+this.canvasId)); this.$canvas = this.$el; this.$wrapper = this.$canvas.find('#'+this.wrapperId); - this.init(o); + this.init(this.config); }, /** diff --git a/test/specs/commands/main.js b/test/specs/commands/main.js index eb70b28dd..23c60e134 100644 --- a/test/specs/commands/main.js +++ b/test/specs/commands/main.js @@ -1,9 +1,12 @@ var modulePath = './../../../test/specs/commands'; define([ - 'Commands'], + 'Commands', + modulePath + '/model/CommandModels', + ], function( - Commands + Commands, + Models ) { describe('Commands', function() { @@ -20,11 +23,28 @@ define([ delete obj; }); - it('Object exists', function() { - obj.should.be.exist; + it('No commands inside', function() { + (obj.get('test') == null).should.equal(true); + }); + + it('Push new command', function() { + var comm = { test: 'test'}; + obj.add('test', comm); + (obj.get('test').test == 'test').should.equal(true); + }); + + it('No default commands at init', function() { + (obj.get('select-comp') == null).should.equal(true); + }); + + it('Default commands after loadDefaultCommands', function() { + obj.loadDefaultCommands(); + (obj.get('select-comp') == null).should.equal(false); }); }); }); + + Models.run(); }); \ No newline at end of file diff --git a/test/specs/commands/model/CommandModels.js b/test/specs/commands/model/CommandModels.js new file mode 100644 index 000000000..75347fd0b --- /dev/null +++ b/test/specs/commands/model/CommandModels.js @@ -0,0 +1,44 @@ +var path = 'Commands/model/'; +define([path + 'Command', path + 'Commands'], + function(Command, Commands) { + + return { + run : function(){ + describe('Command', function() { + var obj; + + beforeEach(function () { + obj = new Command(); + }); + + afterEach(function () { + delete obj; + }); + + it('Has id property', function() { + obj.has('id').should.equal(true); + }); + + }); + + describe('Commands', function() { + var obj; + + beforeEach(function () { + obj = new Commands(); + }); + + afterEach(function () { + delete obj; + }); + + it('Object is ok', function() { + obj.should.be.ok; + }); + + }); + + } + }; + +}); \ No newline at end of file