[MAILPOET-1263] Force user to create ALC block for post notification

This commit is contained in:
Rostislav Wolny
2018-02-13 21:27:44 +01:00
parent f9204f289f
commit 9d4f996a6a
3 changed files with 45 additions and 0 deletions

View File

@ -305,6 +305,13 @@ define([
return;
}
if ((App.getNewsletter().get('type') === 'notification') &&
contents.indexOf('automatedLatestContent') < 0
) {
this.showValidationError(MailPoet.I18n.t('automatedLatestContentMissing'));
return;
}
this.hideValidationError();
},
showValidationError: function (message) {

View File

@ -101,8 +101,10 @@ define([
describe('view', function () {
before(function () {
var newsletter = { get: sinon.stub().withArgs('type').returns('newsletter') };
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
global.stubConfig(EditorApplication);
EditorApplication.getNewsletter = sinon.stub().returns(newsletter);
});
it('renders', function () {
@ -110,6 +112,41 @@ define([
expect(view.render).to.not.throw();
});
describe('validateNewsletter', function () {
var hideValidationErrorStub;
var view;
beforeEach(function () {
view = new (SaveComponent.SaveView)();
hideValidationErrorStub = sinon.stub(view, 'hideValidationError');
});
it('hides errors for valid newsletter', function () {
view.validateNewsletter({});
expect(hideValidationErrorStub.callCount).to.be.equal(1);
});
it('hides errors for valid post notification', function () {
var newsletter = { get: sinon.stub().withArgs('type').returns('notification') };
EditorApplication.getNewsletter = sinon.stub().returns(newsletter);
view.validateNewsletter({
content: {
blocks: [
{ type: 'automatedLatestContent' }
]
}
});
expect(hideValidationErrorStub.callCount).to.be.equal(1);
});
it('shows error for notification email type when ALC content is not present', function () {
var newsletter = { get: sinon.stub().withArgs('type').returns('notification') };
var showValidationErrorStub = sinon.stub(view, 'showValidationError');
EditorApplication.getNewsletter = sinon.stub().returns(newsletter);
view.validateNewsletter({});
expect(showValidationErrorStub.callCount).to.be.equal(1);
});
});
describe('once rendered', function () {
var view;
beforeEach(function () {

View File

@ -329,6 +329,7 @@
'failedToFetchRenderedPosts': __('Failed to fetch rendered posts'),
'shortcodesWindowTitle': __('Select a shortcode'),
'unsubscribeLinkMissing': __('All emails must include an "Unsubscribe" link. Add a footer widget to your email to continue.'),
'automatedLatestContentMissing': __('Please add an "Automated Latest Content" widget to the email from the right sidebar.'),
'newsletterPreviewEmailMissing': __('Enter an email address to send the preview newsletter to.'),
'newsletterPreviewSent': __('Your test email has been sent!'),
'templateNameMissing': __('Please add a template name'),