editor: Update blockDefaults for posts on change

This commit is contained in:
Rostislav Wolny
2018-03-13 10:56:53 +01:00
parent f6374d0602
commit c7e83377ba
2 changed files with 12 additions and 0 deletions

View File

@ -107,6 +107,7 @@ define([
_.extend(this, Radio.Requests); _.extend(this, Radio.Requests);
this.fetchAvailablePosts(); 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('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailablePosts);
this.on('loadMorePosts', this._loadMorePosts, this); this.on('loadMorePosts', this._loadMorePosts, this);

View File

@ -23,6 +23,7 @@ define([
}; };
describe('model', function () { describe('model', function () {
var model; var model;
var sandbox;
before(function () { before(function () {
CommunicationComponent.getPosts = function () { CommunicationComponent.getPosts = function () {
@ -37,10 +38,12 @@ define([
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel); EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View); EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
model = new (PostsBlock.PostsBlockModel)(); model = new (PostsBlock.PostsBlockModel)();
sandbox = sinon.sandbox.create();
}); });
afterEach(function () { afterEach(function () {
delete EditorApplication.getChannel; delete EditorApplication.getChannel;
sandbox.restore();
}); });
it('has posts type', function () { 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(spy.withArgs('morePostsLoaded').calledOnce).to.be.true;// eslint-disable-line no-unused-expressions
expect(model.get('_availablePosts').length).to.equal(3); 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 () { describe('block view', function () {