editor: Update block defaults for ALC changes
This commit is contained in:
@ -109,10 +109,10 @@ define([
|
|||||||
},
|
},
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
base.BlockView.prototype.initialize.apply(this, arguments);
|
base.BlockView.prototype.initialize.apply(this, arguments);
|
||||||
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:featuredImagePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._scheduleFetchPosts, this);
|
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:featuredImagePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._handleChanges, this);
|
||||||
this.listenTo(this.get('readMoreButton'), 'change', this._scheduleFetchPosts);
|
this.listenTo(this.get('readMoreButton'), 'change', this._handleChanges);
|
||||||
this.listenTo(this.get('divider'), 'change', this._scheduleFetchPosts);
|
this.listenTo(this.get('divider'), 'change', this._handleChanges);
|
||||||
this.on('add remove update reset', this._scheduleFetchPosts);
|
this.on('add remove update reset', this._handleChanges);
|
||||||
this.on('refreshPosts', this.updatePosts, this);
|
this.on('refreshPosts', this.updatePosts, this);
|
||||||
},
|
},
|
||||||
updatePosts: function (posts) {
|
updatePosts: function (posts) {
|
||||||
@ -122,7 +122,8 @@ define([
|
|||||||
* Batch more changes during a specific time, instead of fetching
|
* Batch more changes during a specific time, instead of fetching
|
||||||
* ALC posts on each model change
|
* ALC posts on each model change
|
||||||
*/
|
*/
|
||||||
_scheduleFetchPosts: function () {
|
_handleChanges: function () {
|
||||||
|
this._updateDefaults();
|
||||||
App.getChannel().trigger('automatedLatestContentRefresh');
|
App.getChannel().trigger('automatedLatestContentRefresh');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -73,6 +73,7 @@ define([
|
|||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
var model;
|
var model;
|
||||||
var module;
|
var module;
|
||||||
|
var sandbox;
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
module = AutomatedLatestContentBlock;
|
module = AutomatedLatestContentBlock;
|
||||||
@ -83,11 +84,13 @@ define([
|
|||||||
global.stubConfig(EditorApplication);
|
global.stubConfig(EditorApplication);
|
||||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
|
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
|
||||||
model = new (module.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
delete EditorApplication.getChannel;
|
delete EditorApplication.getChannel;
|
||||||
delete EditorApplication.getBlockTypeModel;
|
delete EditorApplication.getBlockTypeModel;
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has automatedLatestContent type', function () {
|
it('has automatedLatestContent type', function () {
|
||||||
@ -265,6 +268,29 @@ define([
|
|||||||
expect(model.get('_container.blocks').size()).to.equal(1);
|
expect(model.get('_container.blocks').size()).to.equal(1);
|
||||||
expect(model.get('_container.blocks').first().get('type')).to.equal('someCustomType');
|
expect(model.get('_container.blocks').first().get('type')).to.equal('someCustomType');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('updates blockDefaults.automatedLatestContent when handling changes', function () {
|
||||||
|
var stub = sandbox.stub(EditorApplication.getConfig(), 'set');
|
||||||
|
model.set('amount', '17');
|
||||||
|
model.set('contentType', 'mailpoet_page');
|
||||||
|
model.set('terms', []);
|
||||||
|
model.set('inclusionType', 'exclude');
|
||||||
|
model.set('displayType', 'full');
|
||||||
|
model.set('titleFormat', 'h3');
|
||||||
|
model.set('titleAlignment', 'right');
|
||||||
|
model.set('titleIsLink', true);
|
||||||
|
model.set('imageFullWidth', true);
|
||||||
|
model.set('featuredImagePosition', 'aboveTitle');
|
||||||
|
model.set('showAuthor', 'belowText');
|
||||||
|
model.set('authorPrecededBy', 'Custom config author preceded by');
|
||||||
|
model.set('showCategories', 'belowText');
|
||||||
|
model.set('categoriesPrecededBy', 'Custom config categories preceded by');
|
||||||
|
model.set('sortBy', 'oldest');
|
||||||
|
model.set('showDivider', false);
|
||||||
|
expect(stub.callCount).to.equal(16);
|
||||||
|
expect(stub.getCall(15).args[0]).to.equal('blockDefaults.automatedLatestContent');
|
||||||
|
expect(stub.getCall(15).args[1]).to.deep.equal(model.toJSON());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
|
Reference in New Issue
Block a user