From 93ef1d0197012dd8c8388c91e947123eb124afec Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Thu, 8 Jun 2017 10:19:24 +0100 Subject: [PATCH 1/3] Fix ALC buttons settings when updating all buttons [MAILPOET-896] --- .../src/newsletter_editor/blocks/automatedLatestContent.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js index 430e0a1496..d042c3e79a 100644 --- a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js +++ b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js @@ -129,6 +129,12 @@ define([ Module.AutomatedLatestContentBlockView = base.BlockView.extend({ className: "mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block", + initialize: function() { + function replaceButtonStylesHandler(data) { + this.model.set({'readMoreButton': data}); + } + App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this)); + }, getTemplate: function() { return templates.automatedLatestContentBlock; }, regions: { toolsRegion: '.mailpoet_tools', From 152edda03f9702b7ddebdf1cd0f98638081b2ffb Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Thu, 8 Jun 2017 15:34:23 +0100 Subject: [PATCH 2/3] Add unit test [MAILPOET-896] --- .../blocks/automatedLatestContent.js | 4 +- .../blocks/automatedLatestContent.spec.js | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js index d042c3e79a..cf7dd38a0c 100644 --- a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js +++ b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js @@ -131,9 +131,9 @@ define([ className: "mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block", initialize: function() { function replaceButtonStylesHandler(data) { - this.model.set({'readMoreButton': data}); + this.model.set({"readMoreButton": data}); } - App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this)); + App.getChannel().on("replaceAllButtonStyles", replaceButtonStylesHandler.bind(this)); }, getTemplate: function() { return templates.automatedLatestContentBlock; }, regions: { diff --git a/tests/javascript/newsletter_editor/blocks/automatedLatestContent.spec.js b/tests/javascript/newsletter_editor/blocks/automatedLatestContent.spec.js index bbea9d7b47..4fea329702 100644 --- a/tests/javascript/newsletter_editor/blocks/automatedLatestContent.spec.js +++ b/tests/javascript/newsletter_editor/blocks/automatedLatestContent.spec.js @@ -282,6 +282,43 @@ define([ }); }); + describe('replaceAllButtonStyles', function () { + var model, view, module, onStub; + + before(function() { + module = AutomatedLatestContentBlock; + }); + + beforeEach(function () { + onStub = sinon.stub() + global.stubChannel(EditorApplication, {on: onStub}) + global.stubConfig(EditorApplication); + EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model); + EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View); + model = {set: sinon.stub()} + view = new (module.AutomatedLatestContentBlockView)({model: model}); + }); + + it("listens to the event", function () { + expect(onStub).to.have.been.calledOnce; + expect(onStub).to.have.been.calledWith("replaceAllButtonStyles", sinon.match.func); + }); + + it("updates the model", function () { + const callback = onStub.getCall(0).args[1]; + const data = { + styles: { + block: { + borderRadius: "14px", + }, + }, + }; + callback(data); + expect(model.set).to.have.been.calledOnce; + expect(model.set).to.have.been.calledWithMatch(sinon.match.has("readMoreButton", data)); + }); + }); + describe('block settings view', function () { var model, view, module; @@ -510,3 +547,4 @@ define([ }); }); }); + From bc51b6efc8b903371d932957bdb58d97f68bf909 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Fri, 9 Jun 2017 07:24:26 +0100 Subject: [PATCH 3/3] Add replaceAllButtonStyles test to button [MAILPOET-896] --- .../newsletter_editor/blocks/button.spec.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/javascript/newsletter_editor/blocks/button.spec.js b/tests/javascript/newsletter_editor/blocks/button.spec.js index 126d6c694f..07263e1657 100644 --- a/tests/javascript/newsletter_editor/blocks/button.spec.js +++ b/tests/javascript/newsletter_editor/blocks/button.spec.js @@ -259,6 +259,38 @@ define([ }); }); + describe('replaceAllButtonStyles', function () { + var model, view, onStub; + + + beforeEach(function () { + onStub = sinon.stub() + global.stubChannel(EditorApplication, {on: onStub}) + model = {set: sinon.stub(), toJSON: sinon.stub()} + view = new (ButtonBlock.ButtonBlockView)({model: model}); + view.render(); + }); + + it("listens to the event", function () { + expect(onStub).to.have.been.calledOnce; + expect(onStub).to.have.been.calledWith("replaceAllButtonStyles", sinon.match.func); + }); + + it("updates the model", function () { + const callback = onStub.getCall(0).args[1]; + const data = { + styles: { + block: { + borderRadius: "14px", + }, + }, + }; + callback(data); + expect(model.set).to.have.been.calledOnce; + expect(model.set).to.have.been.calledWithExactly(data); + }); + }); + describe('block settings view', function () { var model;