diff --git a/assets/js/src/newsletter_editor/blocks/posts.js b/assets/js/src/newsletter_editor/blocks/posts.js index 108b83c095..5a6d7587df 100644 --- a/assets/js/src/newsletter_editor/blocks/posts.js +++ b/assets/js/src/newsletter_editor/blocks/posts.js @@ -107,6 +107,7 @@ define([ _.extend(this, Radio.Requests); this.fetchAvailablePosts(); + this.on('change', this._updateDefaults, this); this.on('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailablePosts); this.on('loadMorePosts', this._loadMorePosts, this); diff --git a/tests/javascript/newsletter_editor/blocks/posts.spec.js b/tests/javascript/newsletter_editor/blocks/posts.spec.js index d59ec048ba..cf47dd20e4 100644 --- a/tests/javascript/newsletter_editor/blocks/posts.spec.js +++ b/tests/javascript/newsletter_editor/blocks/posts.spec.js @@ -23,6 +23,7 @@ define([ }; describe('model', function () { var model; + var sandbox; before(function () { CommunicationComponent.getPosts = function () { @@ -37,10 +38,12 @@ define([ EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel); EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View); model = new (PostsBlock.PostsBlockModel)(); + sandbox = sinon.sandbox.create(); }); afterEach(function () { delete EditorApplication.getChannel; + sandbox.restore(); }); it('has posts type', function () { @@ -259,6 +262,14 @@ define([ expect(spy.withArgs('morePostsLoaded').calledOnce).to.be.true;// eslint-disable-line no-unused-expressions expect(model.get('_availablePosts').length).to.equal(3); }); + + it('updates blockDefaults.posts when changed', function () { + var stub = sandbox.stub(EditorApplication.getConfig(), 'set'); + model.trigger('change'); + expect(stub.callCount).to.equal(1); + expect(stub.getCall(0).args[0]).to.equal('blockDefaults.posts'); + expect(stub.getCall(0).args[1]).to.deep.equal(model.toJSON()); + }); }); describe('block view', function () {