editor: Update blockDefaults for posts on change
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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 () {
|
||||
|
Reference in New Issue
Block a user