Browse Source

Add tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
8f0a9e6b69
  1. 3
      src/editor/config/config.js
  2. 8
      src/editor/model/Editor.js
  3. 7
      src/grapesjs/main.js
  4. 11
      test/specs/grapesjs/main.js

3
src/editor/config/config.js

@ -70,6 +70,9 @@ define(function () {
//Configurations for Css Composer //Configurations for Css Composer
cssComposer : {}, cssComposer : {},
// Dom element
el: '',
}; };
return config; return config;
}); });

8
src/editor/model/Editor.js

@ -43,12 +43,15 @@ define([
}, },
initialize: function(c) { initialize: function(c) {
this.config = c; this.config = c;
this.pfx = this.config.storagePrefix; this.pfx = this.config.storagePrefix;
this.compName = this.pfx + 'components' + this.config.id; this.compName = this.pfx + 'components' + this.config.id;
this.rulesName = this.pfx + 'rules' + this.config.id; this.rulesName = this.pfx + 'rules' + this.config.id;
this.set('Config', c); this.set('Config', c);
//console.log(c);
//getCacheLoad
this.initParser(); this.initParser();
this.initStorage(); this.initStorage();
this.initClassManager(); this.initClassManager();
@ -89,7 +92,8 @@ define([
* @private * @private
* */ * */
initCssComposer: function() { initCssComposer: function() {
this.config.cssComposer.defaults = this.config.style; if(this.config.style)
this.config.cssComposer.defaults = this.config.style;
var cfg = this.config.cssComposer, var cfg = this.config.cssComposer,
df = ''; df = '';
pfx = cfg.stylePrefix || 'css-'; pfx = cfg.stylePrefix || 'css-';

7
src/grapesjs/main.js

@ -32,6 +32,13 @@ define(function (require) {
* @return {grapesjs.Editor} GrapesJS Editor instance * @return {grapesjs.Editor} GrapesJS Editor instance
*/ */
init: function(config) { init: function(config) {
var c = config || {};
var els = c.container;
if(!els)
throw new Error("'container' is required");
config.el = document.querySelector(els);
var editor = new Editor(config); var editor = new Editor(config);
//- new EditorView({model: editor}).render(); //- new EditorView({model: editor}).render();
//- inject and start plugins (plugins) //- inject and start plugins (plugins)

11
test/specs/grapesjs/main.js

@ -1,5 +1,5 @@
define(['GrapesJS', 'PluginManager'], define(['GrapesJS', 'PluginManager', 'chai'],
function(GrapesJS, PluginManager) { function(GrapesJS, PluginManager, chai) {
describe('GrapesJS', function() { describe('GrapesJS', function() {
@ -40,7 +40,7 @@ define(['GrapesJS', 'PluginManager'],
}); });
it('Init new editor', function() { it('Init new editor', function() {
var editor = obj.init(); var editor = obj.init(config);
editor.should.not.be.empty; editor.should.not.be.empty;
}); });
@ -65,16 +65,17 @@ define(['GrapesJS', 'PluginManager'],
it('Init editor with css', function() { it('Init editor with css', function() {
config.style = cssString; config.style = cssString;
var editor = obj.init(config); var editor = obj.init(config);
console.log(editor.CssComposer.getRules());
var rules = editor.CssComposer.getRules(); var rules = editor.CssComposer.getRules();
rules.length.should.equal(2); rules.length.should.equal(2);
rules.at(0).get('selectors').at(0).get('name').should.equal('test2'); rules.at(0).get('selectors').at(0).get('name').should.equal('test2');
}); });
it('Init editor from element', function() { it.skip('Init editor from element', function() {
config.fromElement = 1; config.fromElement = 1;
fixture.html(documentEl); fixture.html(documentEl);
console.log('START');
var editor = obj.init(config); var editor = obj.init(config);
console.log('END');
var html = editor.getHtml(); var html = editor.getHtml();
var css = editor.getCss(); var css = editor.getCss();
(html ? html : '').should.equal(htmlString); (html ? html : '').should.equal(htmlString);

Loading…
Cancel
Save