Tests space-before-function-paren

This commit is contained in:
Amine Ben hammou
2017-09-27 15:41:06 +00:00
parent bb8591a67b
commit 68165b7b78
20 changed files with 202 additions and 203 deletions

View File

@ -18,7 +18,6 @@
"no-shadow": 0, "no-shadow": 0,
"padded-blocks": 0, "padded-blocks": 0,
"object-curly-spacing": 0, "object-curly-spacing": 0,
"func-names": 0, "func-names": 0
"space-before-function-paren": 0
} }
} }

View File

@ -52,9 +52,9 @@ global.interact = function () {
styleCursor: global.interact styleCursor: global.interact
}; };
}; };
global.spectrum = function() { return this; }; global.spectrum = function () { return this; };
jQuery.fn.spectrum = global.spectrum; jQuery.fn.spectrum = global.spectrum;
jQuery.fn.stick_in_parent = function() { return this; }; jQuery.fn.stick_in_parent = function () { return this; };
// Add global stubs for convenience // Add global stubs for convenience
// TODO: Extract those to a separate file // TODO: Extract those to a separate file
@ -78,18 +78,18 @@ global.stubAvailableStyles = function (EditorApplication, styles) {
App.getAvailableStyles = sinon.stub().returns(new global.Backbone.SuperModel(styles || {})); App.getAvailableStyles = sinon.stub().returns(new global.Backbone.SuperModel(styles || {}));
}; };
global.stubImage = function(defaultWidth, defaultHeight) { global.stubImage = function (defaultWidth, defaultHeight) {
global.Image = function() { global.Image = function () {
this.onload = function() {}; this.onload = function () {};
this.naturalWidth = defaultWidth; this.naturalWidth = defaultWidth;
this.naturalHeight = defaultHeight; this.naturalHeight = defaultHeight;
this.address = ''; this.address = '';
Object.defineProperty(this, 'src', { Object.defineProperty(this, 'src', {
get: function() { get: function () {
return this.address; return this.address;
}, },
set: function(src) { set: function (src) {
this.address = src; this.address = src;
this.onload(); this.onload();
} }

View File

@ -9,7 +9,7 @@ define([
'newsletter_editor/blocks/container', 'newsletter_editor/blocks/container',
'amd-inject-loader!newsletter_editor/blocks/automatedLatestContent', 'amd-inject-loader!newsletter_editor/blocks/automatedLatestContent',
'newsletter_editor/components/communication' 'newsletter_editor/components/communication'
], function( ], function (
App, App,
AutomatedLatestContentBlock, AutomatedLatestContentBlock,
ContainerBlock, ContainerBlock,
@ -19,19 +19,19 @@ define([
var EditorApplication = App; var EditorApplication = App;
var CommunicationComponent = Communication; var CommunicationComponent = Communication;
describe('Automated Latest Content Supervisor', function() { describe('Automated Latest Content Supervisor', function () {
var model; var model;
var mock; var mock;
var module; var module;
beforeEach(function() { beforeEach(function () {
model = new AutomatedLatestContentBlock.ALCSupervisor(); model = new AutomatedLatestContentBlock.ALCSupervisor();
}); });
it('fetches posts in bulk from the server', function() { it('fetches posts in bulk from the server', function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
EditorApplication.findModels = sinon.stub().returns([new Backbone.SuperModel()]); EditorApplication.findModels = sinon.stub().returns([new Backbone.SuperModel()]);
mock = sinon.mock({ getBulkTransformedPosts: function() {} }) mock = sinon.mock({ getBulkTransformedPosts: function () {} })
.expects('getBulkTransformedPosts').once().returns(jQuery.Deferred()); .expects('getBulkTransformedPosts').once().returns(jQuery.Deferred());
module = AutomatedLatestContentInjector({ module = AutomatedLatestContentInjector({
@ -46,7 +46,7 @@ define([
mock.verify(); mock.verify();
}); });
it('refreshes posts for given blocks', function() { it('refreshes posts for given blocks', function () {
var block1 = new Backbone.SuperModel(); var block1 = new Backbone.SuperModel();
var block2 = new Backbone.SuperModel(); var block2 = new Backbone.SuperModel();
var postsSet1 = [ var postsSet1 = [
@ -74,7 +74,7 @@ define([
var model; var model;
var module; var module;
before(function() { before(function () {
module = AutomatedLatestContentBlock; module = AutomatedLatestContentBlock;
}); });
@ -254,7 +254,7 @@ define([
expect(model.get('divider.styles.block.padding')).to.equal('38px'); expect(model.get('divider.styles.block.padding')).to.equal('38px');
}); });
it('accepts displayable posts', function() { it('accepts displayable posts', function () {
var model; var model;
EditorApplication.getBlockTypeModel = sinon.stub().returns(ContainerBlock.ContainerBlockModel); EditorApplication.getBlockTypeModel = sinon.stub().returns(ContainerBlock.ContainerBlockModel);
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
@ -273,7 +273,7 @@ define([
var view; var view;
var module; var module;
before(function() { before(function () {
module = AutomatedLatestContentBlock; module = AutomatedLatestContentBlock;
}); });
@ -334,10 +334,10 @@ define([
var view; var view;
var module; var module;
before(function() { before(function () {
module = AutomatedLatestContentInjector({ module = AutomatedLatestContentInjector({
'newsletter_editor/components/communication': { 'newsletter_editor/components/communication': {
getPostTypes: function() { getPostTypes: function () {
return jQuery.Deferred(); return jQuery.Deferred();
} }
} }
@ -345,7 +345,7 @@ define([
}); });
before(function () { before(function () {
CommunicationComponent.getPostTypes = function() { CommunicationComponent.getPostTypes = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve([ deferred.resolve([
{ {
@ -378,7 +378,7 @@ define([
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View); EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
}); });
beforeEach(function() { beforeEach(function () {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
}); });
@ -392,7 +392,7 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
beforeEach(function() { beforeEach(function () {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
view.render(); view.render();
@ -500,10 +500,10 @@ define([
expect(model.get('showDivider')).to.equal(newValue); expect(model.get('showDivider')).to.equal(newValue);
}); });
describe('when "title only" display type is selected', function() { describe('when "title only" display type is selected', function () {
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
view.render(); view.render();
@ -514,10 +514,10 @@ define([
expect(view.$('.mailpoet_automated_latest_content_title_as_list')).to.not.have.$class('mailpoet_hidden'); expect(view.$('.mailpoet_automated_latest_content_title_as_list')).to.not.have.$class('mailpoet_hidden');
}); });
describe('when "title as list" is selected', function() { describe('when "title as list" is selected', function () {
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
view.render(); view.render();
@ -530,14 +530,14 @@ define([
expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.have.$class('mailpoet_hidden'); expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.have.$class('mailpoet_hidden');
}); });
it('is set to "yes"', function() { it('is set to "yes"', function () {
expect(model.get('titleIsLink')).to.equal(true); expect(model.get('titleIsLink')).to.equal(true);
}); });
}); });
}); });
describe('when "title as list" is deselected', function() { describe('when "title as list" is deselected', function () {
before(function() { before(function () {
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change(); view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
view.$('.mailpoet_automated_latest_content_title_format').val('h3').change(); view.$('.mailpoet_automated_latest_content_title_format').val('h3').change();
}); });

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/button' 'newsletter_editor/blocks/button'
], function(App, ButtonBlock) { ], function (App, ButtonBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Button', function () { describe('Button', function () {
@ -322,7 +322,7 @@ define([
describe('once rendered', function () { describe('once rendered', function () {
var model; var model;
var view; var view;
before(function() { before(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {
@ -331,7 +331,7 @@ define([
}); });
}); });
beforeEach(function() { beforeEach(function () {
model = new (ButtonBlock.ButtonBlockModel)({ model = new (ButtonBlock.ButtonBlockModel)({
type: 'button', type: 'button',
text: 'Some random text' text: 'Some random text'
@ -453,7 +453,7 @@ define([
expect(view.$('.mailpoet_field_button_line_height_input').val()).to.equal('37'); expect(view.$('.mailpoet_field_button_line_height_input').val()).to.equal('37');
}); });
it('does not display link option when `hideLink` option is active', function() { it('does not display link option when `hideLink` option is active', function () {
view = new (ButtonBlock.ButtonBlockSettingsView)({ view = new (ButtonBlock.ButtonBlockSettingsView)({
model: model, model: model,
renderOptions: { renderOptions: {
@ -464,7 +464,7 @@ define([
expect(view.$('.mailpoet_field_button_url').length).to.equal(0); expect(view.$('.mailpoet_field_button_url').length).to.equal(0);
}); });
it('does not display "Apply to all" option when `hideApplyToAll` option is active', function() { it('does not display "Apply to all" option when `hideApplyToAll` option is active', function () {
view = new (ButtonBlock.ButtonBlockSettingsView)({ view = new (ButtonBlock.ButtonBlockSettingsView)({
model: model, model: model,
renderOptions: { renderOptions: {

View File

@ -5,7 +5,7 @@ const Backbone = global.Backbone;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/container' 'newsletter_editor/blocks/container'
], function(App, ContainerBlock) { ], function (App, ContainerBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Container', function () { describe('Container', function () {
@ -205,7 +205,7 @@ define([
describe('once rendered', function () { describe('once rendered', function () {
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
model = new (ContainerBlock.ContainerBlockModel)(); model = new (ContainerBlock.ContainerBlockModel)();

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/divider' 'newsletter_editor/blocks/divider'
], function(App, DividerBlock) { ], function (App, DividerBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Divider', function () { describe('Divider', function () {
@ -157,7 +157,7 @@ define([
var model; var model;
var view; var view;
before(function() { before(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {
dividers: ['solid', 'inset'] dividers: ['solid', 'inset']
@ -200,13 +200,13 @@ define([
expect(model.get('styles.block.backgroundColor')).to.equal('#cccccc'); expect(model.get('styles.block.backgroundColor')).to.equal('#cccccc');
}); });
it('changes color of available divider styles when actual divider color changes', function() { it('changes color of available divider styles when actual divider color changes', function () {
var newColor = '#889912'; var newColor = '#889912';
view.$('.mailpoet_field_divider_border_color').val(newColor).change(); view.$('.mailpoet_field_divider_border_color').val(newColor).change();
expect(view.$('.mailpoet_field_divider_style div')).to.have.$css('border-top-color', newColor); expect(view.$('.mailpoet_field_divider_style div')).to.have.$css('border-top-color', newColor);
}); });
it('does not display "Apply to all" option when `hideApplyToAll` option is active', function() { it('does not display "Apply to all" option when `hideApplyToAll` option is active', function () {
view = new (DividerBlock.DividerBlockSettingsView)({ view = new (DividerBlock.DividerBlockSettingsView)({
model: model, model: model,
renderOptions: { renderOptions: {

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/footer' 'newsletter_editor/blocks/footer'
], function(App, FooterBlock) { ], function (App, FooterBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Footer', function () { describe('Footer', function () {
@ -155,7 +155,7 @@ define([
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'], fonts: ['Arial', 'Tahoma'],

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/header' 'newsletter_editor/blocks/header'
], function(App, HeaderBlock) { ], function (App, HeaderBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Header', function () { describe('Header', function () {
@ -155,7 +155,7 @@ define([
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'], fonts: ['Arial', 'Tahoma'],

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/image' 'newsletter_editor/blocks/image'
], function(App, ImageBlock) { ], function (App, ImageBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Image', function () { describe('Image', function () {

View File

@ -8,7 +8,7 @@ define([
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'newsletter_editor/blocks/posts', 'newsletter_editor/blocks/posts',
'newsletter_editor/blocks/container' 'newsletter_editor/blocks/container'
], function(App, Communication, PostsBlock, ContainerBlock) { ], function (App, Communication, PostsBlock, ContainerBlock) {
var EditorApplication = App; var EditorApplication = App;
var CommunicationComponent = Communication; var CommunicationComponent = Communication;
@ -24,8 +24,8 @@ define([
describe('model', function () { describe('model', function () {
var model; var model;
before(function() { before(function () {
CommunicationComponent.getPosts = function() { CommunicationComponent.getPosts = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
return deferred; return deferred;
}; };
@ -238,7 +238,7 @@ define([
}); });
it('triggers loading and loaded events for more posts', function () { it('triggers loading and loaded events for more posts', function () {
var stub = sinon.stub(CommunicationComponent, 'getPosts', function() { var stub = sinon.stub(CommunicationComponent, 'getPosts', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve([{}]); // 1 post deferred.resolve([{}]); // 1 post
return deferred; return deferred;
@ -291,7 +291,7 @@ define([
var view; var view;
before(function () { before(function () {
CommunicationComponent.getPostTypes = function() { CommunicationComponent.getPostTypes = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve([ deferred.resolve([
{ {
@ -423,10 +423,10 @@ define([
expect(model.get('readMoreText')).to.equal(newValue); expect(model.get('readMoreText')).to.equal(newValue);
}); });
describe('when "title only" display type is selected', function() { describe('when "title only" display type is selected', function () {
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
model = new (PostsBlock.PostsBlockModel)(); model = new (PostsBlock.PostsBlockModel)();
model.request = sinon.stub().returns({$el: {}}); model.request = sinon.stub().returns({$el: {}});
view = new (PostsBlock.PostsBlockSettingsView)({model: model}); view = new (PostsBlock.PostsBlockSettingsView)({model: model});
@ -438,8 +438,8 @@ define([
expect(view.$('.mailpoet_posts_title_as_list')).to.not.have.$class('mailpoet_hidden'); expect(view.$('.mailpoet_posts_title_as_list')).to.not.have.$class('mailpoet_hidden');
}); });
describe('when "title as list" is selected', function() { describe('when "title as list" is selected', function () {
beforeEach(function() { beforeEach(function () {
view.$('.mailpoet_posts_display_type').val('titleOnly').change(); view.$('.mailpoet_posts_display_type').val('titleOnly').change();
view.$('.mailpoet_posts_title_format').val('ul').change(); view.$('.mailpoet_posts_title_format').val('ul').change();
}); });
@ -449,14 +449,14 @@ define([
expect(view.$('.mailpoet_posts_title_as_link')).to.have.$class('mailpoet_hidden'); expect(view.$('.mailpoet_posts_title_as_link')).to.have.$class('mailpoet_hidden');
}); });
it('is set to "yes"', function() { it('is set to "yes"', function () {
expect(model.get('titleIsLink')).to.equal(true); expect(model.get('titleIsLink')).to.equal(true);
}); });
}); });
}); });
describe('when "title as list" is deselected', function() { describe('when "title as list" is deselected', function () {
before(function() { before(function () {
view.$('.mailpoet_posts_title_format').val('ul').change(); view.$('.mailpoet_posts_title_format').val('ul').change();
view.$('.mailpoet_posts_title_format').val('h3').change(); view.$('.mailpoet_posts_title_format').val('h3').change();
}); });

View File

@ -5,7 +5,7 @@ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/social', 'newsletter_editor/blocks/social',
'backbone' 'backbone'
], function(EditorApplication, SocialBlock, Backbone) { ], function (EditorApplication, SocialBlock, Backbone) {
describe('Social', function () { describe('Social', function () {
describe('block model', function () { describe('block model', function () {
@ -257,18 +257,18 @@ define([
view.render(); view.render();
}); });
it('updates icons in settings if iconset changes', function() { it('updates icons in settings if iconset changes', function () {
view.$('.mailpoet_social_icon_set').last().click(); view.$('.mailpoet_social_icon_set').last().click();
expect(view.$('.mailpoet_social_icon_field_image').val()).to.equal(EditorApplication.getAvailableStyles().get('socialIconSets.light.custom')); expect(view.$('.mailpoet_social_icon_field_image').val()).to.equal(EditorApplication.getAvailableStyles().get('socialIconSets.light.custom'));
}); });
it('removes the icon when "remove" is clicked', function() { it('removes the icon when "remove" is clicked', function () {
view.$('.mailpoet_delete_block').click(); view.$('.mailpoet_delete_block').click();
expect(model.get('icons').length).to.equal(0); expect(model.get('icons').length).to.equal(0);
expect(view.$('.mailpoet_social_icon_settings').length).to.equal(0); expect(view.$('.mailpoet_social_icon_settings').length).to.equal(0);
}); });
it('adds another icon when "Add another social network" is pressed', function() { it('adds another icon when "Add another social network" is pressed', function () {
view.$('.mailpoet_add_social_icon').click(); view.$('.mailpoet_add_social_icon').click();
expect(model.get('icons').length).to.equal(2); expect(model.get('icons').length).to.equal(2);
}); });

View File

@ -4,7 +4,7 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/spacer' 'newsletter_editor/blocks/spacer'
], function(App, SpacerBlock) { ], function (App, SpacerBlock) {
var EditorApplication = App; var EditorApplication = App;
describe('Spacer', function () { describe('Spacer', function () {
@ -139,7 +139,7 @@ define([
describe('once rendered', function () { describe('once rendered', function () {
var view; var view;
var model; var model;
beforeEach(function() { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
model = new (SpacerBlock.SpacerBlockModel)(); model = new (SpacerBlock.SpacerBlockModel)();

View File

@ -3,7 +3,7 @@ const expect = global.expect;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/text' 'newsletter_editor/blocks/text'
], function(EditorApplication, TextBlock) { ], function (EditorApplication, TextBlock) {
describe('Text', function () { describe('Text', function () {
describe('model', function () { describe('model', function () {

View File

@ -6,14 +6,14 @@ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'amd-inject-loader!newsletter_editor/components/communication' 'amd-inject-loader!newsletter_editor/components/communication'
], function(EditorApplication, Communication, CommunicationInjector) { ], function (EditorApplication, Communication, CommunicationInjector) {
describe('getPostTypes', function() { describe('getPostTypes', function () {
it('fetches post types from the server', function() { it('fetches post types from the server', function () {
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: function() { post: function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
data: { data: {
@ -26,14 +26,14 @@ define([
} }
} }
}); });
module.getPostTypes().done(function(types) { module.getPostTypes().done(function (types) {
expect(types).to.eql(['val1', 'val2']); expect(types).to.eql(['val1', 'val2']);
}); });
}); });
it('caches results', function() { it('caches results', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred); var mock = sinon.mock({ post: function () {} }).expects('post').once().returns(deferred);
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
@ -52,10 +52,10 @@ define([
}); });
}); });
describe('getTaxonomies', function() { describe('getTaxonomies', function () {
it('sends post type to endpoint', function() { it('sends post type to endpoint', function () {
var spy; var spy;
var post = function() { var post = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
category: 'val1', category: 'val1',
@ -77,11 +77,11 @@ define([
expect(spy.args[0][0].data.postType).to.equal('post'); expect(spy.args[0][0].data.postType).to.equal('post');
}); });
it('fetches taxonomies from the server', function() { it('fetches taxonomies from the server', function () {
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: function() { post: function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
data: { data: {
@ -93,14 +93,14 @@ define([
} }
} }
}); });
module.getTaxonomies('page').done(function(types) { module.getTaxonomies('page').done(function (types) {
expect(types).to.eql({ category: 'val1' }); expect(types).to.eql({ category: 'val1' });
}); });
}); });
it('caches results', function() { it('caches results', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred); var mock = sinon.mock({ post: function () {} }).expects('post').once().returns(deferred);
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
@ -116,10 +116,10 @@ define([
}); });
}); });
describe('getTerms', function() { describe('getTerms', function () {
it('sends terms to endpoint', function() { it('sends terms to endpoint', function () {
var spy; var spy;
var post = function() { var post = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({}); deferred.resolve({});
return deferred; return deferred;
@ -140,11 +140,11 @@ define([
expect(spy.args[0][0].data.taxonomies).to.eql(['category', 'post_tag']); expect(spy.args[0][0].data.taxonomies).to.eql(['category', 'post_tag']);
}); });
it('fetches terms from the server', function() { it('fetches terms from the server', function () {
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: function() { post: function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
data: { data: {
@ -157,14 +157,14 @@ define([
} }
} }
}); });
module.getTerms({ taxonomies: ['category'] }).done(function(types) { module.getTerms({ taxonomies: ['category'] }).done(function (types) {
expect(types).to.eql({ term1: 'term1val1', term2: 'term2val2' }); expect(types).to.eql({ term1: 'term1val1', term2: 'term2val2' });
}); });
}); });
it('caches results', function() { it('caches results', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred); var mock = sinon.mock({ post: function () {} }).expects('post').once().returns(deferred);
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
@ -180,10 +180,10 @@ define([
}); });
}); });
describe('getPosts', function() { describe('getPosts', function () {
it('sends options to endpoint', function() { it('sends options to endpoint', function () {
var spy; var spy;
var post = function() { var post = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({}); deferred.resolve({});
return deferred; return deferred;
@ -208,11 +208,11 @@ define([
}); });
}); });
it('fetches posts from the server', function() { it('fetches posts from the server', function () {
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: function() { post: function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
data: [ data: [
@ -225,14 +225,14 @@ define([
} }
} }
}); });
module.getPosts().done(function(posts) { module.getPosts().done(function (posts) {
expect(posts).to.eql([{post_title: 'title 1'}, {post_title: 'post title 2'}]); expect(posts).to.eql([{post_title: 'title 1'}, {post_title: 'post title 2'}]);
}); });
}); });
it('caches results', function() { it('caches results', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred); var mock = sinon.mock({ post: function () {} }).expects('post').once().returns(deferred);
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
@ -251,10 +251,10 @@ define([
}); });
}); });
describe('getTransformedPosts', function() { describe('getTransformedPosts', function () {
it('sends options to endpoint', function() { it('sends options to endpoint', function () {
var spy; var spy;
var post = function() { var post = function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({}); deferred.resolve({});
return deferred; return deferred;
@ -279,11 +279,11 @@ define([
}); });
}); });
it('fetches transformed posts from the server', function() { it('fetches transformed posts from the server', function () {
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: function() { post: function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
data: [ data: [
@ -296,14 +296,14 @@ define([
} }
} }
}); });
module.getTransformedPosts().done(function(posts) { module.getTransformedPosts().done(function (posts) {
expect(posts).to.eql([{type: 'text', text: 'something'}, {type: 'text', text: 'something else'}]); expect(posts).to.eql([{type: 'text', text: 'something'}, {type: 'text', text: 'something else'}]);
}); });
}); });
it('caches results', function() { it('caches results', function () {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred); var mock = sinon.mock({ post: function () {} }).expects('post').once().returns(deferred);
var module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {

View File

@ -3,10 +3,10 @@ const expect = global.expect;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/config' 'newsletter_editor/components/config'
], function(EditorApplication, ConfigComponent) { ], function (EditorApplication, ConfigComponent) {
describe('Config', function () { describe('Config', function () {
it('loads and stores configuration', function() { it('loads and stores configuration', function () {
var model; var model;
ConfigComponent.setConfig({ ConfigComponent.setConfig({
testConfig: 'testValue' testConfig: 'testValue'

View File

@ -6,14 +6,14 @@ const _ = global._;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/content' 'newsletter_editor/components/content'
], function(App, ContentComponent) { ], function (App, ContentComponent) {
var EditorApplication = App; var EditorApplication = App;
describe('Content', function() { describe('Content', function () {
describe('newsletter model', function() { describe('newsletter model', function () {
var model; var model;
beforeEach(function() { beforeEach(function () {
model = new (ContentComponent.NewsletterModel)({ model = new (ContentComponent.NewsletterModel)({
body: { body: {
globalStyles: { globalStyles: {
@ -29,8 +29,8 @@ define([
}); });
}); });
it('triggers autosave on change', function() { it('triggers autosave on change', function () {
var mock = sinon.mock({ trigger: function() {} }).expects('trigger').once().withArgs('autoSave'); var mock = sinon.mock({ trigger: function () {} }).expects('trigger').once().withArgs('autoSave');
global.stubChannel(EditorApplication, { global.stubChannel(EditorApplication, {
trigger: mock trigger: mock
}); });
@ -38,13 +38,13 @@ define([
mock.verify(); mock.verify();
}); });
it('does not include styles and content properties in its JSON', function() { it('does not include styles and content properties in its JSON', function () {
var json = model.toJSON(); var json = model.toJSON();
expect(json).to.deep.equal({subject: 'my test subject'}); expect(json).to.deep.equal({subject: 'my test subject'});
}); });
describe('toJSON()', function() { describe('toJSON()', function () {
it('will only contain properties modifiable by the editor', function() { it('will only contain properties modifiable by the editor', function () {
var model = new (ContentComponent.NewsletterModel)({ var model = new (ContentComponent.NewsletterModel)({
id: 19, id: 19,
subject: 'some subject', subject: 'some subject',
@ -63,8 +63,8 @@ define([
}); });
}); });
describe('block types', function() { describe('block types', function () {
it('registers a block type view and model', function() { it('registers a block type view and model', function () {
var blockModel = new Backbone.SuperModel(); var blockModel = new Backbone.SuperModel();
var blockView = new Backbone.View(); var blockView = new Backbone.View();
ContentComponent.registerBlockType('testType', { ContentComponent.registerBlockType('testType', {
@ -76,8 +76,8 @@ define([
}); });
}); });
describe('transformation to json', function() { describe('transformation to json', function () {
it('includes content, globalStyles and initial newsletter fields', function() { it('includes content, globalStyles and initial newsletter fields', function () {
var json; var json;
var dataField = { var dataField = {
containerModelField: 'containerModelValue' containerModelField: 'containerModelValue'
@ -89,20 +89,20 @@ define([
subject: 'test newsletter subject' subject: 'test newsletter subject'
}; };
EditorApplication._contentContainer = { EditorApplication._contentContainer = {
toJSON: function() { toJSON: function () {
return dataField; return dataField;
} }
}; };
EditorApplication.getGlobalStyles = function() { EditorApplication.getGlobalStyles = function () {
return { return {
toJSON: function() { toJSON: function () {
return stylesField; return stylesField;
} }
}; };
}; };
EditorApplication.getNewsletter = function() { EditorApplication.getNewsletter = function () {
return { return {
toJSON: function() { toJSON: function () {
return newsletterFields; return newsletterFields;
} }
}; };

View File

@ -4,12 +4,12 @@ const Backbone = global.Backbone;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/heading' 'newsletter_editor/components/heading'
], function(EditorApplication, HeadingComponent) { ], function (EditorApplication, HeadingComponent) {
describe('Heading', function() { describe('Heading', function () {
describe('view', function() { describe('view', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
var model = new Backbone.SuperModel({ var model = new Backbone.SuperModel({
subject: 'a test subject' subject: 'a test subject'
}); });
@ -18,14 +18,14 @@ define([
}); });
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
describe('once rendered', function() { describe('once rendered', function () {
var view; var view;
var model; var model;
beforeEach(function() { beforeEach(function () {
model = new Backbone.SuperModel({ model = new Backbone.SuperModel({
subject: 'a test subject', subject: 'a test subject',
preheader: 'a test preheader' preheader: 'a test preheader'
@ -36,12 +36,12 @@ define([
view.render(); view.render();
}); });
it('changes the model when subject field is changed', function() { it('changes the model when subject field is changed', function () {
view.$('.mailpoet_input_title').val('a new testing subject').keyup(); view.$('.mailpoet_input_title').val('a new testing subject').keyup();
expect(model.get('subject')).to.equal('a new testing subject'); expect(model.get('subject')).to.equal('a new testing subject');
}); });
it('changes the model when preheader field is changed', function() { it('changes the model when preheader field is changed', function () {
view.$('.mailpoet_input_preheader').val('a new testing preheader').keyup(); view.$('.mailpoet_input_preheader').val('a new testing preheader').keyup();
expect(model.get('preheader')).to.equal('a new testing preheader'); expect(model.get('preheader')).to.equal('a new testing preheader');
}); });

View File

@ -6,23 +6,23 @@ define([
'newsletter_editor/components/save', 'newsletter_editor/components/save',
'amd-inject-loader!newsletter_editor/components/save', 'amd-inject-loader!newsletter_editor/components/save',
'jquery' 'jquery'
], function(App, SaveComponent, SaveInjector, jQuery) { ], function (App, SaveComponent, SaveInjector, jQuery) {
var EditorApplication = App; var EditorApplication = App;
describe('Save', function() { describe('Save', function () {
describe('save method', function() { describe('save method', function () {
var module; var module;
before(function() { before(function () {
module = SaveInjector({ module = SaveInjector({
'newsletter_editor/components/communication': { 'newsletter_editor/components/communication': {
saveNewsletter: function() { saveNewsletter: function () {
return jQuery.Deferred(); return jQuery.Deferred();
} }
} }
}); });
}); });
it('triggers beforeEditorSave event', function() { it('triggers beforeEditorSave event', function () {
var spy = sinon.spy(); var spy = sinon.spy();
global.stubChannel(EditorApplication, { global.stubChannel(EditorApplication, {
trigger: spy trigger: spy
@ -37,7 +37,7 @@ define([
expect(spy).to.have.been.calledWith('beforeEditorSave'); expect(spy).to.have.been.calledWith('beforeEditorSave');
}); });
it('triggers afterEditorSave event', function() { it('triggers afterEditorSave event', function () {
var module; var module;
var spy = sinon.spy(); var spy = sinon.spy();
var promise = jQuery.Deferred(); var promise = jQuery.Deferred();
@ -59,7 +59,7 @@ define([
expect(spy.withArgs('afterEditorSave').calledOnce).to.be.true;// eslint-disable-line no-unused-expressions expect(spy.withArgs('afterEditorSave').calledOnce).to.be.true;// eslint-disable-line no-unused-expressions
}); });
it('sends newsletter json to server for saving', function() { it('sends newsletter json to server for saving', function () {
var mock = sinon.mock().once().returns(jQuery.Deferred()); var mock = sinon.mock().once().returns(jQuery.Deferred());
var module = SaveInjector({ var module = SaveInjector({
'newsletter_editor/components/communication': { 'newsletter_editor/components/communication': {
@ -74,7 +74,7 @@ define([
mock.verify(); mock.verify();
}); });
it('encodes newsletter body in JSON format', function() { it('encodes newsletter body in JSON format', function () {
var module; var module;
var body = {type: 'testType'}; var body = {type: 'testType'};
var mock = sinon.mock() var mock = sinon.mock()
@ -100,28 +100,28 @@ define([
}); });
describe('view', function() { describe('view', function () {
var view; var view;
before(function() { before(function () {
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) }; EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
view = new (SaveComponent.SaveView)(); view = new (SaveComponent.SaveView)();
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
describe('once rendered', function() { describe('once rendered', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) }; EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
view = new (SaveComponent.SaveView)(); view = new (SaveComponent.SaveView)();
view.render(); view.render();
}); });
it('triggers newsletter saving when clicked on save button', function() { it('triggers newsletter saving when clicked on save button', function () {
var mock = sinon.mock({ request: function() {} }).expects('request').once().withArgs('save'); var mock = sinon.mock({ request: function () {} }).expects('request').once().withArgs('save');
global.stubChannel(EditorApplication, { global.stubChannel(EditorApplication, {
request: mock request: mock
}); });
@ -130,19 +130,19 @@ define([
mock.verify(); mock.verify();
}); });
it('displays saving options when clicked on save options button', function() { it('displays saving options when clicked on save options button', function () {
view.$('.mailpoet_save_show_options').click(); view.$('.mailpoet_save_show_options').click();
expect(view.$('.mailpoet_save_options')).to.not.have.$class('mailpoet_hidden'); expect(view.$('.mailpoet_save_options')).to.not.have.$class('mailpoet_hidden');
}); });
it('triggers template saving when clicked on "save as template" button', function() { 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 mock = sinon.mock({ post: function () {} }).expects('post').once().returns(jQuery.Deferred());
var html2canvasMock = jQuery.Deferred(); var html2canvasMock = jQuery.Deferred();
var module; var module;
var view; var view;
html2canvasMock.resolve({ html2canvasMock.resolve({
toDataURL: function() { return 'somedataurl'; } toDataURL: function () { return 'somedataurl'; }
}); });
EditorApplication.getBody = sinon.stub(); EditorApplication.getBody = sinon.stub();
@ -152,18 +152,18 @@ define([
post: mock post: mock
}, },
I18n: { I18n: {
t: function() { return ''; } t: function () { return ''; }
}, },
Notice: { Notice: {
success: function() {}, success: function () {},
error: function() {} error: function () {}
}, },
trackEvent: function() {} trackEvent: function () {}
}, },
'newsletter_editor/App': EditorApplication, 'newsletter_editor/App': EditorApplication,
html2canvas: function() { html2canvas: function () {
return { return {
then: function() { return html2canvasMock; } then: function () { return html2canvasMock; }
}; };
} }
}); });
@ -177,12 +177,12 @@ define([
mock.verify(); mock.verify();
}); });
it('saves newsletter when clicked on "next" button', function() { it('saves newsletter when clicked on "next" button', function () {
var spy = sinon.spy(); var spy = sinon.spy();
var view; var view;
var module = SaveInjector({ var module = SaveInjector({
'newsletter_editor/components/communication': { 'newsletter_editor/components/communication': {
saveNewsletter: function() { saveNewsletter: function () {
return jQuery.Deferred(); return jQuery.Deferred();
} }
} }

View File

@ -4,53 +4,53 @@ const Backbone = global.Backbone;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/sidebar' 'newsletter_editor/components/sidebar'
], function(EditorApplication, SidebarComponent) { ], function (EditorApplication, SidebarComponent) {
describe('Sidebar', function() { describe('Sidebar', function () {
describe('content view', function() { describe('content view', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
view = new (SidebarComponent.SidebarWidgetsView)({ view = new (SidebarComponent.SidebarWidgetsView)({
collection: new Backbone.Collection([]) collection: new Backbone.Collection([])
}); });
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
}); });
describe('layout view', function() { describe('layout view', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
view = new (SidebarComponent.SidebarLayoutWidgetsView)({ view = new (SidebarComponent.SidebarLayoutWidgetsView)({
collection: new Backbone.Collection([]) collection: new Backbone.Collection([])
}); });
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
}); });
describe('styles view', function() { describe('styles view', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
view = new (SidebarComponent.SidebarStylesView)({ view = new (SidebarComponent.SidebarStylesView)({
model: new Backbone.SuperModel({}), model: new Backbone.SuperModel({}),
availableStyles: new Backbone.SuperModel({}) availableStyles: new Backbone.SuperModel({})
}); });
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
describe('once rendered', function() { describe('once rendered', function () {
var model; var model;
var availableStyles; var availableStyles;
var view; var view;
before(function() { before(function () {
model = new Backbone.SuperModel({ model = new Backbone.SuperModel({
text: { text: {
fontColor: '#000000', fontColor: '#000000',
@ -96,95 +96,95 @@ define([
view.render(); view.render();
}); });
it('changes model if text font color field changes', function() { it('changes model if text font color field changes', function () {
view.$('#mailpoet_text_font_color').val('#123456').change(); view.$('#mailpoet_text_font_color').val('#123456').change();
expect(model.get('text.fontColor')).to.equal('#123456'); expect(model.get('text.fontColor')).to.equal('#123456');
}); });
it('changes model if h1 font color field changes', function() { it('changes model if h1 font color field changes', function () {
view.$('#mailpoet_h1_font_color').val('#123457').change(); view.$('#mailpoet_h1_font_color').val('#123457').change();
expect(model.get('h1.fontColor')).to.equal('#123457'); expect(model.get('h1.fontColor')).to.equal('#123457');
}); });
it('changes model if h2 font color field changes', function() { it('changes model if h2 font color field changes', function () {
view.$('#mailpoet_h2_font_color').val('#123458').change(); view.$('#mailpoet_h2_font_color').val('#123458').change();
expect(model.get('h2.fontColor')).to.equal('#123458'); expect(model.get('h2.fontColor')).to.equal('#123458');
}); });
it('changes model if h3 font color field changes', function() { it('changes model if h3 font color field changes', function () {
view.$('#mailpoet_h3_font_color').val('#123426').change(); view.$('#mailpoet_h3_font_color').val('#123426').change();
expect(model.get('h3.fontColor')).to.equal('#123426'); expect(model.get('h3.fontColor')).to.equal('#123426');
}); });
it('changes model if link font color field changes', function() { it('changes model if link font color field changes', function () {
view.$('#mailpoet_a_font_color').val('#323232').change(); view.$('#mailpoet_a_font_color').val('#323232').change();
expect(model.get('link.fontColor')).to.equal('#323232'); expect(model.get('link.fontColor')).to.equal('#323232');
}); });
it('changes model if newsletter background color field changes', function() { it('changes model if newsletter background color field changes', function () {
view.$('#mailpoet_newsletter_background_color').val('#636237').change(); view.$('#mailpoet_newsletter_background_color').val('#636237').change();
expect(model.get('wrapper.backgroundColor')).to.equal('#636237'); expect(model.get('wrapper.backgroundColor')).to.equal('#636237');
}); });
it('changes model if background color field changes', function() { it('changes model if background color field changes', function () {
view.$('#mailpoet_background_color').val('#878587').change(); view.$('#mailpoet_background_color').val('#878587').change();
expect(model.get('body.backgroundColor')).to.equal('#878587'); expect(model.get('body.backgroundColor')).to.equal('#878587');
}); });
it('changes model if text font family field changes', function() { it('changes model if text font family field changes', function () {
view.$('#mailpoet_text_font_family').val('Times New Roman').change(); view.$('#mailpoet_text_font_family').val('Times New Roman').change();
expect(model.get('text.fontFamily')).to.equal('Times New Roman'); expect(model.get('text.fontFamily')).to.equal('Times New Roman');
}); });
it('changes model if h1 font family field changes', function() { it('changes model if h1 font family field changes', function () {
view.$('#mailpoet_h1_font_family').val('Comic Sans').change(); view.$('#mailpoet_h1_font_family').val('Comic Sans').change();
expect(model.get('h1.fontFamily')).to.equal('Comic Sans'); expect(model.get('h1.fontFamily')).to.equal('Comic Sans');
}); });
it('changes model if h2 font family field changes', function() { it('changes model if h2 font family field changes', function () {
view.$('#mailpoet_h2_font_family').val('Tahoma').change(); view.$('#mailpoet_h2_font_family').val('Tahoma').change();
expect(model.get('h2.fontFamily')).to.equal('Tahoma'); expect(model.get('h2.fontFamily')).to.equal('Tahoma');
}); });
it('changes model if h3 font family field changes', function() { it('changes model if h3 font family field changes', function () {
view.$('#mailpoet_h3_font_family').val('Lucida').change(); view.$('#mailpoet_h3_font_family').val('Lucida').change();
expect(model.get('h3.fontFamily')).to.equal('Lucida'); expect(model.get('h3.fontFamily')).to.equal('Lucida');
}); });
it('changes model if text font size field changes', function() { it('changes model if text font size field changes', function () {
view.$('#mailpoet_text_font_size').val('9px').change(); view.$('#mailpoet_text_font_size').val('9px').change();
expect(model.get('text.fontSize')).to.equal('9px'); expect(model.get('text.fontSize')).to.equal('9px');
}); });
it('changes model if h1 font size field changes', function() { it('changes model if h1 font size field changes', function () {
view.$('#mailpoet_h1_font_size').val('12px').change(); view.$('#mailpoet_h1_font_size').val('12px').change();
expect(model.get('h1.fontSize')).to.equal('12px'); expect(model.get('h1.fontSize')).to.equal('12px');
}); });
it('changes model if h2 font size field changes', function() { it('changes model if h2 font size field changes', function () {
view.$('#mailpoet_h2_font_size').val('14px').change(); view.$('#mailpoet_h2_font_size').val('14px').change();
expect(model.get('h2.fontSize')).to.equal('14px'); expect(model.get('h2.fontSize')).to.equal('14px');
}); });
it('changes model if h3 font size field changes', function() { it('changes model if h3 font size field changes', function () {
view.$('#mailpoet_h3_font_size').val('16px').change(); view.$('#mailpoet_h3_font_size').val('16px').change();
expect(model.get('h3.fontSize')).to.equal('16px'); expect(model.get('h3.fontSize')).to.equal('16px');
}); });
it('changes model if link underline field changes', function() { it('changes model if link underline field changes', function () {
view.$('#mailpoet_a_font_underline').prop('checked', true).change(); view.$('#mailpoet_a_font_underline').prop('checked', true).change();
expect(model.get('link.textDecoration')).to.equal('underline'); expect(model.get('link.textDecoration')).to.equal('underline');
}); });
}); });
}); });
describe('preview view', function() { describe('preview view', function () {
var view; var view;
beforeEach(function() { beforeEach(function () {
view = new (SidebarComponent.SidebarPreviewView)(); view = new (SidebarComponent.SidebarPreviewView)();
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
}); });

View File

@ -4,11 +4,11 @@ const sinon = global.sinon;
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/styles' 'newsletter_editor/components/styles'
], function(App, StylesComponent) { ], function (App, StylesComponent) {
var EditorApplication = App; var EditorApplication = App;
describe('Styles', function () { describe('Styles', function () {
it('loads and stores globally available styles', function() { it('loads and stores globally available styles', function () {
var model; var model;
StylesComponent.setGlobalStyles({ StylesComponent.setGlobalStyles({
testStyle: 'testValue' testStyle: 'testValue'
@ -17,15 +17,15 @@ define([
expect(model.get('testStyle')).to.equal('testValue'); expect(model.get('testStyle')).to.equal('testValue');
}); });
describe('model', function() { describe('model', function () {
var model; var model;
beforeEach(function() { beforeEach(function () {
model = new (StylesComponent.StylesModel)(); model = new (StylesComponent.StylesModel)();
}); });
it('triggers autoSave when changed', function() { it('triggers autoSave when changed', function () {
var mock = sinon.mock({ trigger: function() {}}).expects('trigger').once().withExactArgs('autoSave'); var mock = sinon.mock({ trigger: function () {}}).expects('trigger').once().withExactArgs('autoSave');
EditorApplication.getChannel = function() { EditorApplication.getChannel = function () {
return { return {
trigger: mock trigger: mock
}; };
@ -35,15 +35,15 @@ define([
}); });
}); });
describe('view', function() { describe('view', function () {
var model; var model;
var view; var view;
beforeEach(function() { beforeEach(function () {
model = new (StylesComponent.StylesModel)(); model = new (StylesComponent.StylesModel)();
view = new (StylesComponent.StylesView)({ model: model }); view = new (StylesComponent.StylesView)({ model: model });
}); });
it('renders', function() { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
}); });