diff --git a/assets/js/src/newsletter_editor/components/save.js b/assets/js/src/newsletter_editor/components/save.js index 7c122aedd7..b89fc9bc65 100644 --- a/assets/js/src/newsletter_editor/components/save.js +++ b/assets/js/src/newsletter_editor/components/save.js @@ -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) { diff --git a/tests/javascript/newsletter_editor/components/save.spec.js b/tests/javascript/newsletter_editor/components/save.spec.js index baa23026b8..bdd70e3186 100644 --- a/tests/javascript/newsletter_editor/components/save.spec.js +++ b/tests/javascript/newsletter_editor/components/save.spec.js @@ -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 () { diff --git a/views/newsletter/editor.html b/views/newsletter/editor.html index 6053a48441..e97b9d410f 100644 --- a/views/newsletter/editor.html +++ b/views/newsletter/editor.html @@ -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'),