Rename all non-snake-case JS/TS files
[MAILPOET-4938]
This commit is contained in:
@@ -0,0 +1,375 @@
|
||||
/* (ES6 -> CommonJS transform needed for inject-loader) */
|
||||
/* eslint-disable-next-line max-len */
|
||||
import CommunicationInjector from 'inject-loader!babel-loader?plugins[]=@babel/plugin-transform-modules-commonjs!newsletter_editor/components/communication';
|
||||
|
||||
const expect = global.expect;
|
||||
const jQuery = global.jQuery;
|
||||
const sinon = global.sinon;
|
||||
|
||||
describe('getPostTypes', function () {
|
||||
it('fetches post types from the server', function () {
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
data: {
|
||||
post: 'val1',
|
||||
page: 'val2',
|
||||
},
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
module.getPostTypes().done(function (types) {
|
||||
expect(types).to.eql(['val1', 'val2']);
|
||||
});
|
||||
});
|
||||
|
||||
it('caches results', function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(deferred);
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
deferred.resolve({
|
||||
post: 'val1',
|
||||
page: 'val2',
|
||||
});
|
||||
module.getPostTypes();
|
||||
module.getPostTypes();
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTaxonomies', function () {
|
||||
it('sends post type to endpoint', function () {
|
||||
var spy;
|
||||
var post = function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
category: 'val1',
|
||||
post_tag: 'val2',
|
||||
});
|
||||
return deferred;
|
||||
};
|
||||
var module;
|
||||
spy = sinon.spy(post);
|
||||
module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: spy,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
|
||||
module.getTaxonomies('post');
|
||||
expect(spy.args[0][0].data.postType).to.equal('post');
|
||||
});
|
||||
|
||||
it('fetches taxonomies from the server', function () {
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
data: {
|
||||
category: 'val1',
|
||||
},
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
module.getTaxonomies('page').done(function (types) {
|
||||
expect(types).to.eql({ category: 'val1' });
|
||||
});
|
||||
});
|
||||
|
||||
it('caches results', function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(deferred);
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
deferred.resolve({ category: 'val1' });
|
||||
module.getTaxonomies('page');
|
||||
module.getTaxonomies('page');
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTerms', function () {
|
||||
it('sends terms to endpoint', function () {
|
||||
var spy;
|
||||
var post = function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({});
|
||||
return deferred;
|
||||
};
|
||||
var module;
|
||||
spy = sinon.spy(post);
|
||||
module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: spy,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
|
||||
module.getTerms({
|
||||
taxonomies: ['category', 'post_tag'],
|
||||
});
|
||||
expect(spy.args[0][0].data.taxonomies).to.eql(['category', 'post_tag']);
|
||||
});
|
||||
|
||||
it('fetches terms from the server', function () {
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
data: {
|
||||
term1: 'term1val1',
|
||||
term2: 'term2val2',
|
||||
},
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
module.getTerms({ taxonomies: ['category'] }).done(function (types) {
|
||||
expect(types).to.eql({ term1: 'term1val1', term2: 'term2val2' });
|
||||
});
|
||||
});
|
||||
|
||||
it('caches results', function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(deferred);
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
deferred.resolve({ term1: 'term1val1', term2: 'term2val2' });
|
||||
module.getTerms({ taxonomies: ['category'] });
|
||||
module.getTerms({ taxonomies: ['category'] });
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPosts', function () {
|
||||
it('sends options to endpoint', function () {
|
||||
var spy;
|
||||
var post = function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({});
|
||||
return deferred;
|
||||
};
|
||||
var module;
|
||||
spy = sinon.spy(post);
|
||||
module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: spy,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
|
||||
module.getPosts({
|
||||
type: 'posts',
|
||||
search: 'some search term',
|
||||
});
|
||||
expect(spy.args[0][0].data).to.eql({
|
||||
type: 'posts',
|
||||
search: 'some search term',
|
||||
});
|
||||
});
|
||||
|
||||
it('fetches posts from the server', function () {
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
data: [
|
||||
{ post_title: 'title 1' },
|
||||
{ post_title: 'post title 2' },
|
||||
],
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
module.getPosts().done(function (posts) {
|
||||
expect(posts).to.eql([
|
||||
{ post_title: 'title 1' },
|
||||
{ post_title: 'post title 2' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('caches results', function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(deferred);
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
deferred.resolve({
|
||||
type: 'posts',
|
||||
search: 'some search term',
|
||||
});
|
||||
module.getPosts({});
|
||||
module.getPosts({});
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTransformedPosts', function () {
|
||||
it('sends options to endpoint', function () {
|
||||
var spy;
|
||||
var post = function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({});
|
||||
return deferred;
|
||||
};
|
||||
var module;
|
||||
spy = sinon.spy(post);
|
||||
module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: spy,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
|
||||
module.getTransformedPosts({
|
||||
type: 'posts',
|
||||
posts: [1, 2],
|
||||
});
|
||||
expect(spy.args[0][0].data).to.eql({
|
||||
type: 'posts',
|
||||
posts: [1, 2],
|
||||
});
|
||||
});
|
||||
|
||||
it('fetches transformed posts from the server', function () {
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
deferred.resolve({
|
||||
data: [
|
||||
{ type: 'text', text: 'something' },
|
||||
{ type: 'text', text: 'something else' },
|
||||
],
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
module.getTransformedPosts().done(function (posts) {
|
||||
expect(posts).to.eql([
|
||||
{ type: 'text', text: 'something' },
|
||||
{ type: 'text', text: 'something else' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('caches results', function () {
|
||||
var deferred = jQuery.Deferred();
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(deferred);
|
||||
var module = CommunicationInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CommunicationComponent;
|
||||
deferred.resolve({
|
||||
type: 'posts',
|
||||
posts: [1, 3],
|
||||
});
|
||||
module.getTransformedPosts({});
|
||||
module.getTransformedPosts({});
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
@@ -0,0 +1,14 @@
|
||||
import { ConfigComponent } from 'newsletter_editor/components/config';
|
||||
|
||||
const expect = global.expect;
|
||||
|
||||
describe('Config', function () {
|
||||
it('loads and stores configuration', function () {
|
||||
var model;
|
||||
ConfigComponent.setConfig({
|
||||
testConfig: 'testValue',
|
||||
});
|
||||
model = ConfigComponent.getConfig();
|
||||
expect(model.get('testConfig')).to.equal('testValue');
|
||||
});
|
||||
});
|
@@ -0,0 +1,139 @@
|
||||
import { App } from 'newsletter_editor/App';
|
||||
import { ContentComponent } from 'newsletter_editor/components/content';
|
||||
|
||||
const expect = global.expect;
|
||||
const sinon = global.sinon;
|
||||
const Backbone = global.Backbone;
|
||||
const _ = global._;
|
||||
|
||||
describe('Content', function () {
|
||||
describe('newsletter model', function () {
|
||||
var model;
|
||||
|
||||
beforeEach(function () {
|
||||
model = new ContentComponent.NewsletterModel({
|
||||
body: {
|
||||
globalStyles: {
|
||||
style1: 'style1Value',
|
||||
style2: 'style2Value',
|
||||
},
|
||||
content: {
|
||||
data1: 'data1Value',
|
||||
data2: 'data2Value',
|
||||
},
|
||||
},
|
||||
subject: 'my test subject',
|
||||
});
|
||||
});
|
||||
|
||||
it('triggers autosave on change', function () {
|
||||
var mock = sinon
|
||||
.mock({ trigger: function () {} })
|
||||
.expects('trigger')
|
||||
.once()
|
||||
.withArgs('autoSave');
|
||||
global.stubChannel(App, {
|
||||
trigger: mock,
|
||||
});
|
||||
model.set('subject', 'another test subject');
|
||||
mock.verify();
|
||||
});
|
||||
|
||||
it('does not include styles and content properties in its JSON', function () {
|
||||
var json = model.toJSON();
|
||||
expect(json).to.deep.equal({ subject: 'my test subject' });
|
||||
});
|
||||
|
||||
describe('toJSON()', function () {
|
||||
it('will only contain properties modifiable by the editor', function () {
|
||||
var json;
|
||||
model = new ContentComponent.NewsletterModel({
|
||||
id: 19,
|
||||
subject: 'some subject',
|
||||
preheader: 'some preheader',
|
||||
segments: [1, 2, 3],
|
||||
modified_at: '2000-01-01 12:01:02',
|
||||
someField: 'someValue',
|
||||
});
|
||||
|
||||
json = model.toJSON();
|
||||
expect(json.id).to.equal(19);
|
||||
expect(json.subject).to.equal('some subject');
|
||||
expect(json.preheader).to.equal('some preheader');
|
||||
expect(json).to.not.include.keys(
|
||||
'segments',
|
||||
'modified_at',
|
||||
'someField',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('block types', function () {
|
||||
it('registers a block type view and model', function () {
|
||||
var blockModel = new Backbone.SuperModel();
|
||||
var blockView = new Backbone.View();
|
||||
ContentComponent.registerBlockType('testType', {
|
||||
blockModel: blockModel,
|
||||
blockView: blockView,
|
||||
});
|
||||
expect(ContentComponent.getBlockTypeModel('testType')).to.deep.equal(
|
||||
blockModel,
|
||||
);
|
||||
expect(ContentComponent.getBlockTypeView('testType')).to.deep.equal(
|
||||
blockView,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformation to json', function () {
|
||||
it('includes content, globalStyles and initial newsletter fields', function () {
|
||||
var json;
|
||||
var dataField = {
|
||||
containerModelField: 'containerModelValue',
|
||||
};
|
||||
var stylesField = {
|
||||
globalStylesField: 'globalStylesValue',
|
||||
};
|
||||
var newsletterFields = {
|
||||
subject: 'test newsletter subject',
|
||||
};
|
||||
var blockDefaults = {
|
||||
button: {},
|
||||
};
|
||||
App._contentContainer = {
|
||||
toJSON: function () {
|
||||
return dataField;
|
||||
},
|
||||
};
|
||||
App.getGlobalStyles = function () {
|
||||
return {
|
||||
toJSON: function () {
|
||||
return stylesField;
|
||||
},
|
||||
};
|
||||
};
|
||||
App.getNewsletter = function () {
|
||||
return {
|
||||
toJSON: function () {
|
||||
return newsletterFields;
|
||||
},
|
||||
};
|
||||
};
|
||||
App.getConfig().set('blockDefaults', blockDefaults);
|
||||
json = ContentComponent.toJSON();
|
||||
expect(json).to.deep.equal(
|
||||
_.extend(
|
||||
{
|
||||
body: {
|
||||
content: dataField,
|
||||
globalStyles: stylesField,
|
||||
blockDefaults: blockDefaults,
|
||||
},
|
||||
},
|
||||
newsletterFields,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,70 @@
|
||||
import { HeadingComponent } from 'newsletter_editor/components/heading';
|
||||
|
||||
const expect = global.expect;
|
||||
const Backbone = global.Backbone;
|
||||
|
||||
describe('Heading', function () {
|
||||
describe('view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
var model = new Backbone.SuperModel({
|
||||
subject: 'a test subject',
|
||||
});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new HeadingComponent.HeadingView({
|
||||
model: model,
|
||||
});
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
|
||||
describe('once rendered', function () {
|
||||
var model;
|
||||
beforeEach(function () {
|
||||
model = new Backbone.SuperModel({
|
||||
subject: 'a test subject',
|
||||
preheader: 'a test preheader',
|
||||
});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new HeadingComponent.HeadingView({
|
||||
model: model,
|
||||
});
|
||||
view.render();
|
||||
});
|
||||
|
||||
it('changes the model when subject field is changed', function () {
|
||||
view
|
||||
.$('.mailpoet_input_title')
|
||||
.val('a new testing subject')
|
||||
.trigger('change');
|
||||
expect(model.get('subject')).to.equal('a new testing subject');
|
||||
});
|
||||
|
||||
it('changes the model when preheader field is changed', function () {
|
||||
view
|
||||
.$('.mailpoet_input_preheader')
|
||||
.val('a new testing preheader')
|
||||
.trigger('change');
|
||||
expect(model.get('preheader')).to.equal('a new testing preheader');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,16 @@
|
||||
import { HistoryComponent } from 'newsletter_editor/components/history';
|
||||
|
||||
const expect = global.expect;
|
||||
|
||||
describe('History', function () {
|
||||
describe('view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
view = new HistoryComponent.HistoryView();
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,353 @@
|
||||
import { App } from 'newsletter_editor/App';
|
||||
import { SaveComponent } from 'newsletter_editor/components/save';
|
||||
import jQuery from 'jquery';
|
||||
|
||||
/* (ES6 -> CommonJS transform needed for inject-loader) */
|
||||
/* eslint-disable-next-line max-len */
|
||||
import SaveInjector from 'inject-loader!babel-loader?plugins[]=@babel/plugin-transform-modules-commonjs!newsletter_editor/components/save';
|
||||
|
||||
const expect = global.expect;
|
||||
const sinon = global.sinon;
|
||||
const Backbone = global.Backbone;
|
||||
|
||||
describe('Save', function () {
|
||||
describe('save method', function () {
|
||||
var module;
|
||||
before(function () {
|
||||
module = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
CommunicationComponent: {
|
||||
saveNewsletter: function () {
|
||||
return jQuery.Deferred();
|
||||
},
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
});
|
||||
|
||||
it('triggers beforeEditorSave event', function () {
|
||||
var spy = sinon.spy();
|
||||
global.stubChannel(App, {
|
||||
trigger: spy,
|
||||
});
|
||||
App.toJSON = sinon.stub().returns({
|
||||
body: {
|
||||
type: 'container',
|
||||
},
|
||||
});
|
||||
module.save();
|
||||
expect(spy).to.have.callCount(1);
|
||||
expect(spy).to.have.been.calledWith('beforeEditorSave');
|
||||
});
|
||||
|
||||
it('triggers afterEditorSave event', function () {
|
||||
var innerModule;
|
||||
var spy = sinon.spy();
|
||||
var promise = jQuery.Deferred();
|
||||
global.stubChannel(App, {
|
||||
trigger: spy,
|
||||
});
|
||||
App.toJSON = sinon.stub().returns({
|
||||
body: {
|
||||
type: 'container',
|
||||
},
|
||||
});
|
||||
innerModule = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
CommunicationComponent: {
|
||||
saveNewsletter: sinon.stub().returns(promise),
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
promise.resolve({ success: true });
|
||||
innerModule.save();
|
||||
expect(spy.withArgs('afterEditorSave').calledOnce).to.be.true; // eslint-disable-line no-unused-expressions
|
||||
});
|
||||
|
||||
it('sends newsletter json to server for saving', function () {
|
||||
var mock = sinon.mock().once().returns(jQuery.Deferred());
|
||||
var innerModule = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
CommunicationComponent: {
|
||||
saveNewsletter: mock,
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
global.stubChannel(App);
|
||||
|
||||
App.toJSON = sinon.stub().returns({});
|
||||
innerModule.save();
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
|
||||
it('encodes newsletter body in JSON format', function () {
|
||||
var innerModule;
|
||||
var body = { type: 'testType' };
|
||||
var mock = sinon
|
||||
.mock()
|
||||
.once()
|
||||
.withArgs({
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.returns(jQuery.Deferred());
|
||||
global.stubChannel(App);
|
||||
|
||||
App.toJSON = sinon.stub().returns({
|
||||
body: body,
|
||||
});
|
||||
innerModule = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
CommunicationComponent: {
|
||||
saveNewsletter: mock,
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
innerModule.save();
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('view', function () {
|
||||
var validNewsletter = {
|
||||
body: {
|
||||
content: {
|
||||
blocks: [{ type: 'footer' }],
|
||||
},
|
||||
},
|
||||
};
|
||||
before(function () {
|
||||
var newsletter = {
|
||||
get: sinon.stub().withArgs('type').returns('newsletter'),
|
||||
};
|
||||
App._contentContainer = {
|
||||
isValid: sinon.stub().returns(true),
|
||||
};
|
||||
global.stubConfig(App);
|
||||
App.getNewsletter = sinon.stub().returns(newsletter);
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
var view;
|
||||
var model = new Backbone.SuperModel({});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new SaveComponent.SaveView({ model: model });
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
|
||||
describe('validateNewsletter', function () {
|
||||
var hideValidationErrorStub;
|
||||
var view;
|
||||
var model;
|
||||
beforeEach(function () {
|
||||
model = new Backbone.SuperModel({});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new SaveComponent.SaveView({ model: model });
|
||||
hideValidationErrorStub = sinon.stub(view, 'hideValidationError');
|
||||
});
|
||||
|
||||
it('hides errors for valid newsletter', function () {
|
||||
view.validateNewsletter(validNewsletter);
|
||||
expect(hideValidationErrorStub.callCount).to.be.equal(1);
|
||||
});
|
||||
|
||||
it('hides errors for valid post notification', function () {
|
||||
var newsletter = {
|
||||
get: sinon.stub().withArgs('type').returns('notification'),
|
||||
};
|
||||
App.getNewsletter = sinon.stub().returns(newsletter);
|
||||
view.validateNewsletter({
|
||||
body: {
|
||||
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');
|
||||
App.getNewsletter = sinon.stub().returns(newsletter);
|
||||
view.validateNewsletter(validNewsletter);
|
||||
expect(showValidationErrorStub.callCount).to.be.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('once rendered', function () {
|
||||
var view;
|
||||
var model;
|
||||
beforeEach(function () {
|
||||
App._contentContainer = {
|
||||
isValid: sinon.stub().returns(true),
|
||||
};
|
||||
model = new Backbone.SuperModel({});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new SaveComponent.SaveView({ model: model });
|
||||
view.render();
|
||||
});
|
||||
|
||||
it('triggers newsletter saving when clicked on save button', function () {
|
||||
var mock = sinon
|
||||
.mock({ request: function () {} })
|
||||
.expects('request')
|
||||
.once()
|
||||
.withArgs('save');
|
||||
global.stubChannel(App, {
|
||||
request: mock,
|
||||
});
|
||||
view.$('.mailpoet_save_button').trigger('click');
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
|
||||
it('displays saving options when clicked on save options button', function () {
|
||||
view.$('.mailpoet_save_show_options').trigger('click');
|
||||
expect(view.$('.mailpoet_save_options')).to.not.have.$class(
|
||||
'mailpoet_hidden',
|
||||
);
|
||||
});
|
||||
|
||||
it('triggers template saving when clicked on "save as template" button', function () {
|
||||
var mock = sinon
|
||||
.mock({ post: function () {} })
|
||||
.expects('post')
|
||||
.once()
|
||||
.returns(jQuery.Deferred());
|
||||
var promiseMock = {};
|
||||
var module;
|
||||
|
||||
promiseMock.then = function (cb) {
|
||||
cb();
|
||||
return promiseMock;
|
||||
};
|
||||
promiseMock.catch = promiseMock.then;
|
||||
|
||||
App.getBody = sinon.stub();
|
||||
App.getNewsletter = function () {
|
||||
return {
|
||||
get: function () {
|
||||
return 'standard';
|
||||
},
|
||||
};
|
||||
};
|
||||
module = SaveInjector({
|
||||
mailpoet: {
|
||||
MailPoet: {
|
||||
Ajax: {
|
||||
post: mock,
|
||||
},
|
||||
I18n: {
|
||||
t: function () {
|
||||
return '';
|
||||
},
|
||||
},
|
||||
Notice: {
|
||||
success: function () {},
|
||||
error: function () {},
|
||||
},
|
||||
trackEvent: function () {},
|
||||
},
|
||||
},
|
||||
'newsletter_editor/App': { App },
|
||||
common: {
|
||||
fromNewsletter: function () {
|
||||
return promiseMock;
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
model = new Backbone.SuperModel({});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new module.SaveView({ model: model });
|
||||
view.render();
|
||||
|
||||
view.$('.mailpoet_save_as_template_name').val('A sample template');
|
||||
view
|
||||
.$('.mailpoet_save_as_template_description')
|
||||
.val('Sample template description');
|
||||
view.$('.mailpoet_save_as_template').trigger('click');
|
||||
|
||||
mock.verify();
|
||||
});
|
||||
|
||||
it('saves newsletter when clicked on "next" button', function () {
|
||||
var spy = sinon.spy();
|
||||
var module = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
CommunicationComponent: {
|
||||
saveNewsletter: function () {
|
||||
return jQuery.Deferred();
|
||||
},
|
||||
},
|
||||
},
|
||||
}).SaveComponent;
|
||||
global.stubChannel(App, {
|
||||
trigger: spy,
|
||||
});
|
||||
model = new Backbone.SuperModel({});
|
||||
model.isWoocommerceTransactional = function () {
|
||||
return false;
|
||||
};
|
||||
model.isAutomationEmail = function () {
|
||||
return false;
|
||||
};
|
||||
model.isConfirmationEmailTemplate = function () {
|
||||
return false;
|
||||
};
|
||||
view = new module.SaveView({ model: model });
|
||||
view.render();
|
||||
|
||||
view.$('.mailpoet_save_next').trigger('click');
|
||||
expect(spy).to.have.callCount(1);
|
||||
expect(spy).to.have.been.calledWith('beforeEditorSave');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('preview view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
view = new SaveComponent.NewsletterPreviewView();
|
||||
});
|
||||
|
||||
it.skip('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,211 @@
|
||||
import { SidebarComponent } from 'newsletter_editor/components/sidebar';
|
||||
|
||||
const expect = global.expect;
|
||||
const Backbone = global.Backbone;
|
||||
|
||||
describe('Sidebar', function () {
|
||||
describe('content view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
view = new SidebarComponent.SidebarWidgetsView({
|
||||
collection: new Backbone.Collection([]),
|
||||
});
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('layout view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
view = new SidebarComponent.SidebarLayoutWidgetsView({
|
||||
collection: new Backbone.Collection([]),
|
||||
});
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('styles view', function () {
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
view = new SidebarComponent.SidebarStylesView({
|
||||
model: new Backbone.SuperModel({}),
|
||||
availableStyles: new Backbone.SuperModel({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
|
||||
describe('once rendered', function () {
|
||||
var model;
|
||||
var availableStyles;
|
||||
var innerView;
|
||||
before(function () {
|
||||
model = new Backbone.SuperModel({
|
||||
text: {
|
||||
fontColor: '#000000',
|
||||
fontFamily: 'Arial',
|
||||
},
|
||||
h1: {
|
||||
fontColor: '#000001',
|
||||
fontFamily: 'Arial',
|
||||
},
|
||||
h2: {
|
||||
fontColor: '#000002',
|
||||
fontFamily: 'Arial',
|
||||
},
|
||||
h3: {
|
||||
fontColor: '#000003',
|
||||
fontFamily: 'Arial',
|
||||
},
|
||||
link: {
|
||||
fontColor: '#000005',
|
||||
textDecoration: 'none',
|
||||
},
|
||||
wrapper: {
|
||||
backgroundColor: '#090909',
|
||||
},
|
||||
body: {
|
||||
backgroundColor: '#020202',
|
||||
},
|
||||
});
|
||||
availableStyles = new Backbone.SuperModel({
|
||||
fonts: {
|
||||
standard: [
|
||||
'Arial',
|
||||
'Times New Roman',
|
||||
'Tahoma',
|
||||
'Comic Sans',
|
||||
'Lucida',
|
||||
],
|
||||
custom: [
|
||||
'Arvo',
|
||||
'Lato',
|
||||
'Lora',
|
||||
'Merriweather',
|
||||
'Merriweather Sans',
|
||||
'Noticia Text',
|
||||
'Open Sans',
|
||||
'Playfair Display',
|
||||
'Roboto',
|
||||
'Source Sans Pro',
|
||||
],
|
||||
},
|
||||
textSizes: ['9px', '10px'],
|
||||
headingSizes: ['10px', '12px', '14px', '16px', '18px'],
|
||||
});
|
||||
innerView = new SidebarComponent.SidebarStylesView({
|
||||
model: model,
|
||||
availableStyles: availableStyles,
|
||||
});
|
||||
|
||||
innerView.render();
|
||||
});
|
||||
|
||||
it('changes model if text font color field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_text_font_color')
|
||||
.val('#123456')
|
||||
.trigger('change');
|
||||
expect(model.get('text.fontColor')).to.equal('#123456');
|
||||
});
|
||||
|
||||
it('changes model if h1 font color field changes', function () {
|
||||
innerView.$('#mailpoet_h1_font_color').val('#123457').trigger('change');
|
||||
expect(model.get('h1.fontColor')).to.equal('#123457');
|
||||
});
|
||||
|
||||
it('changes model if h2 font color field changes', function () {
|
||||
innerView.$('#mailpoet_h2_font_color').val('#123458').trigger('change');
|
||||
expect(model.get('h2.fontColor')).to.equal('#123458');
|
||||
});
|
||||
|
||||
it('changes model if h3 font color field changes', function () {
|
||||
innerView.$('#mailpoet_h3_font_color').val('#123426').trigger('change');
|
||||
expect(model.get('h3.fontColor')).to.equal('#123426');
|
||||
});
|
||||
|
||||
it('changes model if link font color field changes', function () {
|
||||
innerView.$('#mailpoet_a_font_color').val('#323232').trigger('change');
|
||||
expect(model.get('link.fontColor')).to.equal('#323232');
|
||||
});
|
||||
|
||||
it('changes model if newsletter background color field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_newsletter_background_color')
|
||||
.val('#636237')
|
||||
.trigger('change');
|
||||
expect(model.get('wrapper.backgroundColor')).to.equal('#636237');
|
||||
});
|
||||
|
||||
it('changes model if background color field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_background_color')
|
||||
.val('#878587')
|
||||
.trigger('change');
|
||||
expect(model.get('body.backgroundColor')).to.equal('#878587');
|
||||
});
|
||||
|
||||
it('changes model if text font family field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_text_font_family')
|
||||
.val('Times New Roman')
|
||||
.trigger('change');
|
||||
expect(model.get('text.fontFamily')).to.equal('Times New Roman');
|
||||
});
|
||||
|
||||
it('changes model if h1 font family field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_h1_font_family')
|
||||
.val('Comic Sans')
|
||||
.trigger('change');
|
||||
expect(model.get('h1.fontFamily')).to.equal('Comic Sans');
|
||||
});
|
||||
|
||||
it('changes model if h2 font family field changes', function () {
|
||||
innerView.$('#mailpoet_h2_font_family').val('Tahoma').trigger('change');
|
||||
expect(model.get('h2.fontFamily')).to.equal('Tahoma');
|
||||
});
|
||||
|
||||
it('changes model if h3 font family field changes', function () {
|
||||
innerView.$('#mailpoet_h3_font_family').val('Lucida').trigger('change');
|
||||
expect(model.get('h3.fontFamily')).to.equal('Lucida');
|
||||
});
|
||||
|
||||
it('changes model if text font size field changes', function () {
|
||||
innerView.$('#mailpoet_text_font_size').val('9px').trigger('change');
|
||||
expect(model.get('text.fontSize')).to.equal('9px');
|
||||
});
|
||||
|
||||
it('changes model if h1 font size field changes', function () {
|
||||
innerView.$('#mailpoet_h1_font_size').val('12px').trigger('change');
|
||||
expect(model.get('h1.fontSize')).to.equal('12px');
|
||||
});
|
||||
|
||||
it('changes model if h2 font size field changes', function () {
|
||||
innerView.$('#mailpoet_h2_font_size').val('14px').trigger('change');
|
||||
expect(model.get('h2.fontSize')).to.equal('14px');
|
||||
});
|
||||
|
||||
it('changes model if h3 font size field changes', function () {
|
||||
innerView.$('#mailpoet_h3_font_size').val('16px').trigger('change');
|
||||
expect(model.get('h3.fontSize')).to.equal('16px');
|
||||
});
|
||||
|
||||
it('changes model if link underline field changes', function () {
|
||||
innerView
|
||||
.$('#mailpoet_a_font_underline')
|
||||
.prop('checked', true)
|
||||
.trigger('change');
|
||||
expect(model.get('link.textDecoration')).to.equal('underline');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,52 @@
|
||||
import { App } from 'newsletter_editor/App';
|
||||
import { StylesComponent } from 'newsletter_editor/components/styles';
|
||||
|
||||
const expect = global.expect;
|
||||
const sinon = global.sinon;
|
||||
|
||||
describe('Styles', function () {
|
||||
it('loads and stores globally available styles', function () {
|
||||
var model;
|
||||
StylesComponent.setGlobalStyles({
|
||||
testStyle: 'testValue',
|
||||
});
|
||||
model = StylesComponent.getGlobalStyles();
|
||||
expect(model.get('testStyle')).to.equal('testValue');
|
||||
});
|
||||
|
||||
describe('model', function () {
|
||||
var model;
|
||||
beforeEach(function () {
|
||||
model = new StylesComponent.StylesModel();
|
||||
});
|
||||
|
||||
it('triggers autoSave when changed', function () {
|
||||
var mock = sinon
|
||||
.mock({ trigger: function () {} })
|
||||
.expects('trigger')
|
||||
.once()
|
||||
.withExactArgs('autoSave');
|
||||
App.getChannel = function () {
|
||||
return {
|
||||
on: function () {},
|
||||
trigger: mock,
|
||||
};
|
||||
};
|
||||
model.set('text.fontColor', '#123456');
|
||||
mock.verify();
|
||||
});
|
||||
});
|
||||
|
||||
describe('view', function () {
|
||||
var model;
|
||||
var view;
|
||||
beforeEach(function () {
|
||||
model = new StylesComponent.StylesModel();
|
||||
view = new StylesComponent.StylesView({ model: model });
|
||||
});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user