diff --git a/src/css_composer/index.js b/src/css_composer/index.js index fcf7ea2aa..1a5dd374d 100644 --- a/src/css_composer/index.js +++ b/src/css_composer/index.js @@ -138,7 +138,7 @@ module.exports = () => { if (isArray(obj)) { obj.length && rules.reset(obj); - } else { + } else if (obj) { rules.reset(obj); } diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index d924f75af..9032fa049 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -93,7 +93,7 @@ module.exports = Backbone.Model.extend({ clb && clb(); }; - if (sm && sm.getConfig().autoload) { + if (sm && sm.canAutoload()) { this.load(postLoad); } else { postLoad(); diff --git a/src/storage_manager/index.js b/src/storage_manager/index.js index a68bd2e7b..9f9b8efe2 100644 --- a/src/storage_manager/index.js +++ b/src/storage_manager/index.js @@ -54,6 +54,14 @@ module.exports = () => { return this; }, + /** + * Get configuration object + * @return {Object} + * */ + getConfig() { + return c; + }, + /** * Checks if autosave is enabled * @return {Boolean} @@ -220,12 +228,21 @@ module.exports = () => { }, /** - * Get configuration object - * @return {Object} + * Get current storage + * @return {Storage} + * */ + getCurrentStorage() { + return this.get(this.getCurrent()); + }, + + /** + * Check if autoload is possible + * @return {Boolean} * @private * */ - getConfig() { - return c; + canAutoload() { + const storage = this.getCurrentStorage(); + return storage && this.getConfig().autoload; } }; }; diff --git a/test/specs/grapesjs/index.js b/test/specs/grapesjs/index.js index 303527a15..db4723538 100644 --- a/test/specs/grapesjs/index.js +++ b/test/specs/grapesjs/index.js @@ -37,7 +37,7 @@ describe('GrapesJS', () => { storageManager: { autoload: 0, autosave: 0, - type: '' + type: 0 } }; obj = grapesjs; @@ -141,25 +141,19 @@ describe('GrapesJS', () => { ).toEqual('test2'); }); - it.skip('Init editor from element', () => { + it('Init editor from element', () => { config.fromElement = 1; - fixtures.innerHTML = documentEl; - var editor = obj.init(config); - var html = editor.getHtml(); - var css = editor.getCss(); - var protCss = editor.getConfig().protectedCss; - /* - (html ? html : '').should.equal(htmlString); - (css ? css : '').should.equal(protCss + '.test2{color:red;}');// .test3 is discarded in css - editor.getComponents().length.should.equal(2); - editor.getStyle().length.should.equal(2); - */ - - expect(html ? html : '').toEqual(htmlString); + config.storageManager = { type: 0 }; + fixture.innerHTML = documentEl; + const editor = obj.init(config); + const html = editor.getHtml(); + const css = editor.getCss(); + const protCss = editor.getConfig().protectedCss; + expect(html).toEqual(htmlString); expect(editor.getComponents().length).toEqual(2); - // .test3 is discarded in css - expect(css ? css : '').toEqual(protCss + '.test2{color:red;}'); - // bust is still here + // .test3 is discarded in CSS + expect(css).toEqual(`${protCss}.test2{color:red;}`); + // but it's still there expect(editor.getStyle().length).toEqual(2); });