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([ }); }); }); +