Integrate newsletter editor tests

This commit is contained in:
Tautvidas Sipavičius
2015-08-26 18:24:43 +03:00
parent 4d1fd2b2d8
commit 21a4843a48
29 changed files with 3116 additions and 2805 deletions

View File

@ -6,7 +6,7 @@
define('newsletter_editor/behaviors/ColorPickerBehavior', [ define('newsletter_editor/behaviors/ColorPickerBehavior', [
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'spectrum-colorpicker', 'spectrum',
], function(Marionette, BehaviorsLookup) { ], function(Marionette, BehaviorsLookup) {
BehaviorsLookup.ColorPickerBehavior = Marionette.Behavior.extend({ BehaviorsLookup.ColorPickerBehavior = Marionette.Behavior.extend({

View File

@ -9,7 +9,7 @@ define('newsletter_editor/behaviors/ContainerDropZoneBehavior', [
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact.js', 'interact',
], function(Marionette, _, BehaviorsLookup, interact) { ], function(Marionette, _, BehaviorsLookup, interact) {
BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({ BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({

View File

@ -7,7 +7,7 @@
define('newsletter_editor/behaviors/DraggableBehavior', [ define('newsletter_editor/behaviors/DraggableBehavior', [
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact.js', 'interact',
], function(Marionette, BehaviorsLookup, interact) { ], function(Marionette, BehaviorsLookup, interact) {
BehaviorsLookup.DraggableBehavior = Marionette.Behavior.extend({ BehaviorsLookup.DraggableBehavior = Marionette.Behavior.extend({

View File

@ -6,7 +6,7 @@
define('newsletter_editor/behaviors/ResizableBehavior', [ define('newsletter_editor/behaviors/ResizableBehavior', [
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact.js', 'interact',
], function(Marionette, BehaviorsLookup, interact) { ], function(Marionette, BehaviorsLookup, interact) {
BehaviorsLookup.ResizableBehavior = Marionette.Behavior.extend({ BehaviorsLookup.ResizableBehavior = Marionette.Behavior.extend({

View File

@ -66,7 +66,6 @@ define('newsletter_editor/blocks/automatedLatestContent', [
}, },
fetchPosts: function() { fetchPosts: function() {
var that = this; var that = this;
console.log('automatedLatestContent.fetchPosts disabled');
// TODO: Migrate to new AJAX queries // TODO: Migrate to new AJAX queries
//mailpoet_post_wpi('automated_latest_content.php', this.toJSON(), function(response) { //mailpoet_post_wpi('automated_latest_content.php', this.toJSON(), function(response) {
//console.log('ALC fetched', arguments); //console.log('ALC fetched', arguments);

View File

@ -76,7 +76,6 @@ define('newsletter_editor/blocks/posts', [
}, },
fetchAvailablePosts: function() { fetchAvailablePosts: function() {
var that = this; var that = this;
console.log('posts.fetchAvailablePosts disabled');
// TODO: Move this logic to new AJAX query format // TODO: Move this logic to new AJAX query format
//mailpoet_post_wpi('posts.php', this.toJSON(), function(response) { //mailpoet_post_wpi('posts.php', this.toJSON(), function(response) {
//console.log('Posts fetched', arguments); //console.log('Posts fetched', arguments);
@ -112,7 +111,6 @@ define('newsletter_editor/blocks/posts', [
if (data.posts.length === 0) return; if (data.posts.length === 0) return;
console.log('posts._insertSelectedPosts disabled');
// TODO: Move query logic to new AJAX format // TODO: Move query logic to new AJAX format
//mailpoet_post_wpi('automated_latest_content.php', data, function(response) { //mailpoet_post_wpi('automated_latest_content.php', data, function(response) {
//console.log('Available posts fetched', arguments); //console.log('Available posts fetched', arguments);

View File

@ -16,7 +16,6 @@ define('newsletter_editor/components/save', [
// save newsletter // save newsletter
console.log('save disabled');
// TODO: Migrate logic to new AJAX format // TODO: Migrate logic to new AJAX format
//mailpoet_post_wpi('newsletter_save.php', json, function(response) { //mailpoet_post_wpi('newsletter_save.php', json, function(response) {
//if(response.success !== undefined && response.success === true) { //if(response.success !== undefined && response.success === true) {

View File

@ -220,7 +220,6 @@ define('newsletter_editor/components/sidebar', [
// send test email // send test email
MailPoet.Modal.loading(true); MailPoet.Modal.loading(true);
console.log('sendPreview disabled');
// TODO: Migrate logic to new AJAX format // TODO: Migrate logic to new AJAX format
//mailpoet_post_wpi('newsletter_preview.php', data, function(response) { //mailpoet_post_wpi('newsletter_preview.php', data, function(response) {
//if(response.success !== undefined && response.success === true) { //if(response.success !== undefined && response.success === true) {

View File

@ -0,0 +1,28 @@
var fs = require('fs');
module.exports = {
loadFileToContainer: function (path, window, containerTagName, options) {
var contents = fs.readFileSync(path),
container = window.document.createElement(containerTagName);
options = options || {};
container.innerHTML = contents;
if (options.type) {
container.type = options.type;
}
if (options.id) {
container.id = options.id;
}
global.window.document.body.appendChild(container);
},
loadScript: function (scriptPath, window, options) {
this.loadFileToContainer(scriptPath, window, 'script', options);
},
loadTemplate: function (path, window, options) {
var w = window || global.window;
options = options || {};
options.type = "text/x-handlebars-template";
this.loadScript("views/newsletter/templates/" + path, w, options);
},
};

View File

@ -27,4 +27,179 @@ if (!global.document || !global.window) {
}; };
} }
global.testHelpers = require('./loadHelpers.js');
global.$ = global.jQuery = global.window.jQuery = require('jquery'); global.$ = global.jQuery = global.window.jQuery = require('jquery');
testHelpers.loadScript('tests/javascript/testBundles/vendor.js', global.window);
global.Handlebars = global.window.Handlebars;
// Stub out interact.js
global.interact = function () {
return {
draggable: global.interact,
restrict: global.interact,
resizable: global.interact,
on: global.interact,
dropzone: global.interact,
preventDefault: global.interact,
};
};
jQuery.fn.spectrum = global.spectrum = function() { return this; };
jQuery.fn.stick_in_parent = function() { return this; };
// Add global stubs for convenience
// TODO: Extract those to a separate file
global.stubChannel = function (EditorApplication, returnObject) {
EditorApplication.getChannel = sinon.stub().returns(_.defaults(returnObject || {}, {
trigger: function () {
},
on: function () {
},
}));
};
global.stubConfig = function (EditorApplication, config) {
config = config || {};
EditorApplication.getConfig = sinon.stub().returns(new Backbone.SuperModel(config));
};
global.stubAvailableStyles = function (EditorApplication, styles) {
styles = styles || {};
EditorApplication.getAvailableStyles = sinon.stub().returns(new Backbone.SuperModel(styles));
};
testHelpers.loadTemplate('blocks/base/toolsGeneric.hbs', window, {id: 'newsletter_editor_template_tools_generic'});
testHelpers.loadTemplate('blocks/automatedLatestContent/block.hbs', window, {id: 'newsletter_editor_template_automated_latest_content_block'});
testHelpers.loadTemplate('blocks/automatedLatestContent/widget.hbs', window, {id: 'newsletter_editor_template_automated_latest_content_widget'});
testHelpers.loadTemplate('blocks/automatedLatestContent/settings.hbs', window, {id: 'newsletter_editor_template_automated_latest_content_settings'});
testHelpers.loadTemplate('blocks/button/block.hbs', window, {id: 'newsletter_editor_template_button_block'});
testHelpers.loadTemplate('blocks/button/widget.hbs', window, {id: 'newsletter_editor_template_button_widget'});
testHelpers.loadTemplate('blocks/button/settings.hbs', window, {id: 'newsletter_editor_template_button_settings'});
testHelpers.loadTemplate('blocks/container/block.hbs', window, {id: 'newsletter_editor_template_container_block'});
testHelpers.loadTemplate('blocks/container/emptyBlock.hbs', window, {id: 'newsletter_editor_template_container_block_empty'});
testHelpers.loadTemplate('blocks/container/oneColumnLayoutWidget.hbs', window, {id: 'newsletter_editor_template_container_one_column_widget'});
testHelpers.loadTemplate('blocks/container/twoColumnLayoutWidget.hbs', window, {id: 'newsletter_editor_template_container_two_column_widget'});
testHelpers.loadTemplate('blocks/container/threeColumnLayoutWidget.hbs', window, {id: 'newsletter_editor_template_container_three_column_widget'});
testHelpers.loadTemplate('blocks/container/settings.hbs', window, {id: 'newsletter_editor_template_container_settings'});
testHelpers.loadTemplate('blocks/divider/block.hbs', window, {id: 'newsletter_editor_template_divider_block'});
testHelpers.loadTemplate('blocks/divider/widget.hbs', window, {id: 'newsletter_editor_template_divider_widget'});
testHelpers.loadTemplate('blocks/divider/settings.hbs', window, {id: 'newsletter_editor_template_divider_settings'});
testHelpers.loadTemplate('blocks/footer/block.hbs', window, {id: 'newsletter_editor_template_footer_block'});
testHelpers.loadTemplate('blocks/footer/widget.hbs', window, {id: 'newsletter_editor_template_footer_widget'});
testHelpers.loadTemplate('blocks/footer/settings.hbs', window, {id: 'newsletter_editor_template_footer_settings'});
testHelpers.loadTemplate('blocks/header/block.hbs', window, {id: 'newsletter_editor_template_header_block'});
testHelpers.loadTemplate('blocks/header/widget.hbs', window, {id: 'newsletter_editor_template_header_widget'});
testHelpers.loadTemplate('blocks/header/settings.hbs', window, {id: 'newsletter_editor_template_header_settings'});
testHelpers.loadTemplate('blocks/image/block.hbs', window, {id: 'newsletter_editor_template_image_block'});
testHelpers.loadTemplate('blocks/image/widget.hbs', window, {id: 'newsletter_editor_template_image_widget'});
testHelpers.loadTemplate('blocks/image/settings.hbs', window, {id: 'newsletter_editor_template_image_settings'});
testHelpers.loadTemplate('blocks/posts/block.hbs', window, {id: 'newsletter_editor_template_posts_block'});
testHelpers.loadTemplate('blocks/posts/widget.hbs', window, {id: 'newsletter_editor_template_posts_widget'});
testHelpers.loadTemplate('blocks/posts/settings.hbs', window, {id: 'newsletter_editor_template_posts_settings'});
testHelpers.loadTemplate('blocks/posts/settingsDisplayOptions.hbs', window, {id: 'newsletter_editor_template_posts_settings_display_options'});
testHelpers.loadTemplate('blocks/posts/settingsSelection.hbs', window, {id: 'newsletter_editor_template_posts_settings_selection'});
testHelpers.loadTemplate('blocks/posts/settingsSelectionEmpty.hbs', window, {id: 'newsletter_editor_template_posts_settings_selection_empty'});
testHelpers.loadTemplate('blocks/posts/settingsSinglePost.hbs', window, {id: 'newsletter_editor_template_posts_settings_single_post'});
testHelpers.loadTemplate('blocks/social/block.hbs', window, {id: 'newsletter_editor_template_social_block'});
testHelpers.loadTemplate('blocks/social/blockIcon.hbs', window, {id: 'newsletter_editor_template_social_block_icon'});
testHelpers.loadTemplate('blocks/social/widget.hbs', window, {id: 'newsletter_editor_template_social_widget'});
testHelpers.loadTemplate('blocks/social/settings.hbs', window, {id: 'newsletter_editor_template_social_settings'});
testHelpers.loadTemplate('blocks/social/settingsIcon.hbs', window, {id: 'newsletter_editor_template_social_settings_icon'});
testHelpers.loadTemplate('blocks/social/settingsIconSelector.hbs', window, {id: 'newsletter_editor_template_social_settings_icon_selector'});
testHelpers.loadTemplate('blocks/social/settingsStyles.hbs', window, {id: 'newsletter_editor_template_social_settings_styles'});
testHelpers.loadTemplate('blocks/spacer/block.hbs', window, {id: 'newsletter_editor_template_spacer_block'});
testHelpers.loadTemplate('blocks/spacer/widget.hbs', window, {id: 'newsletter_editor_template_spacer_widget'});
testHelpers.loadTemplate('blocks/spacer/settings.hbs', window, {id: 'newsletter_editor_template_spacer_settings'});
testHelpers.loadTemplate('blocks/text/block.hbs', window, {id: 'newsletter_editor_template_text_block'});
testHelpers.loadTemplate('blocks/text/widget.hbs', window, {id: 'newsletter_editor_template_text_widget'});
testHelpers.loadTemplate('blocks/text/settings.hbs', window, {id: 'newsletter_editor_template_text_settings'});
testHelpers.loadTemplate('components/heading.hbs', window, {id: 'newsletter_editor_template_heading'});
testHelpers.loadTemplate('components/save.hbs', window, {id: 'newsletter_editor_template_save'});
testHelpers.loadTemplate('components/styles.hbs', window, {id: 'newsletter_editor_template_styles'});
testHelpers.loadTemplate('components/sidebar/sidebar.hbs', window, {id: 'newsletter_editor_template_sidebar'});
testHelpers.loadTemplate('components/sidebar/content.hbs', window, {id: 'newsletter_editor_template_sidebar_content'});
testHelpers.loadTemplate('components/sidebar/layout.hbs', window, {id: 'newsletter_editor_template_sidebar_layout'});
testHelpers.loadTemplate('components/sidebar/preview.hbs', window, {id: 'newsletter_editor_template_sidebar_preview'});
testHelpers.loadTemplate('components/sidebar/styles.hbs', window, {id: 'newsletter_editor_template_sidebar_styles'});
global.templates = {
styles: Handlebars.compile(jQuery('#newsletter_editor_template_styles').html()),
save: Handlebars.compile(jQuery('#newsletter_editor_template_save').html()),
heading: Handlebars.compile(jQuery('#newsletter_editor_template_heading').html()),
sidebar: Handlebars.compile(jQuery('#newsletter_editor_template_sidebar').html()),
sidebarContent: Handlebars.compile(jQuery('#newsletter_editor_template_sidebar_content').html()),
sidebarLayout: Handlebars.compile(jQuery('#newsletter_editor_template_sidebar_layout').html()),
sidebarStyles: Handlebars.compile(jQuery('#newsletter_editor_template_sidebar_styles').html()),
sidebarPreview: Handlebars.compile(jQuery('#newsletter_editor_template_sidebar_preview').html()),
genericBlockTools: Handlebars.compile(jQuery('#newsletter_editor_template_tools_generic').html()),
containerBlock: Handlebars.compile(jQuery('#newsletter_editor_template_container_block').html()),
containerEmpty: Handlebars.compile(jQuery('#newsletter_editor_template_container_block_empty').html()),
oneColumnLayoutInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_container_one_column_widget').html()),
twoColumnLayoutInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_container_two_column_widget').html()),
threeColumnLayoutInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_container_three_column_widget').html()),
containerBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_container_settings').html()),
buttonBlock: Handlebars.compile(jQuery('#newsletter_editor_template_button_block').html()),
buttonInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_button_widget').html()),
buttonBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_button_settings').html()),
dividerBlock: Handlebars.compile(jQuery('#newsletter_editor_template_divider_block').html()),
dividerInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_divider_widget').html()),
dividerBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_divider_settings').html()),
footerBlock: Handlebars.compile(jQuery('#newsletter_editor_template_footer_block').html()),
footerInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_footer_widget').html()),
footerBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_footer_settings').html()),
headerBlock: Handlebars.compile(jQuery('#newsletter_editor_template_header_block').html()),
headerInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_header_widget').html()),
headerBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_header_settings').html()),
imageBlock: Handlebars.compile(jQuery('#newsletter_editor_template_image_block').html()),
imageInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_image_widget').html()),
imageBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_image_settings').html()),
socialBlock: Handlebars.compile(jQuery('#newsletter_editor_template_social_block').html()),
socialIconBlock: Handlebars.compile(jQuery('#newsletter_editor_template_social_block_icon').html()),
socialInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_social_widget').html()),
socialBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_social_settings').html()),
socialSettingsIconSelector: Handlebars.compile(jQuery('#newsletter_editor_template_social_settings_icon_selector').html()),
socialSettingsIcon: Handlebars.compile(jQuery('#newsletter_editor_template_social_settings_icon').html()),
socialSettingsStyles: Handlebars.compile(jQuery('#newsletter_editor_template_social_settings_styles').html()),
spacerBlock: Handlebars.compile(jQuery('#newsletter_editor_template_spacer_block').html()),
spacerInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_spacer_widget').html()),
spacerBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_spacer_settings').html()),
automatedLatestContentBlock: Handlebars.compile(jQuery('#newsletter_editor_template_automated_latest_content_block').html()),
automatedLatestContentInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_automated_latest_content_widget').html()),
automatedLatestContentBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_automated_latest_content_settings').html()),
postsBlock: Handlebars.compile(jQuery('#newsletter_editor_template_posts_block').html()),
postsInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_posts_widget').html()),
postsBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_posts_settings').html()),
postSelectionPostsBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_posts_settings_selection').html()),
emptyPostPostsBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_posts_settings_selection_empty').html()),
singlePostPostsBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_posts_settings_single_post').html()),
displayOptionsPostsBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_posts_settings_display_options').html()),
textBlock: Handlebars.compile(jQuery('#newsletter_editor_template_text_block').html()),
textInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_text_widget').html()),
textBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_text_settings').html()),
};

View File

@ -1,394 +1,401 @@
describe('Automated latest content', function () { define('test/newsletter_editor/blocks/automatedLatestContent', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/automatedLatestContent'
], function(EditorApplication) {
beforeEach(function () { describe('Automated latest content', function () {
global.stubChannel(); describe('model', function () {
global.stubConfig(); var model;
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
global.mailpoet_post_wpi = sinon.stub();
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
});
afterEach(function () { beforeEach(function () {
delete EditorApplication.getChannel; global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
global.mailpoet_post_wpi = sinon.stub();
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
});
it('has automatedLatestContent type', function () { afterEach(function () {
expect(model.get('type')).to.equal('automatedLatestContent'); delete EditorApplication.getChannel;
}); });
it('has post amount limit', function () { it('has automatedLatestContent type', function () {
expect(model.get('amount')).to.match(/^\d+$/); expect(model.get('type')).to.equal('automatedLatestContent');
}); });
it('has post type filter', function () { it('has post amount limit', function () {
expect(model.get('contentType')).to.match(/^(post|page|mailpoet_page)$/); expect(model.get('amount')).to.match(/^\d+$/);
}); });
it('has terms filter', function () { it('has post type filter', function () {
expect(model.get('terms')).to.have.length(0); expect(model.get('contentType')).to.match(/^(post|page|mailpoet_page)$/);
}); });
it('has inclusion filter', function () { it('has terms filter', function () {
expect(model.get('inclusionType')).to.match(/^(include|exclude)$/); expect(model.get('terms')).to.have.length(0);
}); });
it('has display type', function () { it('has inclusion filter', function () {
expect(model.get('displayType')).to.match(/^(excerpt|full|titleOnly)$/); expect(model.get('inclusionType')).to.match(/^(include|exclude)$/);
}); });
it('has title heading format', function () { it('has display type', function () {
expect(model.get('titleFormat')).to.match(/^(h1|h2|h3|ul)$/); expect(model.get('displayType')).to.match(/^(excerpt|full|titleOnly)$/);
}); });
it('has title position', function () { it('has title heading format', function () {
expect(model.get('titlePosition')).to.match(/^(inTextBlock|aboveBlock)$/); expect(model.get('titleFormat')).to.match(/^(h1|h2|h3|ul)$/);
}); });
it('has title alignment', function () { it('has title position', function () {
expect(model.get('titleAlignment')).to.match(/^(left|center|right)$/); expect(model.get('titlePosition')).to.match(/^(inTextBlock|aboveBlock)$/);
}); });
it('optionally has title as link', function () { it('has title alignment', function () {
expect(model.get('titleIsLink')).to.be.a('boolean'); expect(model.get('titleAlignment')).to.match(/^(left|center|right)$/);
}); });
it('has image width', function () { it('optionally has title as link', function () {
expect(model.get('imagePadded')).to.be.a('boolean'); expect(model.get('titleIsLink')).to.be.a('boolean');
}); });
it('has an option to display author', function () { it('has image width', function () {
expect(model.get('showAuthor')).to.match(/^(no|aboveText|belowText)$/); expect(model.get('imagePadded')).to.be.a('boolean');
}); });
it('has text preceding author', function () { it('has an option to display author', function () {
expect(model.get('authorPrecededBy')).to.be.a('string'); expect(model.get('showAuthor')).to.match(/^(no|aboveText|belowText)$/);
}); });
it('has an option to display categories', function () { it('has text preceding author', function () {
expect(model.get('showCategories')).to.match(/^(no|aboveText|belowText)$/); expect(model.get('authorPrecededBy')).to.be.a('string');
}); });
it('has text preceding categories', function () { it('has an option to display categories', function () {
expect(model.get('categoriesPrecededBy')).to.be.a('string'); expect(model.get('showCategories')).to.match(/^(no|aboveText|belowText)$/);
}); });
it('has a link or a button type for read more', function () { it('has text preceding categories', function () {
expect(model.get('readMoreType')).to.match(/^(link|button)$/); expect(model.get('categoriesPrecededBy')).to.be.a('string');
}); });
it('has read more text', function () { it('has a link or a button type for read more', function () {
expect(model.get('readMoreText')).to.be.a('string'); expect(model.get('readMoreType')).to.match(/^(link|button)$/);
}); });
it('has a read more button', function () { it('has read more text', function () {
expect(model.get('readMoreButton')).to.be.instanceof(Backbone.Model); expect(model.get('readMoreText')).to.be.a('string');
}); });
it('has sorting', function () { it('has a read more button', function () {
expect(model.get('sortBy')).to.match(/^(newest|oldest)$/); expect(model.get('readMoreButton')).to.be.instanceof(Backbone.Model);
}); });
it('has an option to display divider', function () { it('has sorting', function () {
expect(model.get('showDivider')).to.be.a('boolean'); expect(model.get('sortBy')).to.match(/^(newest|oldest)$/);
}); });
it('has a divider', function () { it('has an option to display divider', function () {
expect(model.get('divider')).to.be.instanceof(Backbone.Model); expect(model.get('showDivider')).to.be.a('boolean');
}); });
it("uses defaults from config when they are set", function () { it('has a divider', function () {
global.stubConfig({ expect(model.get('divider')).to.be.instanceof(Backbone.Model);
blockDefaults: { });
automatedLatestContent: {
amount: '17',
contentType: 'mailpoet_page', // 'post'|'page'|'mailpoet_page'
inclusionType: 'exclude', // 'include'|'exclude'
displayType: 'full', // 'excerpt'|'full'|'titleOnly'
titleFormat: 'h3', // 'h1'|'h2'|'h3'|'ul'
titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
titleAlignment: 'right', // 'left'|'center'|'right'
titleIsLink: true, // false|true
imagePadded: false, // true|false
showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
authorPrecededBy: 'Custom config author preceded by',
showCategories: 'belowText', // 'no'|'aboveText'|'belowText'
categoriesPrecededBy: 'Custom config categories preceded by',
readMoreType: 'button', // 'link'|'button'
readMoreText: 'Custom Config read more text',
readMoreButton: {
text: 'Custom config read more',
url: '[postLink]',
styles: {
block: {
backgroundColor: '#123456',
borderColor: '#234567',
},
link: {
fontColor: '#345678',
fontFamily: 'Tahoma',
fontSize: '37px',
},
},
},
sortBy: 'oldest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {
src: 'http://example.org/someConfigDividerImage.png',
styles: {
block: {
backgroundColor: '#456789',
padding: '38px',
},
},
},
},
},
});
var model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
expect(model.get('amount')).to.equal('17'); it("uses defaults from config when they are set", function () {
expect(model.get('contentType')).to.equal('mailpoet_page'); global.stubConfig(EditorApplication, {
expect(model.get('inclusionType')).to.equal('exclude'); blockDefaults: {
expect(model.get('displayType')).to.equal('full'); automatedLatestContent: {
expect(model.get('titleFormat')).to.equal('h3'); amount: '17',
expect(model.get('titlePosition')).to.equal('aboveBlock'); contentType: 'mailpoet_page', // 'post'|'page'|'mailpoet_page'
expect(model.get('titleAlignment')).to.equal('right'); inclusionType: 'exclude', // 'include'|'exclude'
expect(model.get('titleIsLink')).to.equal(true); displayType: 'full', // 'excerpt'|'full'|'titleOnly'
expect(model.get('imagePadded')).to.equal(false); titleFormat: 'h3', // 'h1'|'h2'|'h3'|'ul'
expect(model.get('showAuthor')).to.equal('belowText'); titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by'); titleAlignment: 'right', // 'left'|'center'|'right'
expect(model.get('showCategories')).to.equal('belowText'); titleIsLink: true, // false|true
expect(model.get('categoriesPrecededBy')).to.equal('Custom config categories preceded by'); imagePadded: false, // true|false
expect(model.get('readMoreType')).to.equal('button'); showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
expect(model.get('readMoreText')).to.equal('Custom Config read more text'); authorPrecededBy: 'Custom config author preceded by',
expect(model.get('readMoreButton.text')).to.equal('Custom config read more'); showCategories: 'belowText', // 'no'|'aboveText'|'belowText'
expect(model.get('readMoreButton.url')).to.equal('[postLink]'); categoriesPrecededBy: 'Custom config categories preceded by',
expect(model.get('readMoreButton.styles.block.backgroundColor')).to.equal('#123456'); readMoreType: 'button', // 'link'|'button'
expect(model.get('readMoreButton.styles.block.borderColor')).to.equal('#234567'); readMoreText: 'Custom Config read more text',
expect(model.get('readMoreButton.styles.link.fontColor')).to.equal('#345678'); readMoreButton: {
expect(model.get('readMoreButton.styles.link.fontFamily')).to.equal('Tahoma'); text: 'Custom config read more',
expect(model.get('readMoreButton.styles.link.fontSize')).to.equal('37px'); url: '[postLink]',
expect(model.get('sortBy')).to.equal('oldest'); styles: {
expect(model.get('showDivider')).to.equal(true); block: {
expect(model.get('divider.src')).to.equal('http://example.org/someConfigDividerImage.png'); backgroundColor: '#123456',
expect(model.get('divider.styles.block.backgroundColor')).to.equal('#456789'); borderColor: '#234567',
expect(model.get('divider.styles.block.padding')).to.equal('38px'); },
}); link: {
}); fontColor: '#345678',
fontFamily: 'Tahoma',
fontSize: '37px',
},
},
},
sortBy: 'oldest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {
src: 'http://example.org/someConfigDividerImage.png',
styles: {
block: {
backgroundColor: '#456789',
padding: '38px',
},
},
},
},
},
});
var model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
describe('block view', function () { expect(model.get('amount')).to.equal('17');
var model, view; expect(model.get('contentType')).to.equal('mailpoet_page');
expect(model.get('inclusionType')).to.equal('exclude');
expect(model.get('displayType')).to.equal('full');
expect(model.get('titleFormat')).to.equal('h3');
expect(model.get('titlePosition')).to.equal('aboveBlock');
expect(model.get('titleAlignment')).to.equal('right');
expect(model.get('titleIsLink')).to.equal(true);
expect(model.get('imagePadded')).to.equal(false);
expect(model.get('showAuthor')).to.equal('belowText');
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by');
expect(model.get('showCategories')).to.equal('belowText');
expect(model.get('categoriesPrecededBy')).to.equal('Custom config categories preceded by');
expect(model.get('readMoreType')).to.equal('button');
expect(model.get('readMoreText')).to.equal('Custom Config read more text');
expect(model.get('readMoreButton.text')).to.equal('Custom config read more');
expect(model.get('readMoreButton.url')).to.equal('[postLink]');
expect(model.get('readMoreButton.styles.block.backgroundColor')).to.equal('#123456');
expect(model.get('readMoreButton.styles.block.borderColor')).to.equal('#234567');
expect(model.get('readMoreButton.styles.link.fontColor')).to.equal('#345678');
expect(model.get('readMoreButton.styles.link.fontFamily')).to.equal('Tahoma');
expect(model.get('readMoreButton.styles.link.fontSize')).to.equal('37px');
expect(model.get('sortBy')).to.equal('oldest');
expect(model.get('showDivider')).to.equal(true);
expect(model.get('divider.src')).to.equal('http://example.org/someConfigDividerImage.png');
expect(model.get('divider.styles.block.backgroundColor')).to.equal('#456789');
expect(model.get('divider.styles.block.padding')).to.equal('38px');
});
});
beforeEach(function () { describe('block view', function () {
global.stubChannel(); var model, view;
global.stubConfig();
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockView)({model: model});
});
afterEach(function () { beforeEach(function () {
delete EditorApplication.getChannel; global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockView)({model: model});
});
it('renders', function () { afterEach(function () {
expect(view.render).to.not.throw(); delete EditorApplication.getChannel;
expect(view.$('.mailpoet_content')).to.have.length(1); });
});
});
describe('block settings view', function () { it('renders', function () {
var model, view; expect(view.render).to.not.throw();
expect(view.$('.mailpoet_content')).to.have.length(1);
});
});
before(function () { describe('block settings view', function () {
global.stubChannel(); var model, view;
global.stubConfig({
blockDefaults: {},
});
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
});
beforeEach(function() { before(function () {
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)(); global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model}); global.stubConfig(EditorApplication, {
}); blockDefaults: {},
});
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
});
after(function () { beforeEach(function() {
delete EditorApplication.getChannel; model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
}); view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
});
it('renders', function () { after(function () {
expect(view.render).to.not.throw(); delete EditorApplication.getChannel;
}); });
describe('once rendered', function () { it('renders', function () {
beforeEach(function() { expect(view.render).to.not.throw();
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)(); });
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
view.render();
});
it('changes the model if post amount changes', function () { describe('once rendered', function () {
var newValue = '11'; beforeEach(function() {
view.$('.mailpoet_automated_latest_content_show_amount').val(newValue).keyup(); model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
expect(model.get('amount')).to.equal(newValue); view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
}); view.render();
});
it('changes the model if post type changes', function () { it('changes the model if post amount changes', function () {
var newValue = 'mailpoet_page'; var newValue = '11';
view.$('.mailpoet_automated_latest_content_content_type').val(newValue).change(); view.$('.mailpoet_automated_latest_content_show_amount').val(newValue).keyup();
expect(model.get('contentType')).to.equal(newValue); expect(model.get('amount')).to.equal(newValue);
}); });
it('changes the model if inclusion type changes', function () { it('changes the model if post type changes', function () {
var newValue = 'exclude'; var newValue = 'mailpoet_page';
view.$('.mailpoet_automated_latest_content_include_or_exclude').val(newValue).change(); view.$('.mailpoet_automated_latest_content_content_type').val(newValue).change();
expect(model.get('inclusionType')).to.equal(newValue); expect(model.get('contentType')).to.equal(newValue);
}); });
it('changes the model if display type changes', function () { it('changes the model if inclusion type changes', function () {
var newValue = 'full'; var newValue = 'exclude';
view.$('.mailpoet_automated_latest_content_display_type').val(newValue).change(); view.$('.mailpoet_automated_latest_content_include_or_exclude').val(newValue).change();
expect(model.get('displayType')).to.equal(newValue); expect(model.get('inclusionType')).to.equal(newValue);
}); });
it('changes the model if title format changes', function () { it('changes the model if display type changes', function () {
var newValue = 'h3'; var newValue = 'full';
view.$('.mailpoet_automated_latest_content_title_format').val(newValue).change(); view.$('.mailpoet_automated_latest_content_display_type').val(newValue).change();
expect(model.get('titleFormat')).to.equal(newValue); expect(model.get('displayType')).to.equal(newValue);
}); });
it('changes the model if title position changes', function () { it('changes the model if title format changes', function () {
var newValue = 'aboveBlock'; var newValue = 'h3';
view.$('.mailpoet_automated_latest_content_title_position').val(newValue).change(); view.$('.mailpoet_automated_latest_content_title_format').val(newValue).change();
expect(model.get('titlePosition')).to.equal(newValue); expect(model.get('titleFormat')).to.equal(newValue);
}); });
it('changes the model if title alignment changes', function () { it('changes the model if title position changes', function () {
var newValue = 'right'; var newValue = 'aboveBlock';
view.$('.mailpoet_automated_latest_content_title_alignment').val(newValue).change(); view.$('.mailpoet_automated_latest_content_title_position').val(newValue).change();
expect(model.get('titleAlignment')).to.equal(newValue); expect(model.get('titlePosition')).to.equal(newValue);
}); });
it('changes the model if title link changes', function () { it('changes the model if title alignment changes', function () {
var newValue = true; var newValue = 'right';
view.$('.mailpoet_automated_latest_content_title_as_links').val(newValue).change(); view.$('.mailpoet_automated_latest_content_title_alignment').val(newValue).change();
expect(model.get('titleIsLink')).to.equal(newValue); expect(model.get('titleAlignment')).to.equal(newValue);
}); });
it('changes the model if image alignment changes', function () { it('changes the model if title link changes', function () {
var newValue = false; var newValue = true;
view.$('.mailpoet_automated_latest_content_image_padded').val(newValue).change(); view.$('.mailpoet_automated_latest_content_title_as_links').val(newValue).change();
expect(model.get('imagePadded')).to.equal(newValue); expect(model.get('titleIsLink')).to.equal(newValue);
}); });
it('changes the model if show author changes', function () { it('changes the model if image alignment changes', function () {
var newValue = 'belowText'; var newValue = false;
view.$('.mailpoet_automated_latest_content_show_author').val(newValue).change(); view.$('.mailpoet_automated_latest_content_image_padded').val(newValue).change();
expect(model.get('showAuthor')).to.equal(newValue); expect(model.get('imagePadded')).to.equal(newValue);
}); });
it('changes the model if author preceded by changes', function () { it('changes the model if show author changes', function () {
var newValue = 'New author preceded by test'; var newValue = 'belowText';
view.$('.mailpoet_automated_latest_content_author_preceded_by').val(newValue).keyup(); view.$('.mailpoet_automated_latest_content_show_author').val(newValue).change();
expect(model.get('authorPrecededBy')).to.equal(newValue); expect(model.get('showAuthor')).to.equal(newValue);
}); });
it('changes the model if show categories changes', function () { it('changes the model if author preceded by changes', function () {
var newValue = 'belowText'; var newValue = 'New author preceded by test';
view.$('.mailpoet_automated_latest_content_show_categories').val(newValue).change(); view.$('.mailpoet_automated_latest_content_author_preceded_by').val(newValue).keyup();
expect(model.get('showCategories')).to.equal(newValue); expect(model.get('authorPrecededBy')).to.equal(newValue);
}); });
it('changes the model if categories preceded by changes', function () { it('changes the model if show categories changes', function () {
var newValue = 'New categories preceded by test'; var newValue = 'belowText';
view.$('.mailpoet_automated_latest_content_categories').val(newValue).keyup(); view.$('.mailpoet_automated_latest_content_show_categories').val(newValue).change();
expect(model.get('categoriesPrecededBy')).to.equal(newValue); expect(model.get('showCategories')).to.equal(newValue);
}); });
it('changes the model if read more button type changes', function () { it('changes the model if categories preceded by changes', function () {
var newValue = 'link'; var newValue = 'New categories preceded by test';
view.$('.mailpoet_automated_latest_content_read_more_type').val(newValue).change(); view.$('.mailpoet_automated_latest_content_categories').val(newValue).keyup();
expect(model.get('readMoreType')).to.equal(newValue); expect(model.get('categoriesPrecededBy')).to.equal(newValue);
}); });
it('changes the model if read more text changes', function () { it('changes the model if read more button type changes', function () {
var newValue = 'New read more text'; var newValue = 'link';
view.$('.mailpoet_automated_latest_content_read_more_text').val(newValue).keyup(); view.$('.mailpoet_automated_latest_content_read_more_type').val(newValue).change();
expect(model.get('readMoreText')).to.equal(newValue); expect(model.get('readMoreType')).to.equal(newValue);
}); });
it('changes the model if sort by changes', function () { it('changes the model if read more text changes', function () {
var newValue = 'oldest'; var newValue = 'New read more text';
view.$('.mailpoet_automated_latest_content_sort_by').val(newValue).change(); view.$('.mailpoet_automated_latest_content_read_more_text').val(newValue).keyup();
expect(model.get('sortBy')).to.equal(newValue); expect(model.get('readMoreText')).to.equal(newValue);
}); });
it('changes the model if show divider changes', function () { it('changes the model if sort by changes', function () {
var newValue = true; var newValue = 'oldest';
view.$('.mailpoet_automated_latest_content_show_divider').val(newValue).change(); view.$('.mailpoet_automated_latest_content_sort_by').val(newValue).change();
expect(model.get('showDivider')).to.equal(newValue); expect(model.get('sortBy')).to.equal(newValue);
}); });
describe('when "title only" display type is selected', function() { it('changes the model if show divider changes', function () {
var model, view; var newValue = true;
beforeEach(function() { view.$('.mailpoet_automated_latest_content_show_divider').val(newValue).change();
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)(); expect(model.get('showDivider')).to.equal(newValue);
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model}); });
view.render();
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
});
it('shows "title as list" option', function () { describe('when "title only" display type is selected', function() {
expect(view.$('.mailpoet_automated_latest_content_title_as_list')).to.not.have.$class('mailpoet_hidden'); var model, view;
}); beforeEach(function() {
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
});
describe('when "title as list" is selected', function() { it('shows "title as list" option', function () {
var model, view; expect(view.$('.mailpoet_automated_latest_content_title_as_list')).to.not.have.$class('mailpoet_hidden');
beforeEach(function() { });
model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
});
describe('"title is link" option', function () { describe('when "title as list" is selected', function() {
it('is hidden', function () { var model, view;
expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.have.$class('mailpoet_hidden'); beforeEach(function() {
}); model = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockModel)();
view = new (EditorApplication.module('blocks.automatedLatestContent').AutomatedLatestContentBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
});
it('is set to "yes"', function() { describe('"title is link" option', function () {
expect(model.get('titleIsLink')).to.equal(true); it('is hidden', function () {
}); expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.have.$class('mailpoet_hidden');
}); });
});
describe('when "title as list" is deselected', function() { it('is set to "yes"', function() {
before(function() { expect(model.get('titleIsLink')).to.equal(true);
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change(); });
view.$('.mailpoet_automated_latest_content_title_format').val('h3').change(); });
}); });
describe('"title is link" option', function () { describe('when "title as list" is deselected', function() {
it('is visible', function () { before(function() {
expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.not.have.$class('mailpoet_hidden'); view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
}); view.$('.mailpoet_automated_latest_content_title_format').val('h3').change();
}); });
});
}); describe('"title is link" option', function () {
it('is visible', function () {
expect(view.$('.mailpoet_automated_latest_content_title_as_link')).to.not.have.$class('mailpoet_hidden');
});
});
});
});
it.skip('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,415 +1,422 @@
describe("Button", function () { define('test/newsletter_editor/blocks/button', [
describe("model", function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/button'
], function(EditorApplication) {
beforeEach(function () {
global.stubChannel(); describe("Button", function () {
global.stubConfig({ describe("model", function () {
blockDefaults: {}, var model;
});
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)(); beforeEach(function () {
}); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication, {
afterEach(function () { blockDefaults: {},
delete EditorApplication.getChannel; });
}); model = new (EditorApplication.module('blocks.button').ButtonBlockModel)();
});
it("has a button type", function () {
expect(model.get('type')).to.equal('button'); afterEach(function () {
}); delete EditorApplication.getChannel;
});
it("has a label", function () {
expect(model.get('text')).to.be.a('string'); it("has a button type", function () {
}); expect(model.get('type')).to.equal('button');
});
it("has a url", function () {
expect(model.get('url')).to.be.a('string'); it("has a label", function () {
}); expect(model.get('text')).to.be.a('string');
});
it("has a block background color", function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); it("has a url", function () {
}); expect(model.get('url')).to.be.a('string');
});
it("has a block border color", function () {
expect(model.get('styles.block.borderColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); it("has a block background color", function () {
}); expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
});
it("has a block border width", function () {
expect(model.get('styles.block.borderWidth')).to.match(/^\d+px$/); it("has a block border color", function () {
}); expect(model.get('styles.block.borderColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
});
it("has block border radius", function () {
expect(model.get('styles.block.borderRadius')).to.match(/^\d+px$/); it("has a block border width", function () {
}); expect(model.get('styles.block.borderWidth')).to.match(/^\d+px$/);
});
it("has block border style", function () {
expect(model.get('styles.block.borderStyle')).to.equal('solid'); it("has block border radius", function () {
}); expect(model.get('styles.block.borderRadius')).to.match(/^\d+px$/);
});
it("has a text color", function () {
expect(model.get('styles.block.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); it("has block border style", function () {
}); expect(model.get('styles.block.borderStyle')).to.equal('solid');
});
it("has a text font family", function () {
expect(model.get('styles.block.fontFamily')).to.be.a('string'); it("has a text color", function () {
}); expect(model.get('styles.block.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
});
it("has a text size", function () {
expect(model.get('styles.block.fontSize')).to.match(/^\d+px$/); it("has a text font family", function () {
}); expect(model.get('styles.block.fontFamily')).to.be.a('string');
});
it("has width", function () {
expect(model.get('styles.block.width')).to.match(/^\d+px$/); it("has a text size", function () {
}); expect(model.get('styles.block.fontSize')).to.match(/^\d+px$/);
});
it("has line height", function () {
expect(model.get('styles.block.lineHeight')).to.match(/^\d+px$/); it("has width", function () {
}); expect(model.get('styles.block.width')).to.match(/^\d+px$/);
});
it("changes attributes with set", function () {
var newText = 'Some new text'; it("has line height", function () {
model.set('text', newText); expect(model.get('styles.block.lineHeight')).to.match(/^\d+px$/);
expect(model.get('text')).to.equal(newText); });
});
it("changes attributes with set", function () {
it("triggers autosave if any attribute changes", function () { var newText = 'Some new text';
var mock = sinon.mock().exactly(11).withArgs('autoSave'); model.set('text', newText);
EditorApplication.getChannel = sinon.stub().returns({ expect(model.get('text')).to.equal(newText);
trigger: mock, });
});
model.set('text', 'some other text'); it("triggers autosave if any attribute changes", function () {
model.set('url', 'some url'); var mock = sinon.mock().exactly(11).withArgs('autoSave');
model.set('styles.block.backgroundColor', '#123456'); EditorApplication.getChannel = sinon.stub().returns({
model.set('styles.block.borderColor', '#234567'); trigger: mock,
model.set('styles.block.borderWidth', '3px'); });
model.set('styles.block.borderRadius', '8px'); model.set('text', 'some other text');
model.set('styles.block.width', '400px'); model.set('url', 'some url');
model.set('styles.block.lineHeight', '100px'); model.set('styles.block.backgroundColor', '#123456');
model.set('styles.block.fontColor', '#345678'); model.set('styles.block.borderColor', '#234567');
model.set('styles.block.fontFamily', 'Some other style'); model.set('styles.block.borderWidth', '3px');
model.set('styles.block.fontSize', '10px'); model.set('styles.block.borderRadius', '8px');
mock.verify(); model.set('styles.block.width', '400px');
}); model.set('styles.block.lineHeight', '100px');
model.set('styles.block.fontColor', '#345678');
it("uses defaults from config when they are set", function () { model.set('styles.block.fontFamily', 'Some other style');
global.stubConfig({ model.set('styles.block.fontSize', '10px');
blockDefaults: { mock.verify();
button: { });
text: 'Some new text',
url: 'http://somenewurl.com', it("uses defaults from config when they are set", function () {
styles: { global.stubConfig(EditorApplication, {
block: { blockDefaults: {
backgroundColor: '#123456', button: {
borderColor: '#234567', text: 'Some new text',
borderWidth: '11px', url: 'http://somenewurl.com',
borderRadius: '13px', styles: {
borderStyle: 'solid', block: {
width: '371px', backgroundColor: '#123456',
lineHeight: '107px', borderColor: '#234567',
fontColor: '#345678', borderWidth: '11px',
fontFamily: 'Tahoma', borderRadius: '13px',
fontSize: '30px', borderStyle: 'solid',
}, width: '371px',
}, lineHeight: '107px',
}, fontColor: '#345678',
}, fontFamily: 'Tahoma',
}); fontSize: '30px',
var model = new (EditorApplication.module('blocks.button').ButtonBlockModel)(); },
},
expect(model.get('text')).to.equal('Some new text'); },
expect(model.get('url')).to.equal('http://somenewurl.com'); },
expect(model.get('styles.block.backgroundColor')).to.equal('#123456'); });
expect(model.get('styles.block.borderColor')).to.equal('#234567'); var model = new (EditorApplication.module('blocks.button').ButtonBlockModel)();
expect(model.get('styles.block.borderWidth')).to.equal('11px');
expect(model.get('styles.block.borderRadius')).to.equal('13px'); expect(model.get('text')).to.equal('Some new text');
expect(model.get('styles.block.borderStyle')).to.equal('solid'); expect(model.get('url')).to.equal('http://somenewurl.com');
expect(model.get('styles.block.width')).to.equal('371px'); expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
expect(model.get('styles.block.lineHeight')).to.equal('107px'); expect(model.get('styles.block.borderColor')).to.equal('#234567');
expect(model.get('styles.block.fontColor')).to.equal('#345678'); expect(model.get('styles.block.borderWidth')).to.equal('11px');
expect(model.get('styles.block.fontFamily')).to.equal('Tahoma'); expect(model.get('styles.block.borderRadius')).to.equal('13px');
expect(model.get('styles.block.fontSize')).to.equal('30px'); expect(model.get('styles.block.borderStyle')).to.equal('solid');
}); expect(model.get('styles.block.width')).to.equal('371px');
}); expect(model.get('styles.block.lineHeight')).to.equal('107px');
expect(model.get('styles.block.fontColor')).to.equal('#345678');
describe('block view', function () { expect(model.get('styles.block.fontFamily')).to.equal('Tahoma');
var model; expect(model.get('styles.block.fontSize')).to.equal('30px');
});
beforeEach(function () { });
global.stubChannel();
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)(); describe('block view', function () {
}); var model;
it('renders', function () { beforeEach(function () {
var view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model}); global.stubChannel(EditorApplication);
expect(view.render).to.not.throw(); model = new (EditorApplication.module('blocks.button').ButtonBlockModel)();
expect(view.$('.mailpoet_editor_button')).to.have.length(1); });
});
it('renders', function () {
it('rerenders when attributes change', function () { var view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model});
var view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model}); expect(view.render).to.not.throw();
view.render(); expect(view.$('.mailpoet_editor_button')).to.have.length(1);
});
model.set('text', 'Some new text');
it('rerenders when attributes change', function () {
expect(view.$('.mailpoet_editor_button').text()).to.equal('Some new text'); var view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model});
}); view.render();
describe('once rendered', function () { model.set('text', 'Some new text');
var model, view;
expect(view.$('.mailpoet_editor_button').text()).to.equal('Some new text');
before(function () { });
global.stubChannel();
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({ describe('once rendered', function () {
text: 'Some button', var model, view;
url: 'http://example.org',
styles: { before(function () {
block: { global.stubChannel(EditorApplication);
backgroundColor: '#123456', model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({
borderColor: '#234567', text: 'Some button',
borderWidth: '7px', url: 'http://example.org',
borderRadius: '8px', styles: {
borderStyle: 'solid', block: {
width: '123px', backgroundColor: '#123456',
lineHeight: '45px', borderColor: '#234567',
fontColor: '#345678', borderWidth: '7px',
fontFamily: 'Arial', borderRadius: '8px',
fontSize: '12px', borderStyle: 'solid',
}, width: '123px',
}, lineHeight: '45px',
}); fontColor: '#345678',
view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model}); fontFamily: 'Arial',
view.render(); fontSize: '12px',
}); },
},
it('has a specified text', function () { });
expect(view.$('.mailpoet_editor_button').text()).to.equal(model.get('text')); view = new (EditorApplication.module('blocks.button').ButtonBlockView)({model: model});
}); view.render();
});
it('has a specified button url', function () {
expect(view.$('.mailpoet_editor_button').attr('href')).to.equal(model.get('url')); it('has a specified text', function () {
}); expect(view.$('.mailpoet_editor_button').text()).to.equal(model.get('text'));
});
it('has a specified background color', function () {
// jQuery colors appear in rgb format, not hex6 it('has a specified button url', function () {
expect(view.$('.mailpoet_editor_button').css('background-color')).to.equal('rgb(18, 52, 86)'); expect(view.$('.mailpoet_editor_button').attr('href')).to.equal(model.get('url'));
}); });
it('has a specified border color', function () { it('has a specified background color', function () {
expect(view.$('.mailpoet_editor_button').css('border-color')).to.equal(model.get('styles.block.borderColor')); // jQuery colors appear in rgb format, not hex6
}); expect(view.$('.mailpoet_editor_button').css('background-color')).to.equal('rgb(18, 52, 86)');
});
it('has a specified border width', function () {
expect(view.$('.mailpoet_editor_button').css('border-width')).to.equal(model.get('styles.block.borderWidth')); it('has a specified border color', function () {
}); expect(view.$('.mailpoet_editor_button').css('border-color')).to.equal(model.get('styles.block.borderColor'));
});
it('has a specified border radius', function () {
expect(view.$('.mailpoet_editor_button').css('border-radius')).to.equal(model.get('styles.block.borderRadius')); it('has a specified border width', function () {
}); expect(view.$('.mailpoet_editor_button').css('border-width')).to.equal(model.get('styles.block.borderWidth'));
});
it('has a specified border style', function () {
expect(view.$('.mailpoet_editor_button').css('border-style')).to.equal(model.get('styles.block.borderStyle')); it('has a specified border radius', function () {
}); expect(view.$('.mailpoet_editor_button').css('border-radius')).to.equal(model.get('styles.block.borderRadius'));
});
it('has a specified width', function () {
expect(view.$('.mailpoet_editor_button').css('width')).to.equal(model.get('styles.block.width')); it('has a specified border style', function () {
}); expect(view.$('.mailpoet_editor_button').css('border-style')).to.equal(model.get('styles.block.borderStyle'));
});
it('has a specified line height', function () {
expect(view.$('.mailpoet_editor_button').css('lineHeight')).to.equal(model.get('styles.block.lineHeight')); it('has a specified width', function () {
}); expect(view.$('.mailpoet_editor_button').css('width')).to.equal(model.get('styles.block.width'));
});
it('has a specified font color', function () {
// jQuery colors appear in rgb format, not hex6 it('has a specified line height', function () {
expect(view.$('.mailpoet_editor_button').css('color')).to.equal('rgb(52, 86, 120)'); expect(view.$('.mailpoet_editor_button').css('lineHeight')).to.equal(model.get('styles.block.lineHeight'));
}); });
it('has a specified font family', function () { it('has a specified font color', function () {
expect(view.$('.mailpoet_editor_button').css('font-family')).to.equal(model.get('styles.block.fontFamily')); // jQuery colors appear in rgb format, not hex6
}); expect(view.$('.mailpoet_editor_button').css('color')).to.equal('rgb(52, 86, 120)');
});
it('has a specified font size', function () {
expect(view.$('.mailpoet_editor_button').css('font-size')).to.equal(model.get('styles.block.fontSize')); it('has a specified font family', function () {
}); expect(view.$('.mailpoet_editor_button').css('font-family')).to.equal(model.get('styles.block.fontFamily'));
}); });
});
it('has a specified font size', function () {
describe('block settings view', function () { expect(view.$('.mailpoet_editor_button').css('font-size')).to.equal(model.get('styles.block.fontSize'));
var model; });
});
beforeEach(function () { });
global.stubChannel();
global.stubAvailableStyles({ describe('block settings view', function () {
fonts: ['Arial', 'Tahoma'], var model;
headingSizes: ['16px', '20px'],
}); beforeEach(function () {
global.stubChannel(EditorApplication);
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({ global.stubAvailableStyles(EditorApplication, {
type: 'button', fonts: ['Arial', 'Tahoma'],
text: 'Some random text', headingSizes: ['16px', '20px'],
}); });
});
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({
it('renders', function () { type: 'button',
var view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({model: model}); text: 'Some random text',
expect(view.render).to.not.throw(); });
}); });
describe('once rendered', function () { it('renders', function () {
var model, view; var view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({model: model});
before(function() { expect(view.render).to.not.throw();
global.stubChannel(); });
global.stubConfig();
global.stubAvailableStyles({ describe('once rendered', function () {
fonts: ['Arial', 'Tahoma'], var model, view;
headingSizes: ['16px', '20px'], before(function() {
}); global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
beforeEach(function() { fonts: ['Arial', 'Tahoma'],
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({ headingSizes: ['16px', '20px'],
type: 'button', });
text: 'Some random text', });
});
view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({model: model}); beforeEach(function() {
model = new (EditorApplication.module('blocks.button').ButtonBlockModel)({
view.render(); type: 'button',
}); text: 'Some random text',
});
it('updates the model when text is changed', function () { view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({model: model});
var newValue = 'something else';
view.render();
view.$('.mailpoet_field_button_text').val(newValue).keyup(); });
expect(model.get('text')).to.equal(newValue); it('updates the model when text is changed', function () {
}); var newValue = 'something else';
it('updates the model when link is changed', function () { view.$('.mailpoet_field_button_text').val(newValue).keyup();
var newValue = 'http://google.com/?q=123456';
expect(model.get('text')).to.equal(newValue);
view.$('.mailpoet_field_button_url').val(newValue).keyup(); });
expect(model.get('url')).to.equal(newValue); it('updates the model when link is changed', function () {
}); var newValue = 'http://google.com/?q=123456';
it('updates the model when font color changes', function () { view.$('.mailpoet_field_button_url').val(newValue).keyup();
var newValue = '#cccccc';
expect(model.get('url')).to.equal(newValue);
view.$('.mailpoet_field_button_font_color').val(newValue).change(); });
expect(model.get('styles.block.fontColor')).to.equal(newValue); it('updates the model when font color changes', function () {
}); var newValue = '#cccccc';
it('updates the model when font family changes', function () { view.$('.mailpoet_field_button_font_color').val(newValue).change();
var newValue = 'Tahoma';
expect(model.get('styles.block.fontColor')).to.equal(newValue);
view.$('.mailpoet_field_button_font_family').val(newValue).change(); });
expect(model.get('styles.block.fontFamily')).to.equal(newValue); it('updates the model when font family changes', function () {
}); var newValue = 'Tahoma';
it('updates the model when font size changes', function () { view.$('.mailpoet_field_button_font_family').val(newValue).change();
var newValue = '20px';
view.$('.mailpoet_field_button_font_size').val(newValue).change(); expect(model.get('styles.block.fontFamily')).to.equal(newValue);
expect(model.get('styles.block.fontSize')).to.equal(newValue); });
});
it('updates the model when font size changes', function () {
it('updates the model when background color changes', function () { var newValue = '20px';
var newValue = '#cccccc'; view.$('.mailpoet_field_button_font_size').val(newValue).change();
expect(model.get('styles.block.fontSize')).to.equal(newValue);
view.$('.mailpoet_field_button_background_color').val(newValue).change(); });
expect(model.get('styles.block.backgroundColor')).to.equal(newValue); it('updates the model when background color changes', function () {
}); var newValue = '#cccccc';
it('updates the model when border color changes', function () { view.$('.mailpoet_field_button_background_color').val(newValue).change();
var newValue = '#cccccc';
expect(model.get('styles.block.backgroundColor')).to.equal(newValue);
view.$('.mailpoet_field_button_border_color').val(newValue).change(); });
expect(model.get('styles.block.borderColor')).to.equal(newValue); it('updates the model when border color changes', function () {
}); var newValue = '#cccccc';
it('updates the model when border width changes', function () { view.$('.mailpoet_field_button_border_color').val(newValue).change();
view.$('.mailpoet_field_button_border_width').val('3').change();
expect(model.get('styles.block.borderWidth')).to.equal('3px'); expect(model.get('styles.block.borderColor')).to.equal(newValue);
}); });
it('updates the range slider when border width input changes', function () {
view.$('.mailpoet_field_button_border_width_input').val('5').keyup(); it('updates the model when border width changes', function () {
expect(view.$('.mailpoet_field_button_border_width').val()).to.equal('5'); view.$('.mailpoet_field_button_border_width').val('3').change();
}); expect(model.get('styles.block.borderWidth')).to.equal('3px');
it('updates the input when border width range slider changes', function () { });
view.$('.mailpoet_field_button_border_width').val('4').change(); it('updates the range slider when border width input changes', function () {
expect(view.$('.mailpoet_field_button_border_width_input').val()).to.equal('4'); view.$('.mailpoet_field_button_border_width_input').val('5').keyup();
}); expect(view.$('.mailpoet_field_button_border_width').val()).to.equal('5');
});
it('updates the model when border radius changes', function () { it('updates the input when border width range slider changes', function () {
view.$('.mailpoet_field_button_border_radius').val('7').change(); view.$('.mailpoet_field_button_border_width').val('4').change();
expect(model.get('styles.block.borderRadius')).to.equal('7px'); expect(view.$('.mailpoet_field_button_border_width_input').val()).to.equal('4');
}); });
it('updates the range slider when border radius input changes', function () {
view.$('.mailpoet_field_button_border_radius_input').val('7').keyup(); it('updates the model when border radius changes', function () {
expect(view.$('.mailpoet_field_button_border_radius').val()).to.equal('7'); view.$('.mailpoet_field_button_border_radius').val('7').change();
}); expect(model.get('styles.block.borderRadius')).to.equal('7px');
it('updates the input when border radius range slider changes', function () { });
view.$('.mailpoet_field_button_border_radius').val('7').change(); it('updates the range slider when border radius input changes', function () {
expect(view.$('.mailpoet_field_button_border_radius_input').val()).to.equal('7'); view.$('.mailpoet_field_button_border_radius_input').val('7').keyup();
}); expect(view.$('.mailpoet_field_button_border_radius').val()).to.equal('7');
});
it('updates the model when width changes', function () { it('updates the input when border radius range slider changes', function () {
view.$('.mailpoet_field_button_width').val('127').change(); view.$('.mailpoet_field_button_border_radius').val('7').change();
expect(model.get('styles.block.width')).to.equal('127px'); expect(view.$('.mailpoet_field_button_border_radius_input').val()).to.equal('7');
}); });
it('updates the range slider when width input changes', function () {
view.$('.mailpoet_field_button_width_input').val('127').keyup(); it('updates the model when width changes', function () {
expect(view.$('.mailpoet_field_button_width').val()).to.equal('127'); view.$('.mailpoet_field_button_width').val('127').change();
}); expect(model.get('styles.block.width')).to.equal('127px');
it('updates the input when width range slider changes', function () { });
view.$('.mailpoet_field_button_width').val('127').change(); it('updates the range slider when width input changes', function () {
expect(view.$('.mailpoet_field_button_width_input').val()).to.equal('127'); view.$('.mailpoet_field_button_width_input').val('127').keyup();
}); expect(view.$('.mailpoet_field_button_width').val()).to.equal('127');
});
it('updates the model when line height changes', function () { it('updates the input when width range slider changes', function () {
view.$('.mailpoet_field_button_line_height').val('37').change(); view.$('.mailpoet_field_button_width').val('127').change();
expect(model.get('styles.block.lineHeight')).to.equal('37px'); expect(view.$('.mailpoet_field_button_width_input').val()).to.equal('127');
}); });
it('updates the range slider when line height input changes', function () {
view.$('.mailpoet_field_button_line_height_input').val('37').keyup(); it('updates the model when line height changes', function () {
expect(view.$('.mailpoet_field_button_line_height').val()).to.equal('37'); view.$('.mailpoet_field_button_line_height').val('37').change();
}); expect(model.get('styles.block.lineHeight')).to.equal('37px');
it('updates the input when line height range slider changes', function () { });
view.$('.mailpoet_field_button_line_height').val('37').change(); it('updates the range slider when line height input changes', function () {
expect(view.$('.mailpoet_field_button_line_height_input').val()).to.equal('37'); view.$('.mailpoet_field_button_line_height_input').val('37').keyup();
}); expect(view.$('.mailpoet_field_button_line_height').val()).to.equal('37');
});
it('does not display link option when `hideLink` option is active', function() { it('updates the input when line height range slider changes', function () {
view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({ view.$('.mailpoet_field_button_line_height').val('37').change();
model: model, expect(view.$('.mailpoet_field_button_line_height_input').val()).to.equal('37');
renderOptions: { });
hideLink: true,
}, it('does not display link option when `hideLink` option is active', function() {
}); view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({
view.render(); model: model,
expect(view.$('.mailpoet_field_button_url').length).to.equal(0); renderOptions: {
}); hideLink: true,
},
it('does not display "Apply to all" option when `hideApplyToAll` option is active', function() { });
view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({ view.render();
model: model, expect(view.$('.mailpoet_field_button_url').length).to.equal(0);
renderOptions: { });
hideApplyToAll: true,
}, it('does not display "Apply to all" option when `hideApplyToAll` option is active', function() {
}); view = new (EditorApplication.module('blocks.button').ButtonBlockSettingsView)({
view.render(); model: model,
expect(view.$('.mailpoet_field_button_replace_all_styles').length).to.equal(0); renderOptions: {
}); hideApplyToAll: true,
},
it('closes the sidepanel after "Done" is clicked', function () { });
var mock = sinon.mock().once(); view.render();
global.MailPoet.Modal.cancel = mock; expect(view.$('.mailpoet_field_button_replace_all_styles').length).to.equal(0);
view.$('.mailpoet_done_editing').click(); });
mock.verify();
delete(global.MailPoet.Modal.cancel); it.skip('closes the sidepanel after "Done" is clicked', function () {
}); var mock = sinon.mock().once();
}); global.MailPoet.Modal.cancel = mock;
}); view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
}); });

View File

@ -1,192 +1,207 @@
describe('Container', function () { define('test/newsletter_editor/blocks/container', [
var ModelClass = EditorApplication.module('blocks.container').ContainerBlockModel; 'newsletter_editor/App',
'newsletter_editor/blocks/container'
], function(EditorApplication) {
describe('model', function () { describe('Container', function () {
describe('by default', function () { var ModelClass = EditorApplication.module('blocks.container').ContainerBlockModel;
global.stubConfig();
var model = new ModelClass();
it('has container type', function () { describe('model', function () {
expect(model.get('type')).to.equal('container'); describe('by default', function () {
global.stubConfig(EditorApplication);
var model = new ModelClass();
it('has container type', function () {
expect(model.get('type')).to.equal('container');
});
it('has orientation', function () {
expect(model.get('orientation')).to.equal('vertical');
});
it('has a background color', function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
});
it('has a collection of blocks', function () {
expect(model.get('blocks')).to.be.instanceof(Backbone.Collection);
});
it("uses defaults from config when they are set", function () {
global.stubConfig(EditorApplication, {
blockDefaults: {
container: {
styles: {
block: {
backgroundColor: '#123456',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)();
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
});
});
describe('when creating with children', function () {
var testModel = {
type: 'sampleType',
someField: 'Some Content',
},
model;
it('will recursively create children', function () {
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.container').ContainerBlockModel)({
type: 'container',
blocks: [testModel],
}, {parse: true});
expect(model.get('blocks')).to.have.length(1);
expect(model.get('blocks').at(0).get('type')).to.equal(testModel.type);
expect(model.get('blocks').at(0).get('someField')).to.equal(testModel.someField);
});
it('will create nested containers and their children', function () {
var stub = sinon.stub();
stub.withArgs('container').returns(ModelClass);
stub.withArgs('someType').returns(Backbone.Model);
EditorApplication.getBlockTypeModel = stub;
model = new ModelClass({
type: 'container',
blocks: [
{
type: 'container',
blocks: [
{
type: 'someType',
someField: 'some text',
},
{
type: 'someType',
someField: 'some text 2',
},
],
}
],
}, {parse: true});
expect(model.get('blocks')).to.have.length(1);
expect(model.get('blocks').at(0).get('blocks')).to.have.length(2);
expect(model.get('blocks').at(0).get('blocks').at(1).get('someField')).to.equal('some text 2');
});
});
});
describe('block view', function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
});
describe('once rendered', function () {
describe('on root level', function () {
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view;
beforeEach(function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication);
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({
model: model,
renderOptions: {
depth: 0,
},
});
view.render();
});
it('does not have a deletion tool', function () {
expect(view.$('.mailpoet_delete_block')).to.have.length(0);
});
it('does not have a move tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(0);
});
it('does not have a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(0);
});
});
describe.skip('on non-root levels', function () {
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view;
beforeEach(function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication);
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({
model: model,
renderOptions: {
depth: 1,
},
});
view.render();
});
it('has a deletion tool', function () {
expect(view.$('.mailpoet_delete_block')).to.have.length(1);
});
it('has a move tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(0);
});
it('has a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(1);
});
});
});
});
describe('settings view', function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view = new (EditorApplication.module('blocks.container').ContainerBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
});
describe('once rendered', function () {
var model, view;
beforeEach(function() {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication);
model = new (EditorApplication.module('blocks.container').ContainerBlockModel)();
view = new (EditorApplication.module('blocks.container').ContainerBlockSettingsView)({model: model});
}); });
it('has orientation', function () { it('updates the model when background color changes', function () {
expect(model.get('orientation')).to.equal('vertical'); view.$('.mailpoet_field_container_background_color').val('#123456').change();
}); expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
});
it('has a background color', function () { it.skip('closes the sidepanel after "Done" is clicked', function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); var mock = sinon.mock().once();
}); global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('has a collection of blocks', function () {
expect(model.get('blocks')).to.be.instanceof(Backbone.Collection);
});
it("uses defaults from config when they are set", function () {
global.stubConfig({
blockDefaults: {
container: {
styles: {
block: {
backgroundColor: '#123456',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)();
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
});
});
describe('when creating with children', function () {
var testModel = {
type: 'sampleType',
someField: 'Some Content',
},
model;
it('will recursively create children', function () {
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.container').ContainerBlockModel)({
type: 'container',
blocks: [testModel],
}, {parse: true});
expect(model.get('blocks')).to.have.length(1);
expect(model.get('blocks').at(0).get('type')).to.equal(testModel.type);
expect(model.get('blocks').at(0).get('someField')).to.equal(testModel.someField);
});
it('will create nested containers and their children', function () {
var stub = sinon.stub();
stub.withArgs('container').returns(ModelClass);
stub.withArgs('someType').returns(Backbone.Model);
EditorApplication.getBlockTypeModel = stub;
model = new ModelClass({
type: 'container',
blocks: [
{
type: 'container',
blocks: [
{
type: 'someType',
someField: 'some text',
},
{
type: 'someType',
someField: 'some text 2',
},
],
}
],
}, {parse: true});
expect(model.get('blocks')).to.have.length(1);
expect(model.get('blocks').at(0).get('blocks')).to.have.length(2);
expect(model.get('blocks').at(0).get('blocks').at(1).get('someField')).to.equal('some text 2');
});
});
});
describe('block view', function () {
global.stubChannel();
global.stubAvailableStyles();
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
});
describe('once rendered', function () {
describe('on root level', function () {
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view;
beforeEach(function () {
global.stubChannel();
global.stubAvailableStyles();
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({
model: model,
renderOptions: {
depth: 0,
},
});
view.render();
});
it('does not have a deletion tool', function () {
expect(view.$('.mailpoet_delete_block')).to.have.length(0);
});
it('does not have a move tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(0);
});
it('does not have a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(0);
});
});
describe.skip('on non-root levels', function () {
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view;
beforeEach(function () {
global.stubChannel();
global.stubAvailableStyles();
view = new (EditorApplication.module('blocks.container').ContainerBlockView)({
model: model,
renderOptions: {
depth: 1,
},
});
view.render();
});
it('has a deletion tool', function () {
expect(view.$('.mailpoet_delete_block')).to.have.length(1);
});
it('has a move tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(0);
});
it('has a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(1);
});
});
});
});
describe('settings view', function () {
global.stubChannel();
global.stubAvailableStyles();
var model = new (EditorApplication.module('blocks.container').ContainerBlockModel)(),
view = new (EditorApplication.module('blocks.container').ContainerBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
});
describe('once rendered', function () {
it('updates the model when background color changes', function () {
view.$('.mailpoet_field_container_background_color').val('#123456').change();
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,199 +1,206 @@
describe("Divider", function () { define('test/newsletter_editor/blocks/divider', [
describe("model", function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/divider'
], function(EditorApplication) {
beforeEach(function () { describe("Divider", function () {
global.stubChannel(); describe("model", function () {
global.stubConfig({ var model;
blockDefaults: {},
});
global.stubAvailableStyles();
model = new (EditorApplication.module('blocks.divider').DividerBlockModel)();
});
afterEach(function () { beforeEach(function () {
delete EditorApplication.getChannel; global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication, {
blockDefaults: {},
});
global.stubAvailableStyles(EditorApplication);
model = new (EditorApplication.module('blocks.divider').DividerBlockModel)();
});
it("has a divider type", function () { afterEach(function () {
expect(model.get('type')).to.equal('divider'); delete EditorApplication.getChannel;
}); });
it("has a background color", function () { it("has a divider type", function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('type')).to.equal('divider');
}); });
it("has padding", function () { it("has a background color", function () {
expect(model.get('styles.block.padding')).to.match(/^\d+px$/); expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('has border style', function () { it("has padding", function () {
expect(model.get('styles.block.borderStyle')).to.match(/^(none|dotted|dashed|solid|double|groove|ridge|inset|outset)$/); expect(model.get('styles.block.padding')).to.match(/^\d+px$/);
}); });
it('has border width', function () { it('has border style', function () {
expect(model.get('styles.block.borderWidth')).to.match(/^\d+px$/); expect(model.get('styles.block.borderStyle')).to.match(/^(none|dotted|dashed|solid|double|groove|ridge|inset|outset)$/);
}); });
it('has border color', function () { it('has border width', function () {
expect(model.get('styles.block.borderColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.block.borderWidth')).to.match(/^\d+px$/);
}); });
it("changes attributes with set", function () { it('has border color', function () {
var newValue = 'outset'; expect(model.get('styles.block.borderColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
model.set('styles.block.borderStyle', newValue); });
expect(model.get('styles.block.borderStyle')).to.equal(newValue);
});
it("triggers autosave if any attribute changes", function () { it("changes attributes with set", function () {
var mock = sinon.mock().exactly(5).withArgs('autoSave'); var newValue = 'outset';
EditorApplication.getChannel = sinon.stub().returns({ model.set('styles.block.borderStyle', newValue);
trigger: mock, expect(model.get('styles.block.borderStyle')).to.equal(newValue);
}); });
model.set('styles.block.backgroundColor', '#000000'); it("triggers autosave if any attribute changes", function () {
model.set('styles.block.padding', '19px'); var mock = sinon.mock().exactly(5).withArgs('autoSave');
model.set('styles.block.borderStyle', 'double'); EditorApplication.getChannel = sinon.stub().returns({
model.set('styles.block.borderWidth', '17px'); trigger: mock,
model.set('styles.block.borderColor', '#123456'); });
mock.verify(); model.set('styles.block.backgroundColor', '#000000');
}); model.set('styles.block.padding', '19px');
model.set('styles.block.borderStyle', 'double');
model.set('styles.block.borderWidth', '17px');
model.set('styles.block.borderColor', '#123456');
it("uses defaults from config when they are set", function () { mock.verify();
global.stubConfig({ });
blockDefaults: {
divider: {
styles: {
block: {
backgroundColor: '#123456',
padding: '37px',
borderStyle: 'inset',
borderWidth: '7px',
borderColor: '#345678',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)();
expect(model.get('styles.block.backgroundColor')).to.equal('#123456'); it("uses defaults from config when they are set", function () {
expect(model.get('styles.block.padding')).to.equal('37px'); global.stubConfig(EditorApplication, {
expect(model.get('styles.block.borderStyle')).to.equal('inset'); blockDefaults: {
expect(model.get('styles.block.borderWidth')).to.equal('7px'); divider: {
expect(model.get('styles.block.borderColor')).to.equal('#345678'); styles: {
}); block: {
}); backgroundColor: '#123456',
padding: '37px',
borderStyle: 'inset',
borderWidth: '7px',
borderColor: '#345678',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)();
describe('block view', function () { expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
global.stubChannel(); expect(model.get('styles.block.padding')).to.equal('37px');
global.stubConfig(); expect(model.get('styles.block.borderStyle')).to.equal('inset');
var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)(), expect(model.get('styles.block.borderWidth')).to.equal('7px');
view; expect(model.get('styles.block.borderColor')).to.equal('#345678');
});
});
beforeEach(function () { describe('block view', function () {
global.stubChannel(); global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.divider').DividerBlockView)({model: model}); global.stubConfig(EditorApplication);
}); var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)(),
view;
it('renders', function () { beforeEach(function () {
expect(view.render).to.not.throw(); global.stubChannel(EditorApplication);
expect(view.$('.mailpoet_divider')).to.have.length(1); view = new (EditorApplication.module('blocks.divider').DividerBlockView)({model: model});
}); });
it('rerenders if model attributes change', function () { it('renders', function () {
view.render(); expect(view.render).to.not.throw();
expect(view.$('.mailpoet_divider')).to.have.length(1);
});
model.set('styles.block.borderStyle', 'inset'); it('rerenders if model attributes change', function () {
view.render();
expect(view.$('.mailpoet_divider').css('border-top-style')).to.equal('inset'); model.set('styles.block.borderStyle', 'inset');
});
});
describe('settings view', function () { expect(view.$('.mailpoet_divider').css('border-top-style')).to.equal('inset');
global.stubChannel(); });
global.stubAvailableStyles({ });
dividers: ['solid', 'inset'],
});
var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)(),
view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({model: model});
it('renders', function () { describe('settings view', function () {
expect(view.render).to.not.throw(); global.stubChannel(EditorApplication);
expect(view.$('.mailpoet_divider_selector')).to.have.length(1); global.stubAvailableStyles(EditorApplication, {
}); dividers: ['solid', 'inset'],
});
var model = new (EditorApplication.module('blocks.divider').DividerBlockModel)(),
view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({model: model});
describe('once rendered', function () { it('renders', function () {
var model, view; expect(view.render).to.not.throw();
expect(view.$('.mailpoet_divider_selector')).to.have.length(1);
});
before(function() { describe('once rendered', function () {
global.stubChannel(); var model, view;
global.stubAvailableStyles({
dividers: ['solid', 'inset'],
});
});
beforeEach(function () { before(function() {
model = new (EditorApplication.module('blocks.divider').DividerBlockModel)(); global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({model: model}); global.stubAvailableStyles(EditorApplication, {
view.render(); dividers: ['solid', 'inset'],
}); });
});
it('updates the model when divider style changes', function () { beforeEach(function () {
view.$('.mailpoet_field_divider_style').last().click(); model = new (EditorApplication.module('blocks.divider').DividerBlockModel)();
expect(model.get('styles.block.borderStyle')).to.equal('inset'); view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({model: model});
}); view.render();
});
it('updates the model when divider width changes', function () { it('updates the model when divider style changes', function () {
view.$('.mailpoet_field_divider_border_width').val('17').change(); view.$('.mailpoet_field_divider_style').last().click();
expect(model.get('styles.block.borderWidth')).to.equal('17px'); expect(model.get('styles.block.borderStyle')).to.equal('inset');
}); });
it('updates the range slider when divider width input changes', function () { it('updates the model when divider width changes', function () {
view.$('.mailpoet_field_divider_border_width_input').val('19').keyup(); view.$('.mailpoet_field_divider_border_width').val('17').change();
expect(view.$('.mailpoet_field_divider_border_width').val()).to.equal('19'); expect(model.get('styles.block.borderWidth')).to.equal('17px');
}); });
it('updates the input when divider width range slider changes', function () { it('updates the range slider when divider width input changes', function () {
view.$('.mailpoet_field_divider_border_width').val('19').change(); view.$('.mailpoet_field_divider_border_width_input').val('19').keyup();
expect(view.$('.mailpoet_field_divider_border_width_input').val()).to.equal('19'); expect(view.$('.mailpoet_field_divider_border_width').val()).to.equal('19');
}); });
it('updates the model when divider color changes', function () { it('updates the input when divider width range slider changes', function () {
view.$('.mailpoet_field_divider_border_color').val('#123457').change(); view.$('.mailpoet_field_divider_border_width').val('19').change();
expect(model.get('styles.block.borderColor')).to.equal('#123457'); expect(view.$('.mailpoet_field_divider_border_width_input').val()).to.equal('19');
}); });
it('updates the model when divider background color changes', function () { it('updates the model when divider color changes', function () {
view.$('.mailpoet_field_divider_background_color').val('#cccccc').change(); view.$('.mailpoet_field_divider_border_color').val('#123457').change();
expect(model.get('styles.block.backgroundColor')).to.equal('#cccccc'); expect(model.get('styles.block.borderColor')).to.equal('#123457');
}); });
it ('changes color of available divider styles when actual divider color changes', function() { it('updates the model when divider background color changes', function () {
var newColor = '#889912'; view.$('.mailpoet_field_divider_background_color').val('#cccccc').change();
view.$('.mailpoet_field_divider_border_color').val(newColor).change(); expect(model.get('styles.block.backgroundColor')).to.equal('#cccccc');
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 ('changes color of available divider styles when actual divider color changes', function() {
view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({ var newColor = '#889912';
model: model, view.$('.mailpoet_field_divider_border_color').val(newColor).change();
renderOptions: { expect(view.$('.mailpoet_field_divider_style div')).to.have.$css('border-top-color', newColor);
hideApplyToAll: true, });
},
}); it('does not display "Apply to all" option when `hideApplyToAll` option is active', function() {
view.render(); view = new (EditorApplication.module('blocks.divider').DividerBlockSettingsView)({
expect(view.$('.mailpoet_button_divider_apply_to_all').length).to.equal(0); model: model,
}); renderOptions: {
hideApplyToAll: true,
},
});
view.render();
expect(view.$('.mailpoet_button_divider_apply_to_all').length).to.equal(0);
});
it.skip('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,189 +1,200 @@
describe('Footer', function () { define('test/newsletter_editor/blocks/footer', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/footer'
beforeEach(function () { ], function(EditorApplication) {
global.stubChannel();
model = new (EditorApplication.module('blocks.footer').FooterBlockModel)();
});
it('has a footer type', function () { describe('Footer', function () {
expect(model.get('type')).to.equal('footer'); describe('model', function () {
}); var model;
beforeEach(function () {
global.stubChannel(EditorApplication);
model = new (EditorApplication.module('blocks.footer').FooterBlockModel)();
});
it('has text', function () { it('has a footer type', function () {
expect(model.get('text')).to.be.a('string'); expect(model.get('type')).to.equal('footer');
}); });
it('has a background color', function () { it('has text', function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('text')).to.be.a('string');
}); });
it('has a text color', function () { it('has a background color', function () {
expect(model.get('styles.text.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('has a font family', function () { it('has a text color', function () {
expect(model.get('styles.text.fontFamily')).to.equal('Arial'); expect(model.get('styles.text.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('has a font size', function () { it('has a font family', function () {
expect(model.get('styles.text.fontSize')).to.match(/^\d+px$/); expect(model.get('styles.text.fontFamily')).to.equal('Arial');
}); });
it('has text alignment', function () { it('has a font size', function () {
expect(model.get('styles.text.textAlign')).to.match(/^(left|center|right|justify)$/); expect(model.get('styles.text.fontSize')).to.match(/^\d+px$/);
}); });
it('has a link color', function () { it('has text alignment', function () {
expect(model.get('styles.link.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.text.textAlign')).to.match(/^(left|center|right|justify)$/);
}); });
it('has link decoration', function () { it('has a link color', function () {
expect(model.get('styles.link.textDecoration')).to.match(/^(underline|none)$/); expect(model.get('styles.link.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('changes attributes with set', function () { it('has link decoration', function () {
var newValue = 'Some New Text'; expect(model.get('styles.link.textDecoration')).to.match(/^(underline|none)$/);
model.set('text', newValue); });
expect(model.get('text')).to.equal(newValue);
});
it('triggers autosave when any of the attributes change', function () { it('changes attributes with set', function () {
var mock = sinon.mock().exactly(8).withArgs('autoSave'); var newValue = 'Some New Text';
EditorApplication.getChannel = sinon.stub().returns({ model.set('text', newValue);
trigger: mock, expect(model.get('text')).to.equal(newValue);
});
it('triggers autosave when any of the attributes change', function () {
var mock = sinon.mock().exactly(8).withArgs('autoSave');
EditorApplication.getChannel = sinon.stub().returns({
trigger: mock,
});
model.set('text', 'Some new text');
model.set('styles.block.backgroundColor', '#123456');
model.set('styles.text.fontColor', '#123456');
model.set('styles.text.fontFamily', 'SomeFontCT');
model.set('styles.text.fontSize', '23px');
model.set('styles.text.textAlign', 'justify');
model.set('styles.link.fontColor', '#123456');
model.set('styles.link.textDecoration', 'underline');
mock.verify();
});
it("uses defaults from config when they are set", function () {
global.stubConfig(EditorApplication, {
blockDefaults: {
footer: {
text: 'some custom config text',
styles: {
block: {
backgroundColor: '#123456',
},
text: {
fontColor: '#234567',
fontFamily: 'Tahoma',
fontSize: '37px',
textAlign: 'right',
},
link: {
fontColor: '#345678',
textDecoration: 'underline',
},
},
}
},
});
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)();
expect(model.get('text')).to.equal('some custom config text');
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
expect(model.get('styles.text.fontColor')).to.equal('#234567');
expect(model.get('styles.text.fontFamily')).to.equal('Tahoma');
expect(model.get('styles.text.fontSize')).to.equal('37px');
expect(model.get('styles.text.textAlign')).to.equal('right');
expect(model.get('styles.link.fontColor')).to.equal('#345678');
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
});
describe('block view', function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)(),
view;
beforeEach(function () {
global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.footer').FooterBlockView)({model: model});
});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_content')).to.have.length(1);
});
});
describe('settings view', function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)(),
view = new (EditorApplication.module('blocks.footer').FooterBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_field_footer_text_color')).to.have.length(1);
});
describe('once rendered', function () {
var model, view;
beforeEach(function() {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
model = new (EditorApplication.module('blocks.footer').FooterBlockModel)({});
view = new (EditorApplication.module('blocks.footer').FooterBlockSettingsView)({model: model});
view.render();
}); });
model.set('text', 'Some new text'); it('updates the model when text font color changes', function () {
model.set('styles.block.backgroundColor', '#123456'); view.$('.mailpoet_field_footer_text_color').val('#123456').change();
model.set('styles.text.fontColor', '#123456'); expect(model.get('styles.text.fontColor')).to.equal('#123456');
model.set('styles.text.fontFamily', 'SomeFontCT'); });
model.set('styles.text.fontSize', '23px');
model.set('styles.text.textAlign', 'justify');
model.set('styles.link.fontColor', '#123456');
model.set('styles.link.textDecoration', 'underline');
mock.verify(); it('updates the model when text font family changes', function () {
}); var value = 'Tahoma';
view.$('.mailpoet_field_footer_text_font_family').val(value).change();
expect(model.get('styles.text.fontFamily')).to.equal(value);
});
it("uses defaults from config when they are set", function () { it('updates the model when text font size changes', function () {
global.stubConfig({ var value = '20px';
blockDefaults: { view.$('.mailpoet_field_footer_text_size').val(value).change();
footer: { expect(model.get('styles.text.fontSize')).to.equal(value);
text: 'some custom config text', });
styles: {
block: {
backgroundColor: '#123456',
},
text: {
fontColor: '#234567',
fontFamily: 'Tahoma',
fontSize: '37px',
textAlign: 'right',
},
link: {
fontColor: '#345678',
textDecoration: 'underline',
},
},
}
},
});
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)();
expect(model.get('text')).to.equal('some custom config text'); it('updates the model when link font color changes', function () {
expect(model.get('styles.block.backgroundColor')).to.equal('#123456'); view.$('#mailpoet_field_footer_link_color').val('#123456').change();
expect(model.get('styles.text.fontColor')).to.equal('#234567'); expect(model.get('styles.link.fontColor')).to.equal('#123456');
expect(model.get('styles.text.fontFamily')).to.equal('Tahoma'); });
expect(model.get('styles.text.fontSize')).to.equal('37px');
expect(model.get('styles.text.textAlign')).to.equal('right');
expect(model.get('styles.link.fontColor')).to.equal('#345678');
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
}); it('updates the model when link text decoration changes', function () {
view.$('#mailpoet_field_footer_link_underline').prop('checked', true).change();
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
describe('block view', function () { it('updates the model when background color changes', function () {
global.stubChannel(); view.$('.mailpoet_field_footer_alignment').last().prop('checked', true).change();
global.stubConfig(); expect(model.get('styles.text.textAlign')).to.equal('right');
global.stubAvailableStyles(); });
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)(),
view;
beforeEach(function () { it.skip('closes the sidepanel after "Done" is clicked', function () {
global.stubChannel(); var mock = sinon.mock().once();
view = new (EditorApplication.module('blocks.footer').FooterBlockView)({model: model}); global.MailPoet.Modal.cancel = mock;
}); view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_content')).to.have.length(1);
});
});
describe('settings view', function () {
global.stubChannel();
global.stubAvailableStyles({
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)(),
view = new (EditorApplication.module('blocks.footer').FooterBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_field_footer_text_color')).to.have.length(1);
});
describe('once rendered', function () {
global.stubChannel();
global.stubAvailableStyles({
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.footer').FooterBlockModel)({}),
view = new (EditorApplication.module('blocks.footer').FooterBlockSettingsView)({model: model});
view.render();
it('updates the model when text font color changes', function () {
view.$('.mailpoet_field_footer_text_color').val('#123456').change();
expect(model.get('styles.text.fontColor')).to.equal('#123456');
});
it('updates the model when text font family changes', function () {
var value = 'Tahoma';
view.$('.mailpoet_field_footer_text_font_family').val(value).change();
expect(model.get('styles.text.fontFamily')).to.equal(value);
});
it('updates the model when text font size changes', function () {
var value = '20px';
view.$('.mailpoet_field_footer_text_size').val(value).change();
expect(model.get('styles.text.fontSize')).to.equal(value);
});
it('updates the model when link font color changes', function () {
view.$('#mailpoet_field_footer_link_color').val('#123456').change();
expect(model.get('styles.link.fontColor')).to.equal('#123456');
});
it('updates the model when link text decoration changes', function () {
view.$('#mailpoet_field_footer_link_underline').prop('checked', true).change();
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
it('updates the model when background color changes', function () {
view.$('.mailpoet_field_footer_alignment').last().prop('checked', true).change();
expect(model.get('styles.text.textAlign')).to.equal('right');
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,192 +1,203 @@
describe('Header', function () { define('test/newsletter_editor/blocks/header', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/header'
beforeEach(function () { ], function(EditorApplication) {
global.stubChannel();
stubConfig({
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.header').HeaderBlockModel)();
});
it('has a header type', function () { describe('Header', function () {
expect(model.get('type')).to.equal('header'); describe('model', function () {
}); var model;
beforeEach(function () {
global.stubChannel(EditorApplication);
global. stubConfig(EditorApplication, {
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.header').HeaderBlockModel)();
});
it('has text', function () { it('has a header type', function () {
expect(model.get('text')).to.be.a('string'); expect(model.get('type')).to.equal('header');
}); });
it('has background color', function () { it('has text', function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('text')).to.be.a('string');
}); });
it('has a text color', function () { it('has background color', function () {
expect(model.get('styles.text.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('has a text font family', function () { it('has a text color', function () {
expect(model.get('styles.text.fontFamily')).to.equal('Arial'); expect(model.get('styles.text.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it('has a text font size', function () { it('has a text font family', function () {
expect(model.get('styles.text.fontSize')).to.match(/^\d+px$/); expect(model.get('styles.text.fontFamily')).to.equal('Arial');
}); });
it('has text align', function () { it('has a text font size', function () {
expect(model.get('styles.text.textAlign')).to.match(/^(left|center|right|justify)$/); expect(model.get('styles.text.fontSize')).to.match(/^\d+px$/);
}); });
it('has link color', function () { it('has text align', function () {
expect(model.get('styles.link.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.text.textAlign')).to.match(/^(left|center|right|justify)$/);
}); });
it('has link text decoration', function () { it('has link color', function () {
expect(model.get('styles.link.textDecoration')).to.match(/^(underline|none)$/); expect(model.get('styles.link.fontColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
}); });
it("changes attributes with set", function () { it('has link text decoration', function () {
var newValue = 'Some random teeeext'; expect(model.get('styles.link.textDecoration')).to.match(/^(underline|none)$/);
model.set('text', newValue); });
expect(model.get('text')).to.equal(newValue);
});
it("triggers autosave if any attribute changes", function () { it("changes attributes with set", function () {
var mock = sinon.mock().exactly(8).withArgs('autoSave'); var newValue = 'Some random teeeext';
EditorApplication.getChannel = sinon.stub().returns({ model.set('text', newValue);
trigger: mock, expect(model.get('text')).to.equal(newValue);
});
it("triggers autosave if any attribute changes", function () {
var mock = sinon.mock().exactly(8).withArgs('autoSave');
EditorApplication.getChannel = sinon.stub().returns({
trigger: mock,
});
model.set('text', 'Some new text');
model.set('styles.block.backgroundColor', '#123456');
model.set('styles.text.fontColor', '#123456');
model.set('styles.text.fontFamily', 'SomeFontCT');
model.set('styles.text.fontSize', '23px');
model.set('styles.text.textAlign', 'justify');
model.set('styles.link.fontColor', '#123456');
model.set('styles.link.textDecoration', 'none');
mock.verify();
});
it("uses defaults from config when they are set", function () {
global.stubConfig(EditorApplication, {
blockDefaults: {
header: {
text: 'some custom config text',
styles: {
block: {
backgroundColor: '#123456',
},
text: {
fontColor: '#234567',
fontFamily: 'Tahoma',
fontSize: '37px',
textAlign: 'right',
},
link: {
fontColor: '#345678',
textDecoration: 'underline',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)();
expect(model.get('text')).to.equal('some custom config text');
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
expect(model.get('styles.text.fontColor')).to.equal('#234567');
expect(model.get('styles.text.fontFamily')).to.equal('Tahoma');
expect(model.get('styles.text.fontSize')).to.equal('37px');
expect(model.get('styles.text.textAlign')).to.equal('right');
expect(model.get('styles.link.fontColor')).to.equal('#345678');
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
});
describe('block view', function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)(),
view;
beforeEach(function () {
global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.header').HeaderBlockView)({model: model});
});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_content')).to.have.length(1);
});
});
describe('settings view', function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)(),
view = new (EditorApplication.module('blocks.header').HeaderBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_field_header_text_color')).to.have.length(1);
});
describe('once rendered', function () {
var model, view;
beforeEach(function() {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
model = new (EditorApplication.module('blocks.header').HeaderBlockModel)({});
view = new (EditorApplication.module('blocks.header').HeaderBlockSettingsView)({model: model});
view.render();
}); });
model.set('text', 'Some new text'); it('updates the model when text font color changes', function () {
model.set('styles.block.backgroundColor', '#123456'); view.$('.mailpoet_field_header_text_color').val('#123456').change();
model.set('styles.text.fontColor', '#123456'); expect(model.get('styles.text.fontColor')).to.equal('#123456');
model.set('styles.text.fontFamily', 'SomeFontCT'); });
model.set('styles.text.fontSize', '23px');
model.set('styles.text.textAlign', 'justify');
model.set('styles.link.fontColor', '#123456');
model.set('styles.link.textDecoration', 'none');
mock.verify(); it('updates the model when text font family changes', function () {
}); var value = 'Tahoma';
view.$('.mailpoet_field_header_text_font_family').val(value).change();
expect(model.get('styles.text.fontFamily')).to.equal(value);
});
it("uses defaults from config when they are set", function () { it('updates the model when text font size changes', function () {
global.stubConfig({ var value = '20px';
blockDefaults: { view.$('.mailpoet_field_header_text_size').val(value).change();
header: { expect(model.get('styles.text.fontSize')).to.equal(value);
text: 'some custom config text', });
styles: {
block: {
backgroundColor: '#123456',
},
text: {
fontColor: '#234567',
fontFamily: 'Tahoma',
fontSize: '37px',
textAlign: 'right',
},
link: {
fontColor: '#345678',
textDecoration: 'underline',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)();
expect(model.get('text')).to.equal('some custom config text'); it('updates the model when link font color changes', function () {
expect(model.get('styles.block.backgroundColor')).to.equal('#123456'); view.$('#mailpoet_field_header_link_color').val('#123456').change();
expect(model.get('styles.text.fontColor')).to.equal('#234567'); expect(model.get('styles.link.fontColor')).to.equal('#123456');
expect(model.get('styles.text.fontFamily')).to.equal('Tahoma'); });
expect(model.get('styles.text.fontSize')).to.equal('37px');
expect(model.get('styles.text.textAlign')).to.equal('right');
expect(model.get('styles.link.fontColor')).to.equal('#345678');
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
});
describe('block view', function () { it('updates the model when link text decoration changes', function () {
global.stubChannel(); view.$('#mailpoet_field_header_link_underline').prop('checked', true).change();
global.stubConfig(); expect(model.get('styles.link.textDecoration')).to.equal('underline');
global.stubAvailableStyles(); });
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)(),
view;
beforeEach(function () { it('updates the model when text alignment changes', function () {
global.stubChannel(); view.$('.mailpoet_field_header_alignment').last().prop('checked', true).change();
view = new (EditorApplication.module('blocks.header').HeaderBlockView)({model: model}); expect(model.get('styles.text.textAlign')).to.equal('right');
}); });
it('renders', function () { it.skip('closes the sidepanel after "Done" is clicked', function () {
expect(view.render).to.not.throw(); var mock = sinon.mock().once();
expect(view.$('.mailpoet_content')).to.have.length(1); global.MailPoet.Modal.cancel = mock;
}); view.$('.mailpoet_done_editing').click();
}); mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
describe('settings view', function () {
global.stubChannel();
global.stubConfig();
global.stubAvailableStyles({
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)(),
view = new (EditorApplication.module('blocks.header').HeaderBlockSettingsView)({model: model});
it('renders', function () {
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_field_header_text_color')).to.have.length(1);
});
describe('once rendered', function () {
global.stubChannel();
global.stubAvailableStyles({
fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'],
});
var model = new (EditorApplication.module('blocks.header').HeaderBlockModel)({}),
view = new (EditorApplication.module('blocks.header').HeaderBlockSettingsView)({model: model});
view.render();
it('updates the model when text font color changes', function () {
view.$('.mailpoet_field_header_text_color').val('#123456').change();
expect(model.get('styles.text.fontColor')).to.equal('#123456');
});
it('updates the model when text font family changes', function () {
var value = 'Tahoma';
view.$('.mailpoet_field_header_text_font_family').val(value).change();
expect(model.get('styles.text.fontFamily')).to.equal(value);
});
it('updates the model when text font size changes', function () {
var value = '20px';
view.$('.mailpoet_field_header_text_size').val(value).change();
expect(model.get('styles.text.fontSize')).to.equal(value);
});
it('updates the model when link font color changes', function () {
view.$('#mailpoet_field_header_link_color').val('#123456').change();
expect(model.get('styles.link.fontColor')).to.equal('#123456');
});
it('updates the model when link text decoration changes', function () {
view.$('#mailpoet_field_header_link_underline').prop('checked', true).change();
expect(model.get('styles.link.textDecoration')).to.equal('underline');
});
it('updates the model when text alignment changes', function () {
view.$('.mailpoet_field_header_alignment').last().prop('checked', true).change();
expect(model.get('styles.text.textAlign')).to.equal('right');
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,193 +1,200 @@
describe('Image', function () { define('test/newsletter_editor/blocks/image', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/image'
beforeEach(function () { ], function(EditorApplication) {
global.stubChannel();
global.stubConfig({
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
});
it('has an image type', function () { describe('Image', function () {
expect(model.get('type')).to.equal('image'); describe('model', function () {
}); var model;
beforeEach(function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication, {
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
});
it('has a link', function () { it('has an image type', function () {
expect(model.get('link')).to.be.a('string'); expect(model.get('type')).to.equal('image');
}); });
it('has an image src', function () { it('has a link', function () {
expect(model.get('src')).to.be.a('string'); expect(model.get('link')).to.be.a('string');
}); });
it('has alt text', function () { it('has an image src', function () {
expect(model.get('alt')).to.be.a('string'); expect(model.get('src')).to.be.a('string');
}); });
it('can be padded', function () { it('has alt text', function () {
expect(model.get('padded')).to.be.a('boolean'); expect(model.get('alt')).to.be.a('string');
}); });
it('has a width', function () { it('can be padded', function () {
expect(model.get('width')).to.match(/^\d+px$/); expect(model.get('padded')).to.be.a('boolean');
}); });
it('has a height', function () { it('has a width', function () {
expect(model.get('height')).to.match(/^\d+px$/); expect(model.get('width')).to.match(/^\d+px$/);
}); });
it('has alignment', function () { it('has a height', function () {
expect(model.get('styles.block.textAlign')).to.match(/^(left|center|right)$/); expect(model.get('height')).to.match(/^\d+px$/);
}); });
it('changes attributes with set', function () { it('has alignment', function () {
var newValue = 'someImage.png'; expect(model.get('styles.block.textAlign')).to.match(/^(left|center|right)$/);
model.set('src', newValue); });
expect(model.get('src')).to.equal(newValue);
});
it('triggers autosave when any of the attributes change', function () { it('changes attributes with set', function () {
var mock = sinon.mock().exactly(7).withArgs('autoSave'); var newValue = 'someImage.png';
EditorApplication.getChannel = sinon.stub().returns({ model.set('src', newValue);
trigger: mock, expect(model.get('src')).to.equal(newValue);
}); });
model.set('link', 'http://example.net'); it('triggers autosave when any of the attributes change', function () {
model.set('src', 'someNewImage.png'); var mock = sinon.mock().exactly(7).withArgs('autoSave');
model.set('alt', 'Some alt text'); EditorApplication.getChannel = sinon.stub().returns({
model.set('padded', false); trigger: mock,
model.set('width', '63px'); });
model.set('height', '61px');
model.set('styles.block.textAlign', 'right');
mock.verify(); model.set('link', 'http://example.net');
}); model.set('src', 'someNewImage.png');
model.set('alt', 'Some alt text');
model.set('padded', false);
model.set('width', '63px');
model.set('height', '61px');
model.set('styles.block.textAlign', 'right');
it("uses defaults from config when they are set", function () { mock.verify();
global.stubConfig({ });
blockDefaults: {
image: {
link: 'http://example.org/customConfigPage',
src: 'http://example.org/someCustomConfigImage.png',
alt: 'Custom config alt',
padded: false,
width: '1234px',
height: '2345px',
styles: {
block: {
textAlign: 'right',
},
},
}
},
});
var model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
expect(model.get('link')).to.equal('http://example.org/customConfigPage'); it("uses defaults from config when they are set", function () {
expect(model.get('src')).to.equal('http://example.org/someCustomConfigImage.png'); global.stubConfig(EditorApplication, {
expect(model.get('alt')).to.equal('Custom config alt'); blockDefaults: {
expect(model.get('padded')).to.equal(false); image: {
expect(model.get('width')).to.equal('1234px'); link: 'http://example.org/customConfigPage',
expect(model.get('height')).to.equal('2345px'); src: 'http://example.org/someCustomConfigImage.png',
expect(model.get('styles.block.textAlign')).to.equal('right'); alt: 'Custom config alt',
}); padded: false,
}); width: '1234px',
height: '2345px',
styles: {
block: {
textAlign: 'right',
},
},
}
},
});
var model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
describe('block view', function () { expect(model.get('link')).to.equal('http://example.org/customConfigPage');
global.stubChannel(); expect(model.get('src')).to.equal('http://example.org/someCustomConfigImage.png');
global.stubConfig(); expect(model.get('alt')).to.equal('Custom config alt');
global.stubAvailableStyles(); expect(model.get('padded')).to.equal(false);
var model = new (EditorApplication.module('blocks.image').ImageBlockModel)(), expect(model.get('width')).to.equal('1234px');
view; expect(model.get('height')).to.equal('2345px');
expect(model.get('styles.block.textAlign')).to.equal('right');
});
});
beforeEach(function () { describe('block view', function () {
view = new (EditorApplication.module('blocks.image').ImageBlockView)({model: model}); global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.image').ImageBlockModel)(),
view;
it('renders', function () { beforeEach(function () {
expect(view.render).to.not.throw(); view = new (EditorApplication.module('blocks.image').ImageBlockView)({model: model});
expect(view.$('.mailpoet_content')).to.have.length(1); });
});
describe('once rendered', function () { it('renders', function () {
var model = new (EditorApplication.module('blocks.image').ImageBlockModel)({ expect(view.render).to.not.throw();
link: 'http://example.org/somepath', expect(view.$('.mailpoet_content')).to.have.length(1);
src: 'http://example.org/someimage.png', });
alt: 'some alt',
}),
view;
beforeEach(function () { describe('once rendered', function () {
global.stubChannel(); var model = new (EditorApplication.module('blocks.image').ImageBlockModel)({
global.stubAvailableStyles(); link: 'http://example.org/somepath',
view = new (EditorApplication.module('blocks.image').ImageBlockView)({model: model}); src: 'http://example.org/someimage.png',
view.render(); alt: 'some alt',
}); }),
view;
it('displays the image', function () { beforeEach(function () {
expect(view.$('.mailpoet_content a').attr('href')).to.equal('http://example.org/somepath'); global.stubChannel(EditorApplication);
expect(view.$('.mailpoet_content img').attr('src')).to.equal('http://example.org/someimage.png'); global.stubAvailableStyles(EditorApplication);
expect(view.$('.mailpoet_content img').attr('alt')).to.equal('some alt'); view = new (EditorApplication.module('blocks.image').ImageBlockView)({model: model});
}); view.render();
});
it('rerenders if attribute changes', function () { it('displays the image', function () {
var newValue = 'http://example.org/someNEWimage.png'; expect(view.$('.mailpoet_content a').attr('href')).to.equal('http://example.org/somepath');
expect(view.$('.mailpoet_content img').attr('src')).to.not.equal(newValue); expect(view.$('.mailpoet_content img').attr('src')).to.equal('http://example.org/someimage.png');
model.set('src', newValue); expect(view.$('.mailpoet_content img').attr('alt')).to.equal('some alt');
expect(view.$('.mailpoet_content img').attr('src')).to.equal(newValue); });
});
});
});
describe('block settings view', function () { it('rerenders if attribute changes', function () {
var model, view; var newValue = 'http://example.org/someNEWimage.png';
expect(view.$('.mailpoet_content img').attr('src')).to.not.equal(newValue);
model.set('src', newValue);
expect(view.$('.mailpoet_content img').attr('src')).to.equal(newValue);
});
});
});
before(function () { describe('block settings view', function () {
global.stubChannel(); var model, view;
global.stubConfig({
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
view = new (EditorApplication.module('blocks.image').ImageBlockSettingsView)({model: model});
});
it('renders', function () { before(function () {
expect(view.render).to.not.throw(); global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication, {
blockDefaults: {},
});
model = new (EditorApplication.module('blocks.image').ImageBlockModel)();
view = new (EditorApplication.module('blocks.image').ImageBlockSettingsView)({model: model});
});
describe('once rendered', function () { it('renders', function () {
it('updates the model when link changes', function () { expect(view.render).to.not.throw();
var newValue = 'http://example.org/someNewLink'; });
view.$('.mailpoet_field_image_link').val(newValue).keyup();
expect(model.get('link')).to.equal(newValue);
});
it('updates the model when src changes', function () { describe('once rendered', function () {
var newValue = 'http://example.org/someNewImage.png'; it('updates the model when link changes', function () {
view.$('.mailpoet_field_image_address').val(newValue).keyup(); var newValue = 'http://example.org/someNewLink';
expect(model.get('src')).to.equal(newValue); view.$('.mailpoet_field_image_link').val(newValue).keyup();
}); expect(model.get('link')).to.equal(newValue);
});
it('updates the model when alt changes', function () { it('updates the model when src changes', function () {
var newValue = 'Some new alt text'; var newValue = 'http://example.org/someNewImage.png';
view.$('.mailpoet_field_image_alt_text').val(newValue).keyup(); view.$('.mailpoet_field_image_address').val(newValue).keyup();
expect(model.get('alt')).to.equal(newValue); expect(model.get('src')).to.equal(newValue);
}); });
it('updates the model when padding changes', function () { it('updates the model when alt changes', function () {
var newValue = 'false'; var newValue = 'Some new alt text';
view.$('.mailpoet_field_image_padded').val(newValue).change(); view.$('.mailpoet_field_image_alt_text').val(newValue).keyup();
expect(model.get('padded')).to.equal(false); expect(model.get('alt')).to.equal(newValue);
}); });
it('updates the model when padding changes', function () {
var newValue = 'false';
view.$('.mailpoet_field_image_padded').val(newValue).change();
expect(model.get('padded')).to.equal(false);
});
it.skip('closes the sidepanel after "Done" is clicked', function() {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('closes the sidepanel after "Done" is clicked', function() {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,381 +1,388 @@
describe('Posts', function () { define('test/newsletter_editor/blocks/posts', [
Backbone.Radio = { 'newsletter_editor/App',
Requests: { 'newsletter_editor/blocks/posts'
request: function () { ], function(EditorApplication) {
}, reply: function () {
},
},
};
describe('model', function () {
var model;
beforeEach(function () { describe('Posts', function () {
global.stubChannel(); Backbone.Radio = {
global.stubConfig(); Requests: {
global.mailpoet_post_wpi = sinon.stub(); request: function () {
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel); }, reply: function () {
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)(); },
}); },
};
describe('model', function () {
var model;
afterEach(function () { beforeEach(function () {
delete EditorApplication.getChannel; global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
global.mailpoet_post_wpi = sinon.stub();
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
});
it('has posts type', function () { afterEach(function () {
expect(model.get('type')).to.equal('posts'); delete EditorApplication.getChannel;
}); });
it('has post amount limit', function () { it('has posts type', function () {
expect(model.get('amount')).to.match(/^\d+$/); expect(model.get('type')).to.equal('posts');
}); });
it('has post type filter', function () { it('has post amount limit', function () {
expect(model.get('contentType')).to.match(/^(post|page|mailpoet_page)$/); expect(model.get('amount')).to.match(/^\d+$/);
}); });
it('has terms filter', function () { it('has post type filter', function () {
expect(model.get('terms')).to.have.length(0); expect(model.get('contentType')).to.match(/^(post|page|mailpoet_page)$/);
}); });
it('has inclusion filter', function () { it('has terms filter', function () {
expect(model.get('inclusionType')).to.match(/^(include|exclude)$/); expect(model.get('terms')).to.have.length(0);
}); });
it('has display type', function () { it('has inclusion filter', function () {
expect(model.get('displayType')).to.match(/^(excerpt|full|titleOnly)$/); expect(model.get('inclusionType')).to.match(/^(include|exclude)$/);
}); });
it('has title heading format', function () { it('has display type', function () {
expect(model.get('titleFormat')).to.match(/^(h1|h2|h3|ul)$/); expect(model.get('displayType')).to.match(/^(excerpt|full|titleOnly)$/);
}); });
it('has title position', function () { it('has title heading format', function () {
expect(model.get('titlePosition')).to.match(/^(inTextBlock|aboveBlock)$/); expect(model.get('titleFormat')).to.match(/^(h1|h2|h3|ul)$/);
}); });
it('has title alignment', function () { it('has title position', function () {
expect(model.get('titleAlignment')).to.match(/^(left|center|right)$/); expect(model.get('titlePosition')).to.match(/^(inTextBlock|aboveBlock)$/);
}); });
it('optionally has title as link', function () { it('has title alignment', function () {
expect(model.get('titleIsLink')).to.be.a('boolean'); expect(model.get('titleAlignment')).to.match(/^(left|center|right)$/);
}); });
it('has image specific alignment', function () { it('optionally has title as link', function () {
expect(model.get('imagePadded')).to.be.a('boolean'); expect(model.get('titleIsLink')).to.be.a('boolean');
}); });
it('has an option to display author', function () { it('has image specific alignment', function () {
expect(model.get('showAuthor')).to.match(/^(no|aboveText|belowText)$/); expect(model.get('imagePadded')).to.be.a('boolean');
}); });
it('has text preceding author', function () { it('has an option to display author', function () {
expect(model.get('authorPrecededBy')).to.be.a('string'); expect(model.get('showAuthor')).to.match(/^(no|aboveText|belowText)$/);
}); });
it('has an option to display categories', function () { it('has text preceding author', function () {
expect(model.get('showCategories')).to.match(/^(no|aboveText|belowText)$/); expect(model.get('authorPrecededBy')).to.be.a('string');
}); });
it('has text preceding categories', function () { it('has an option to display categories', function () {
expect(model.get('categoriesPrecededBy')).to.be.a('string'); expect(model.get('showCategories')).to.match(/^(no|aboveText|belowText)$/);
}); });
it('has a link or a button type for read more', function () { it('has text preceding categories', function () {
expect(model.get('readMoreType')).to.match(/^(link|button)$/); expect(model.get('categoriesPrecededBy')).to.be.a('string');
}); });
it('has read more text', function () { it('has a link or a button type for read more', function () {
expect(model.get('readMoreText')).to.be.a('string'); expect(model.get('readMoreType')).to.match(/^(link|button)$/);
}); });
it('has a read more button', function () { it('has read more text', function () {
expect(model.get('readMoreButton')).to.be.instanceof(Backbone.Model); expect(model.get('readMoreText')).to.be.a('string');
}); });
it('has sorting', function () { it('has a read more button', function () {
expect(model.get('sortBy')).to.match(/^(newest|oldest)$/); expect(model.get('readMoreButton')).to.be.instanceof(Backbone.Model);
}); });
it('has an option to display divider', function () { it('has sorting', function () {
expect(model.get('showDivider')).to.be.a('boolean'); expect(model.get('sortBy')).to.match(/^(newest|oldest)$/);
}); });
it('has a divider', function () { it('has an option to display divider', function () {
expect(model.get('divider')).to.be.instanceof(Backbone.Model); expect(model.get('showDivider')).to.be.a('boolean');
}); });
it("uses defaults from config when they are set", function () { it('has a divider', function () {
global.stubConfig({ expect(model.get('divider')).to.be.instanceof(Backbone.Model);
blockDefaults: { });
posts: {
amount: '17',
contentType: 'mailpoet_page', // 'post'|'page'|'mailpoet_page'
inclusionType: 'exclude', // 'include'|'exclude'
displayType: 'full', // 'excerpt'|'full'|'titleOnly'
titleFormat: 'h3', // 'h1'|'h2'|'h3'|'ul'
titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
titleAlignment: 'right', // 'left'|'center'|'right'
titleIsLink: true, // false|true
imagePadded: false, // true|false
//imageAlignment: 'right', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
authorPrecededBy: 'Custom config author preceded by',
showCategories: 'belowText', // 'no'|'aboveText'|'belowText'
categoriesPrecededBy: 'Custom config categories preceded by',
readMoreType: 'button', // 'link'|'button'
readMoreText: 'Custom Config read more text',
readMoreButton: {
text: 'Custom config read more',
url: '[postLink]',
styles: {
block: {
backgroundColor: '#123456',
borderColor: '#234567',
},
link: {
fontColor: '#345678',
fontFamily: 'Tahoma',
fontSize: '37px',
},
},
},
sortBy: 'oldest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {
src: 'http://example.org/someConfigDividerImage.png',
styles: {
block: {
backgroundColor: '#456789',
padding: '38px',
},
},
},
},
},
});
var model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
expect(model.get('amount')).to.equal('17'); it("uses defaults from config when they are set", function () {
expect(model.get('contentType')).to.equal('mailpoet_page'); global.stubConfig(EditorApplication, {
expect(model.get('inclusionType')).to.equal('exclude'); blockDefaults: {
expect(model.get('displayType')).to.equal('full'); posts: {
expect(model.get('titleFormat')).to.equal('h3'); amount: '17',
expect(model.get('titlePosition')).to.equal('aboveBlock'); contentType: 'mailpoet_page', // 'post'|'page'|'mailpoet_page'
expect(model.get('titleAlignment')).to.equal('right'); inclusionType: 'exclude', // 'include'|'exclude'
expect(model.get('titleIsLink')).to.equal(true); displayType: 'full', // 'excerpt'|'full'|'titleOnly'
expect(model.get('imagePadded')).to.equal(false); titleFormat: 'h3', // 'h1'|'h2'|'h3'|'ul'
expect(model.get('showAuthor')).to.equal('belowText'); titlePosition: 'aboveBlock', // 'inTextBlock'|'aboveBlock',
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by'); titleAlignment: 'right', // 'left'|'center'|'right'
expect(model.get('showCategories')).to.equal('belowText'); titleIsLink: true, // false|true
expect(model.get('categoriesPrecededBy')).to.equal('Custom config categories preceded by'); imagePadded: false, // true|false
expect(model.get('readMoreType')).to.equal('button'); //imageAlignment: 'right', // 'centerFull'|'centerPadded'|'left'|'right'|'alternate'|'none'
expect(model.get('readMoreText')).to.equal('Custom Config read more text'); showAuthor: 'belowText', // 'no'|'aboveText'|'belowText'
expect(model.get('readMoreButton.text')).to.equal('Custom config read more'); authorPrecededBy: 'Custom config author preceded by',
expect(model.get('readMoreButton.url')).to.equal('[postLink]'); showCategories: 'belowText', // 'no'|'aboveText'|'belowText'
expect(model.get('readMoreButton.styles.block.backgroundColor')).to.equal('#123456'); categoriesPrecededBy: 'Custom config categories preceded by',
expect(model.get('readMoreButton.styles.block.borderColor')).to.equal('#234567'); readMoreType: 'button', // 'link'|'button'
expect(model.get('readMoreButton.styles.link.fontColor')).to.equal('#345678'); readMoreText: 'Custom Config read more text',
expect(model.get('readMoreButton.styles.link.fontFamily')).to.equal('Tahoma'); readMoreButton: {
expect(model.get('readMoreButton.styles.link.fontSize')).to.equal('37px'); text: 'Custom config read more',
expect(model.get('sortBy')).to.equal('oldest'); url: '[postLink]',
expect(model.get('showDivider')).to.equal(true); styles: {
expect(model.get('divider.src')).to.equal('http://example.org/someConfigDividerImage.png'); block: {
expect(model.get('divider.styles.block.backgroundColor')).to.equal('#456789'); backgroundColor: '#123456',
expect(model.get('divider.styles.block.padding')).to.equal('38px'); borderColor: '#234567',
}); },
}); link: {
fontColor: '#345678',
fontFamily: 'Tahoma',
fontSize: '37px',
},
},
},
sortBy: 'oldest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {
src: 'http://example.org/someConfigDividerImage.png',
styles: {
block: {
backgroundColor: '#456789',
padding: '38px',
},
},
},
},
},
});
var model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
describe('block view', function () { expect(model.get('amount')).to.equal('17');
var model, view; expect(model.get('contentType')).to.equal('mailpoet_page');
expect(model.get('inclusionType')).to.equal('exclude');
expect(model.get('displayType')).to.equal('full');
expect(model.get('titleFormat')).to.equal('h3');
expect(model.get('titlePosition')).to.equal('aboveBlock');
expect(model.get('titleAlignment')).to.equal('right');
expect(model.get('titleIsLink')).to.equal(true);
expect(model.get('imagePadded')).to.equal(false);
expect(model.get('showAuthor')).to.equal('belowText');
expect(model.get('authorPrecededBy')).to.equal('Custom config author preceded by');
expect(model.get('showCategories')).to.equal('belowText');
expect(model.get('categoriesPrecededBy')).to.equal('Custom config categories preceded by');
expect(model.get('readMoreType')).to.equal('button');
expect(model.get('readMoreText')).to.equal('Custom Config read more text');
expect(model.get('readMoreButton.text')).to.equal('Custom config read more');
expect(model.get('readMoreButton.url')).to.equal('[postLink]');
expect(model.get('readMoreButton.styles.block.backgroundColor')).to.equal('#123456');
expect(model.get('readMoreButton.styles.block.borderColor')).to.equal('#234567');
expect(model.get('readMoreButton.styles.link.fontColor')).to.equal('#345678');
expect(model.get('readMoreButton.styles.link.fontFamily')).to.equal('Tahoma');
expect(model.get('readMoreButton.styles.link.fontSize')).to.equal('37px');
expect(model.get('sortBy')).to.equal('oldest');
expect(model.get('showDivider')).to.equal(true);
expect(model.get('divider.src')).to.equal('http://example.org/someConfigDividerImage.png');
expect(model.get('divider.styles.block.backgroundColor')).to.equal('#456789');
expect(model.get('divider.styles.block.padding')).to.equal('38px');
});
});
beforeEach(function () { describe('block view', function () {
global.stubChannel(); var model, view;
global.stubConfig();
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
view = new (EditorApplication.module('blocks.posts').PostsBlockView)({model: model});
// Disable auto-opening of settings view beforeEach(function () {
view.off('showSettings'); global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication);
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
view = new (EditorApplication.module('blocks.posts').PostsBlockView)({model: model});
afterEach(function () { // Disable auto-opening of settings view
delete EditorApplication.getChannel; view.off('showSettings');
}); });
it('renders', function () { afterEach(function () {
expect(view.render).to.not.throw(); delete EditorApplication.getChannel;
expect(view.$('.mailpoet_content')).to.have.length(1); });
});
});
describe('block settings view', function () { it('renders', function () {
var model, view; expect(view.render).to.not.throw();
expect(view.$('.mailpoet_content')).to.have.length(1);
});
});
before(function () { describe('block settings view', function () {
global.stubChannel(); var model, view;
global.stubConfig({
blockDefaults: {},
});
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
});
it('renders', function () { before(function () {
// Stub out block view requests global.stubChannel(EditorApplication);
model.request = sinon.stub().returns({$el: {}}); global.stubConfig(EditorApplication, {
blockDefaults: {},
});
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
});
expect(view.render).to.not.throw(); it('renders', function () {
}); // Stub out block view requests
model.request = sinon.stub().returns({$el: {}});
describe('once rendered', function () { expect(view.render).to.not.throw();
it('changes the model if post type changes', function () { });
var newValue = 'mailpoet_page';
view.$('.mailpoet_settings_posts_content_type').val(newValue).change();
expect(model.get('contentType')).to.equal(newValue);
});
it('changes the model if post status changes', function () { describe('once rendered', function () {
var newValue = 'pending'; it('changes the model if post type changes', function () {
view.$('.mailpoet_posts_post_status').val(newValue).change(); var newValue = 'mailpoet_page';
expect(model.get('postStatus')).to.equal(newValue); view.$('.mailpoet_settings_posts_content_type').val(newValue).change();
}); expect(model.get('contentType')).to.equal(newValue);
});
it('changes the model if search term changes', function () { it('changes the model if post status changes', function () {
var newValue = 'some New search term'; var newValue = 'pending';
view.$('.mailpoet_posts_search_term').val(newValue).keyup(); view.$('.mailpoet_posts_post_status').val(newValue).change();
expect(model.get('search')).to.equal(newValue); expect(model.get('postStatus')).to.equal(newValue);
}); });
it('changes the model if display type changes', function () { it('changes the model if search term changes', function () {
var newValue = 'full'; var newValue = 'some New search term';
view.$('.mailpoet_posts_display_type').val(newValue).change(); view.$('.mailpoet_posts_search_term').val(newValue).keyup();
expect(model.get('displayType')).to.equal(newValue); expect(model.get('search')).to.equal(newValue);
}); });
it('changes the model if title format changes', function () { it('changes the model if display type changes', function () {
var newValue = 'h3'; var newValue = 'full';
view.$('.mailpoet_posts_title_format').val(newValue).change(); view.$('.mailpoet_posts_display_type').val(newValue).change();
expect(model.get('titleFormat')).to.equal(newValue); expect(model.get('displayType')).to.equal(newValue);
}); });
it('changes the model if title position changes', function () { it('changes the model if title format changes', function () {
var newValue = 'aboveBlock'; var newValue = 'h3';
view.$('.mailpoet_posts_title_position').val(newValue).change(); view.$('.mailpoet_posts_title_format').val(newValue).change();
expect(model.get('titlePosition')).to.equal(newValue); expect(model.get('titleFormat')).to.equal(newValue);
}); });
it('changes the model if title alignment changes', function () { it('changes the model if title position changes', function () {
var newValue = 'right'; var newValue = 'aboveBlock';
view.$('.mailpoet_posts_title_alignment').val(newValue).change(); view.$('.mailpoet_posts_title_position').val(newValue).change();
expect(model.get('titleAlignment')).to.equal(newValue); expect(model.get('titlePosition')).to.equal(newValue);
}); });
it('changes the model if title link changes', function () { it('changes the model if title alignment changes', function () {
var newValue = true; var newValue = 'right';
view.$('.mailpoet_posts_title_as_links').val(newValue).change(); view.$('.mailpoet_posts_title_alignment').val(newValue).change();
expect(model.get('titleIsLink')).to.equal(newValue); expect(model.get('titleAlignment')).to.equal(newValue);
}); });
it('changes the model if image alignment changes', function () { it('changes the model if title link changes', function () {
var newValue = false; var newValue = true;
view.$('.mailpoet_posts_image_padded').val(newValue).change(); view.$('.mailpoet_posts_title_as_links').val(newValue).change();
expect(model.get('imagePadded')).to.equal(newValue); expect(model.get('titleIsLink')).to.equal(newValue);
}); });
it('changes the model if show author changes', function () { it('changes the model if image alignment changes', function () {
var newValue = 'belowText'; var newValue = false;
view.$('.mailpoet_posts_show_author').val(newValue).change(); view.$('.mailpoet_posts_image_padded').val(newValue).change();
expect(model.get('showAuthor')).to.equal(newValue); expect(model.get('imagePadded')).to.equal(newValue);
}); });
it('changes the model if author preceded by changes', function () { it('changes the model if show author changes', function () {
var newValue = 'New author preceded by test'; var newValue = 'belowText';
view.$('.mailpoet_posts_author_preceded_by').val(newValue).keyup(); view.$('.mailpoet_posts_show_author').val(newValue).change();
expect(model.get('authorPrecededBy')).to.equal(newValue); expect(model.get('showAuthor')).to.equal(newValue);
}); });
it('changes the model if show categories changes', function () { it('changes the model if author preceded by changes', function () {
var newValue = 'belowText'; var newValue = 'New author preceded by test';
view.$('.mailpoet_posts_show_categories').val(newValue).change(); view.$('.mailpoet_posts_author_preceded_by').val(newValue).keyup();
expect(model.get('showCategories')).to.equal(newValue); expect(model.get('authorPrecededBy')).to.equal(newValue);
}); });
it('changes the model if categories preceded by changes', function () { it('changes the model if show categories changes', function () {
var newValue = 'New categories preceded by test'; var newValue = 'belowText';
view.$('.mailpoet_posts_categories').val(newValue).keyup(); view.$('.mailpoet_posts_show_categories').val(newValue).change();
expect(model.get('categoriesPrecededBy')).to.equal(newValue); expect(model.get('showCategories')).to.equal(newValue);
}); });
it('changes the model if read more button type changes', function () { it('changes the model if categories preceded by changes', function () {
var newValue = 'link'; var newValue = 'New categories preceded by test';
view.$('.mailpoet_posts_read_more_type').val(newValue).change(); view.$('.mailpoet_posts_categories').val(newValue).keyup();
expect(model.get('readMoreType')).to.equal(newValue); expect(model.get('categoriesPrecededBy')).to.equal(newValue);
}); });
it('changes the model if read more text changes', function () { it('changes the model if read more button type changes', function () {
var newValue = 'New read more text'; var newValue = 'link';
view.$('.mailpoet_posts_read_more_text').val(newValue).keyup(); view.$('.mailpoet_posts_read_more_type').val(newValue).change();
expect(model.get('readMoreText')).to.equal(newValue); expect(model.get('readMoreType')).to.equal(newValue);
}); });
describe('when "title only" display type is selected', function() { it('changes the model if read more text changes', function () {
var model, view; var newValue = 'New read more text';
beforeEach(function() { view.$('.mailpoet_posts_read_more_text').val(newValue).keyup();
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)(); expect(model.get('readMoreText')).to.equal(newValue);
model.request = sinon.stub().returns({$el: {}}); });
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_posts_display_type').val('titleOnly').change();
});
it('shows "title as list" option', function () { describe('when "title only" display type is selected', function() {
expect(view.$('.mailpoet_posts_title_as_list')).to.not.have.$class('mailpoet_hidden'); var model, view;
}); beforeEach(function() {
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
model.request = sinon.stub().returns({$el: {}});
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_posts_display_type').val('titleOnly').change();
});
describe('when "title as list" is selected', function() { it('shows "title as list" option', function () {
var model, view; expect(view.$('.mailpoet_posts_title_as_list')).to.not.have.$class('mailpoet_hidden');
beforeEach(function() { });
model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
model.request = sinon.stub().returns({$el: {}});
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_posts_display_type').val('titleOnly').change();
view.$('.mailpoet_posts_title_format').val('ul').change();
});
describe('"title is link" option', function () { describe('when "title as list" is selected', function() {
it('is hidden', function () { var model, view;
expect(view.$('.mailpoet_posts_title_as_link')).to.have.$class('mailpoet_hidden'); beforeEach(function() {
}); model = new (EditorApplication.module('blocks.posts').PostsBlockModel)();
model.request = sinon.stub().returns({$el: {}});
view = new (EditorApplication.module('blocks.posts').PostsBlockSettingsView)({model: model});
view.render();
view.$('.mailpoet_posts_display_type').val('titleOnly').change();
view.$('.mailpoet_posts_title_format').val('ul').change();
});
it('is set to "yes"', function() { describe('"title is link" option', function () {
expect(model.get('titleIsLink')).to.equal(true); it('is hidden', function () {
}); expect(view.$('.mailpoet_posts_title_as_link')).to.have.$class('mailpoet_hidden');
}); });
});
describe('when "title as list" is deselected', function() { it('is set to "yes"', function() {
before(function() { expect(model.get('titleIsLink')).to.equal(true);
view.$('.mailpoet_posts_title_format').val('ul').change(); });
view.$('.mailpoet_posts_title_format').val('h3').change(); });
}); });
describe('"title is link" option', function () { describe('when "title as list" is deselected', function() {
it('is visible', function () { before(function() {
expect(view.$('.mailpoet_posts_title_as_link')).to.not.have.$class('mailpoet_hidden'); view.$('.mailpoet_posts_title_format').val('ul').change();
}); view.$('.mailpoet_posts_title_format').val('h3').change();
}); });
});
}); describe('"title is link" option', function () {
it('is visible', function () {
expect(view.$('.mailpoet_posts_title_as_link')).to.not.have.$class('mailpoet_hidden');
});
});
});
});
it('changes the model if show divider changes', function () {
var newValue = true;
view.$('.mailpoet_posts_show_divider').val(newValue).change();
expect(model.get('showDivider')).to.equal(newValue);
});
});
});
});
it('changes the model if show divider changes', function () {
var newValue = true;
view.$('.mailpoet_posts_show_divider').val(newValue).change();
expect(model.get('showDivider')).to.equal(newValue);
});
});
});
}); });

View File

@ -1,273 +1,280 @@
describe('Social', function () { define('test/newsletter_editor/blocks/social', [
describe('block model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/social'
beforeEach(function () { ], function(EditorApplication) {
global.stubChannel();
global.stubConfig();
model = new (EditorApplication.module('blocks.social').SocialBlockModel)();
});
it('has a social type', function () { describe('Social', function () {
expect(model.get('type')).to.equal('social'); describe('block model', function () {
}); var model;
beforeEach(function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
model = new (EditorApplication.module('blocks.social').SocialBlockModel)();
});
it('has an icon set it uses', function () { it('has a social type', function () {
expect(model.get('iconSet')).to.be.a('string'); expect(model.get('type')).to.equal('social');
}); });
it('has icons', function () { it('has an icon set it uses', function () {
expect(model.get('icons')).to.be.an.instanceof(Backbone.Collection); expect(model.get('iconSet')).to.be.a('string');
}); });
it("uses defaults from config when they are set", function () { it('has icons', function () {
global.stubConfig({ expect(model.get('icons')).to.be.an.instanceof(Backbone.Collection);
blockDefaults: { });
social: {
iconSet: 'customConfigIconSet',
},
},
});
var model = new (EditorApplication.module('blocks.social').SocialBlockModel)();
expect(model.get('iconSet')).to.equal('customConfigIconSet'); it("uses defaults from config when they are set", function () {
}); global.stubConfig(EditorApplication, {
}); blockDefaults: {
social: {
iconSet: 'customConfigIconSet',
},
},
});
var model = new (EditorApplication.module('blocks.social').SocialBlockModel)();
describe('icon model', function () { expect(model.get('iconSet')).to.equal('customConfigIconSet');
var model; });
before(function () { });
global.stubChannel();
global.stubAvailableStyles({
'socialIconSets.default.custom': 'someimage.jpg',
});
global.stubConfig({
socialIcons: {
custom: {
defaultLink: 'http://example.org',
title: 'sometitle',
}
},
});
model = new (EditorApplication.module('blocks.social').SocialIconModel)();
});
it('has a socialIcon type', function () { describe('icon model', function () {
expect(model.get('type')).to.equal('socialIcon'); var model;
}); before(function () {
global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
'socialIconSets.default.custom': 'someimage.jpg',
});
global.stubConfig(EditorApplication, {
socialIcons: {
custom: {
defaultLink: 'http://example.org',
title: 'sometitle',
}
},
});
model = new (EditorApplication.module('blocks.social').SocialIconModel)();
});
it('has a link', function () { it('has a socialIcon type', function () {
expect(model.get('link')).to.be.a('string'); expect(model.get('type')).to.equal('socialIcon');
expect(model.get('link')).to.equal('http://example.org'); });
});
it('has an image', function () { it('has a link', function () {
expect(model.get('image')).to.equal('someimage.jpg'); expect(model.get('link')).to.be.a('string');
}); expect(model.get('link')).to.equal('http://example.org');
});
it('has height', function () { it('has an image', function () {
expect(model.get('height')).to.equal('32px'); expect(model.get('image')).to.equal('someimage.jpg');
}); });
it('has width', function () { it('has height', function () {
expect(model.get('width')).to.equal('32px'); expect(model.get('height')).to.equal('32px');
}); });
it('has text', function () { it('has width', function () {
expect(model.get('text')).to.equal('sometitle'); expect(model.get('width')).to.equal('32px');
}); });
});
describe('block view', function () { it('has text', function () {
var model; expect(model.get('text')).to.equal('sometitle');
});
});
beforeEach(function () { describe('block view', function () {
global.stubChannel(); var model;
global.stubAvailableStyles({
socialIconSets: {
'default': {
'custom': 'http://www.sott.net/images/icons/big_x.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
text: 'some text',
}
],
});
});
it('renders', function () { beforeEach(function () {
var view = new (EditorApplication.module('blocks.social').SocialBlockView)({model: model}); global.stubChannel(EditorApplication);
expect(view.render).to.not.throw(); global.stubAvailableStyles(EditorApplication, {
expect(view.$('.mailpoet_social')).to.have.length(1); socialIconSets: {
}); 'default': {
'custom': 'http://www.sott.net/images/icons/big_x.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
text: 'some text',
}
],
});
});
describe('once rendered', function () { it('renders', function () {
var model, view; var view = new (EditorApplication.module('blocks.social').SocialBlockView)({model: model});
expect(view.render).to.not.throw();
expect(view.$('.mailpoet_social')).to.have.length(1);
});
before(function () { describe('once rendered', function () {
global.stubChannel(); var model, view;
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'http://example.org/',
image: 'http://example.org/someimage.png',
text: 'some text',
},
{
type: 'socialIcon',
iconType: 'facebook',
link: 'http://facebook.com/',
image: 'http://facebook.com/icon.png',
text: 'Facebook icon',
},
],
});
view = new (EditorApplication.module('blocks.social').SocialBlockView)({model: model});
view.render();
});
it('shows multiple social icons', function () { before(function () {
expect(view.$('.mailpoet_social a').eq(0).prop('href')).to.equal('http://example.org/'); global.stubChannel(EditorApplication);
expect(view.$('.mailpoet_social img').eq(0).prop('src')).to.equal('http://example.org/someimage.png'); model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
expect(view.$('.mailpoet_social img').eq(0).prop('alt')).to.equal('some text'); type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'http://example.org/',
image: 'http://example.org/someimage.png',
text: 'some text',
},
{
type: 'socialIcon',
iconType: 'facebook',
link: 'http://facebook.com/',
image: 'http://facebook.com/icon.png',
text: 'Facebook icon',
},
],
});
view = new (EditorApplication.module('blocks.social').SocialBlockView)({model: model});
view.render();
});
expect(view.$('.mailpoet_social a').eq(1).prop('href')).to.equal('http://facebook.com/'); it('shows multiple social icons', function () {
expect(view.$('.mailpoet_social img').eq(1).prop('src')).to.equal('http://facebook.com/icon.png'); expect(view.$('.mailpoet_social a').eq(0).prop('href')).to.equal('http://example.org/');
expect(view.$('.mailpoet_social img').eq(1).prop('alt')).to.equal('Facebook icon'); expect(view.$('.mailpoet_social img').eq(0).prop('src')).to.equal('http://example.org/someimage.png');
}); expect(view.$('.mailpoet_social img').eq(0).prop('alt')).to.equal('some text');
});
});
describe('block settings view', function () { expect(view.$('.mailpoet_social a').eq(1).prop('href')).to.equal('http://facebook.com/');
var model; expect(view.$('.mailpoet_social img').eq(1).prop('src')).to.equal('http://facebook.com/icon.png');
expect(view.$('.mailpoet_social img').eq(1).prop('alt')).to.equal('Facebook icon');
});
});
});
beforeEach(function () { describe('block settings view', function () {
global.stubChannel(); var model;
global.stubAvailableStyles({
socialIconSets: {
'default': {
'custom': 'someimage.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
height: '32px',
width: '32px',
text: 'some text',
}
],
});
});
it('renders', function () { beforeEach(function () {
var view = new (EditorApplication.module('blocks.social').SocialBlockSettingsView)({model: model}); global.stubChannel(EditorApplication);
expect(view.render).to.not.throw(); global.stubAvailableStyles(EditorApplication, {
}); socialIconSets: {
'default': {
'custom': 'someimage.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
height: '32px',
width: '32px',
text: 'some text',
}
],
});
});
describe('once rendered', function () { it('renders', function () {
var model, view; var view = new (EditorApplication.module('blocks.social').SocialBlockSettingsView)({model: model});
beforeEach(function () { expect(view.render).to.not.throw();
global.stubChannel(); });
global.stubAvailableStyles({
socialIconSets: {
'default': {
'custom': 'http://www.sott.net/images/icons/big_x.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
height: '32px',
width: '32px',
text: 'some text',
}
],
});
view = new (EditorApplication.module('blocks.social').SocialBlockSettingsView)({model: model});
view.render();
});
it('updates icons in settings if iconset changes', function() { describe('once rendered', function () {
view.$('.mailpoet_social_icon_set').last().click(); var model, view;
expect(view.$('.mailpoet_social_icon_field_image').val()).to.equal(EditorApplication.getAvailableStyles().get('socialIconSets.light.custom')); beforeEach(function () {
}); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, {
socialIconSets: {
'default': {
'custom': 'http://www.sott.net/images/icons/big_x.png',
},
'light': {
'custom': 'http://content.indiainfoline.com/wc/news/ImageGallery/css/close_32x32.png',
},
},
socialIcons: {
'custom': {
title: 'Custom',
linkFieldName: 'Page URL',
defaultLink: 'http://example.org',
},
},
});
model = new (EditorApplication.module('blocks.social').SocialBlockModel)({
type: 'social',
iconSet: 'default',
icons: [
{
type: 'socialIcon',
iconType: 'custom',
link: 'somelink.htm',
image: 'someimage.png',
height: '32px',
width: '32px',
text: 'some text',
}
],
});
view = new (EditorApplication.module('blocks.social').SocialBlockSettingsView)({model: model});
view.render();
});
it('removes the icon when "remove" is clicked', function() { it('updates icons in settings if iconset changes', function() {
view.$('.mailpoet_delete_block').click(); view.$('.mailpoet_social_icon_set').last().click();
expect(model.get('icons').length).to.equal(0); expect(view.$('.mailpoet_social_icon_field_image').val()).to.equal(EditorApplication.getAvailableStyles().get('socialIconSets.light.custom'));
expect(view.$('.mailpoet_social_icon_settings').length).to.equal(0); });
});
it('adds another icon when "Add another social network" is pressed', function() { it('removes the icon when "remove" is clicked', function() {
view.$('.mailpoet_add_social_icon').click(); view.$('.mailpoet_delete_block').click();
expect(model.get('icons').length).to.equal(2); expect(model.get('icons').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() {
view.$('.mailpoet_add_social_icon').click();
expect(model.get('icons').length).to.equal(2);
});
it.skip('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,133 +1,143 @@
describe('Spacer', function () { define('test/newsletter_editor/blocks/spacer', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/spacer'
], function(EditorApplication) {
beforeEach(function () { describe('Spacer', function () {
global.stubChannel(); describe('model', function () {
global.stubConfig({ var model;
blockDefaults: {},
});
global.stubAvailableStyles();
model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)();
});
afterEach(function () { beforeEach(function () {
delete EditorApplication.getChannel; global.stubChannel(EditorApplication);
}); global.stubConfig(EditorApplication, {
blockDefaults: {},
});
global.stubAvailableStyles(EditorApplication);
model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)();
});
it('has spacer type', function () { afterEach(function () {
expect(model.get('type')).to.equal('spacer'); delete EditorApplication.getChannel;
}); });
it('has height', function () { it('has spacer type', function () {
expect(model.get('styles.block.height')).to.match(/\d+px/); expect(model.get('type')).to.equal('spacer');
}); });
it('has a background color', function () { it('has height', function () {
expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/); expect(model.get('styles.block.height')).to.match(/\d+px/);
}); });
it("changes attributes with set", function () { it('has a background color', function () {
var newValue = '33px'; expect(model.get('styles.block.backgroundColor')).to.match(/^(#[abcdef0-9]{6})|transparent$/);
model.set('styles.block.height', newValue); });
expect(model.get('styles.block.height')).to.equal(newValue);
});
it("triggers autosave if any attribute changes", function () { it("changes attributes with set", function () {
var mock = sinon.mock().exactly(2).withArgs('autoSave'); var newValue = '33px';
EditorApplication.getChannel = sinon.stub().returns({ model.set('styles.block.height', newValue);
trigger: mock, expect(model.get('styles.block.height')).to.equal(newValue);
}); });
model.set('styles.block.backgroundColor', '#000000'); it("triggers autosave if any attribute changes", function () {
model.set('styles.block.height', '77px'); var mock = sinon.mock().exactly(2).withArgs('autoSave');
EditorApplication.getChannel = sinon.stub().returns({
trigger: mock,
});
mock.verify(); model.set('styles.block.backgroundColor', '#000000');
}); model.set('styles.block.height', '77px');
it("uses defaults from config when they are set", function () { mock.verify();
global.stubConfig({ });
blockDefaults: {
spacer: {
styles: {
block: {
backgroundColor: '#567890',
height: '19px',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)();
expect(model.get('styles.block.backgroundColor')).to.equal('#567890'); it("uses defaults from config when they are set", function () {
expect(model.get('styles.block.height')).to.equal('19px'); global.stubConfig(EditorApplication, {
}); blockDefaults: {
}); spacer: {
styles: {
block: {
backgroundColor: '#567890',
height: '19px',
},
},
},
},
});
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)();
describe('block view', function () { expect(model.get('styles.block.backgroundColor')).to.equal('#567890');
global.stubChannel(); expect(model.get('styles.block.height')).to.equal('19px');
global.stubConfig(); });
global.stubAvailableStyles(); });
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)(),
view;
beforeEach(function () { describe('block view', function () {
global.stubChannel(); global.stubChannel(EditorApplication);
view = new (EditorApplication.module('blocks.spacer').SpacerBlockView)({model: model}); global.stubConfig(EditorApplication);
}); global.stubAvailableStyles(EditorApplication);
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)(),
view;
it('renders', function () { beforeEach(function () {
expect(view.render).to.not.throw(); global.stubChannel(EditorApplication);
expect(view.$('.mailpoet_spacer')).to.have.length(1); view = new (EditorApplication.module('blocks.spacer').SpacerBlockView)({model: model});
expect(view.$('.mailpoet_spacer').css('background-color')).to.equal(model.get('styles.block.backgroundColor')); });
expect(view.$('.mailpoet_spacer').css('height')).to.equal(model.get('styles.block.height'));
});
it('rerenders if model attributes change', function () { it('renders', function () {
view.render(); expect(view.render).to.not.throw();
expect(view.$('.mailpoet_spacer')).to.have.length(1);
expect(view.$('.mailpoet_spacer').css('background-color')).to.equal(model.get('styles.block.backgroundColor'));
expect(view.$('.mailpoet_spacer').css('height')).to.equal(model.get('styles.block.height'));
});
model.set('styles.block.height', '71px'); it('rerenders if model attributes change', function () {
view.render();
expect(view.$('.mailpoet_spacer').css('height')).to.equal('71px'); model.set('styles.block.height', '71px');
});
});
describe('settings view', function () { expect(view.$('.mailpoet_spacer').css('height')).to.equal('71px');
global.stubChannel(); });
global.stubConfig(); });
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)(), describe('settings view', function () {
view; global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
beforeEach(function () { var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)(),
global.stubChannel(); view;
view = new (EditorApplication.module('blocks.spacer').SpacerBlockSettingsView)({model: model});
});
it('renders', function () { beforeEach(function () {
expect(view.render).to.not.throw(); global.stubChannel(EditorApplication);
}); view = new (EditorApplication.module('blocks.spacer').SpacerBlockSettingsView)({model: model});
});
describe('once rendered', function () { it('renders', function () {
global.stubChannel(); expect(view.render).to.not.throw();
global.stubConfig(); });
var model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)(),
describe('once rendered', function () {
var view, model;
beforeEach(function() {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
model = new (EditorApplication.module('blocks.spacer').SpacerBlockModel)();
view = new (EditorApplication.module('blocks.spacer').SpacerBlockSettingsView)({model: model}); view = new (EditorApplication.module('blocks.spacer').SpacerBlockSettingsView)({model: model});
view.render(); view.render();
});
it('updates the model when background color changes', function () { it('updates the model when background color changes', function () {
view.$('.mailpoet_field_spacer_background_color').val('#123456').change(); view.$('.mailpoet_field_spacer_background_color').val('#123456').change();
expect(model.get('styles.block.backgroundColor')).to.equal('#123456'); expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
}); });
it.skip('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
});
it('closes the sidepanel after "Done" is clicked', function () {
var mock = sinon.mock().once();
global.MailPoet.Modal.cancel = mock;
view.$('.mailpoet_done_editing').click();
mock.verify();
delete(global.MailPoet.Modal.cancel);
});
});
});
}); });

View File

@ -1,65 +1,72 @@
describe('Text', function () { define('test/newsletter_editor/blocks/text', [
describe('model', function () { 'newsletter_editor/App',
var model; 'newsletter_editor/blocks/text'
beforeEach(function () { ], function(EditorApplication) {
global.stubChannel();
global.stubConfig();
model = new (EditorApplication.module('blocks.text').TextBlockModel)();
});
it('has a text type', function () { describe('Text', function () {
expect(model.get('type')).to.equal('text'); describe('model', function () {
}); var model;
beforeEach(function () {
global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication);
model = new (EditorApplication.module('blocks.text').TextBlockModel)();
});
it('has text', function () { it('has a text type', function () {
expect(model.get('text')).to.be.a('string'); expect(model.get('type')).to.equal('text');
}); });
it("uses defaults from config when they are set", function () { it('has text', function () {
global.stubConfig({ expect(model.get('text')).to.be.a('string');
blockDefaults: { });
text: {
text: 'some custom config text',
},
},
});
var model = new (EditorApplication.module('blocks.text').TextBlockModel)();
expect(model.get('text')).to.equal('some custom config text'); it("uses defaults from config when they are set", function () {
}); global.stubConfig(EditorApplication, {
}); blockDefaults: {
text: {
text: 'some custom config text',
},
},
});
var model = new (EditorApplication.module('blocks.text').TextBlockModel)();
describe('block view', function () { expect(model.get('text')).to.equal('some custom config text');
global.stubConfig(); });
var model = new (EditorApplication.module('blocks.text').TextBlockModel)(), });
view = new (EditorApplication.module('blocks.text').TextBlockView)({model: model});
it('renders', function () { describe('block view', function () {
expect(view.render).to.not.throw(); global.stubConfig(EditorApplication);
expect(view.$('.mailpoet_content')).to.have.length(1); var model = new (EditorApplication.module('blocks.text').TextBlockModel)(),
}); view = new (EditorApplication.module('blocks.text').TextBlockView)({model: model});
describe('once rendered', function () { it('renders', function () {
var model = new (EditorApplication.module('blocks.text').TextBlockModel)(), expect(view.render).to.not.throw();
view; expect(view.$('.mailpoet_content')).to.have.length(1);
});
beforeEach(function () { describe('once rendered', function () {
global.stubConfig(); var model = new (EditorApplication.module('blocks.text').TextBlockModel)(),
view = new (EditorApplication.module('blocks.text').TextBlockView)({model: model}); view;
view.render();
});
it('has a deletion tool', function () { beforeEach(function () {
expect(view.$('.mailpoet_delete_block')).to.have.length(1); global.stubConfig(EditorApplication);
}); view = new (EditorApplication.module('blocks.text').TextBlockView)({model: model});
view.render();
});
it('has a move tool', function () { it('has a deletion tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(1); expect(view.$('.mailpoet_delete_block')).to.have.length(1);
}); });
it('has a move tool', function () {
expect(view.$('.mailpoet_move_block')).to.have.length(1);
});
it('does not have a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(0);
});
});
});
});
it('does not have a settings tool', function () {
expect(view.$('.mailpoet_edit_block')).to.have.length(0);
});
});
});
}); });

View File

@ -1,9 +1,15 @@
describe('Config', function () { define('test/newsletter_editor/components/config', [
it('loads and stores configuration', function() { 'newsletter_editor/App',
EditorApplication.module('components.config').setConfig({ 'newsletter_editor/components/config'
testConfig: 'testValue', ], function(EditorApplication) {
});
var model = EditorApplication.module('components.config').getConfig(); describe('Config', function () {
expect(model.get('testConfig')).to.equal('testValue'); it('loads and stores configuration', function() {
}); EditorApplication.module('components.config').setConfig({
testConfig: 'testValue',
});
var model = EditorApplication.module('components.config').getConfig();
expect(model.get('testConfig')).to.equal('testValue');
});
});
}); });

View File

@ -1,82 +1,88 @@
describe('Content', function() { define('test/newsletter_editor/components/content', [
describe('newsletter model', function() { 'newsletter_editor/App',
var model; 'newsletter_editor/components/content'
], function(EditorApplication) {
beforeEach(function() { describe('Content', function() {
model = new (EditorApplication.module('components.content').NewsletterModel)({ describe('newsletter model', function() {
styles: { var model;
style1: 'style1Value',
style2: 'style2Value',
},
data: {
data1: 'data1Value',
data2: 'data2Value',
},
someField: 'someValue'
});
});
it('triggers autosave on change', function() { beforeEach(function() {
var mock = sinon.mock({ trigger: function() {} }).expects('trigger').once().withArgs('autoSave'); model = new (EditorApplication.module('components.content').NewsletterModel)({
global.stubChannel({ styles: {
trigger: mock, style1: 'style1Value',
}); style2: 'style2Value',
model.set('someField', 'anotherValue'); },
mock.verify(); data: {
}); data1: 'data1Value',
data2: 'data2Value',
},
someField: 'someValue'
});
});
it('does not include styles and data attributes in its JSON', function() { it('triggers autosave on change', function() {
var json = model.toJSON(); var mock = sinon.mock({ trigger: function() {} }).expects('trigger').once().withArgs('autoSave');
expect(json).to.deep.equal({someField: 'someValue'}); global.stubChannel(EditorApplication, {
}); trigger: mock,
}); });
model.set('someField', 'anotherValue');
mock.verify();
});
describe('block types', function() { it('does not include styles and data attributes in its JSON', function() {
it('registers a block type view and model', function() { var json = model.toJSON();
var blockModel = new Backbone.SuperModel(), expect(json).to.deep.equal({someField: 'someValue'});
blockView = new Backbone.View(); });
EditorApplication.module('components.content').registerBlockType('testType', { });
blockModel: blockModel,
blockView: blockView,
});
expect(EditorApplication.module('components.content').getBlockTypeModel('testType')).to.deep.equal(blockModel);
expect(EditorApplication.module('components.content').getBlockTypeView('testType')).to.deep.equal(blockView);
});
});
describe('transformation to json', function() { describe('block types', function() {
it('includes data, styles and initial newsletter fields', function() { it('registers a block type view and model', function() {
var dataField = { var blockModel = new Backbone.SuperModel(),
containerModelField: 'containerModelValue', blockView = new Backbone.View();
}, stylesField = { EditorApplication.module('components.content').registerBlockType('testType', {
globalStylesField: 'globalStylesValue', blockModel: blockModel,
}, newsletterFields = { blockView: blockView,
newsletter_subject: 'test newsletter subject', });
}; expect(EditorApplication.module('components.content').getBlockTypeModel('testType')).to.deep.equal(blockModel);
EditorApplication._contentContainer = { expect(EditorApplication.module('components.content').getBlockTypeView('testType')).to.deep.equal(blockView);
toJSON: function() { });
return dataField; });
}
}; describe('transformation to json', function() {
EditorApplication.getGlobalStyles = function() { it('includes data, styles and initial newsletter fields', function() {
return { var dataField = {
toJSON: function() { containerModelField: 'containerModelValue',
return stylesField; }, stylesField = {
}, globalStylesField: 'globalStylesValue',
}; }, newsletterFields = {
}; newsletter_subject: 'test newsletter subject',
EditorApplication.getNewsletter = function() { };
return { EditorApplication._contentContainer = {
toJSON: function() { toJSON: function() {
return newsletterFields; return dataField;
}, }
}; };
}; EditorApplication.getGlobalStyles = function() {
var json = EditorApplication.module('components.content').toJSON(); return {
expect(json).to.deep.equal(_.extend({ toJSON: function() {
data: dataField, return stylesField;
styles: stylesField },
}, newsletterFields)); };
}); };
}); EditorApplication.getNewsletter = function() {
return {
toJSON: function() {
return newsletterFields;
},
};
};
var json = EditorApplication.module('components.content').toJSON();
expect(json).to.deep.equal(_.extend({
data: dataField,
styles: stylesField
}, newsletterFields));
});
});
});
}); });

View File

@ -1,41 +1,48 @@
describe('Heading', function() { define('test/newsletter_editor/components/heading', [
describe('view', function() { 'newsletter_editor/App',
var view; 'newsletter_editor/components/heading'
beforeEach(function() { ], function(EditorApplication) {
var model = new Backbone.SuperModel({
newsletter_subject: 'a test subject',
});
view = new (EditorApplication.module("components.heading").HeadingView)({
model: model,
});
});
it('renders', function() { describe('Heading', function() {
expect(view.render).to.not.throw(); describe('view', function() {
}); var view;
beforeEach(function() {
var model = new Backbone.SuperModel({
newsletter_subject: 'a test subject',
});
view = new (EditorApplication.module("components.heading").HeadingView)({
model: model,
});
});
describe('once rendered', function() { it('renders', function() {
var view, model; expect(view.render).to.not.throw();
beforeEach(function() { });
model = new Backbone.SuperModel({
newsletter_subject: 'a test subject',
newsletter_preheader: 'a test preheader',
});
view = new (EditorApplication.module("components.heading").HeadingView)({
model: model,
});
view.render();
});
it('changes the model when subject field is changed', function() { describe('once rendered', function() {
view.$('.mailpoet_input_title').val('a new testing subject').keyup(); var view, model;
expect(model.get('newsletter_subject')).to.equal('a new testing subject'); beforeEach(function() {
}); model = new Backbone.SuperModel({
newsletter_subject: 'a test subject',
newsletter_preheader: 'a test preheader',
});
view = new (EditorApplication.module("components.heading").HeadingView)({
model: model,
});
view.render();
});
it('changes the model when subject field is changed', function() {
view.$('.mailpoet_input_title').val('a new testing subject').keyup();
expect(model.get('newsletter_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').keyup();
expect(model.get('newsletter_preheader')).to.equal('a new testing preheader');
});
});
});
});
it('changes the model when preheader field is changed', function() {
view.$('.mailpoet_input_preheader').val('a new testing preheader').keyup();
expect(model.get('newsletter_preheader')).to.equal('a new testing preheader');
});
});
});
}); });

View File

@ -1,74 +1,81 @@
describe('Save', function() { define('test/newsletter_editor/components/save', [
describe('save method', function() { 'newsletter_editor/App',
it('triggers beforeEditorSave event', function() { 'newsletter_editor/components/save'
var spy = sinon.spy(); ], function(EditorApplication) {
global.stubChannel({
trigger: spy,
});
global.mailpoet_post_wpi = sinon.stub();
EditorApplication.toJSON = sinon.stub();
EditorApplication.module("components.save").save();
expect(spy.withArgs('beforeEditorSave').calledOnce).to.be.true;
});
it('triggers afterEditorSave event', function() { describe('Save', function() {
var stub = sinon.stub().callsArgWith(2, { success: true }), describe('save method', function() {
spy = sinon.spy(); it('triggers beforeEditorSave event', function() {
global.mailpoet_post_wpi = stub; var spy = sinon.spy();
global.stubChannel({ global.stubChannel(EditorApplication, {
trigger: spy, trigger: spy,
}); });
EditorApplication.toJSON = sinon.stub(); global.mailpoet_post_wpi = sinon.stub();
EditorApplication.module("components.save").save(); EditorApplication.toJSON = sinon.stub();
expect(spy.withArgs('afterEditorSave').calledOnce).to.be.true; EditorApplication.module("components.save").save();
}); expect(spy.withArgs('beforeEditorSave').calledOnce).to.be.true;
});
it('sends newsletter json to server for saving', function() { it.skip('triggers afterEditorSave event', function() {
var mock = sinon.mock({ mailpoet_post_wpi: function() {} }).expects('mailpoet_post_wpi').once(); var stub = sinon.stub().callsArgWith(2, { success: true }),
global.stubChannel(); spy = sinon.spy();
global.mailpoet_post_wpi = mock; global.mailpoet_post_wpi = stub;
global.stubChannel(EditorApplication, {
trigger: spy,
});
EditorApplication.toJSON = sinon.stub();
EditorApplication.module("components.save").save();
expect(spy.withArgs('afterEditorSave').calledOnce).to.be.true;
});
EditorApplication.toJSON = sinon.stub().returns({}); it.skip('sends newsletter json to server for saving', function() {
EditorApplication.module("components.save").save(); var mock = sinon.mock({ mailpoet_post_wpi: function() {} }).expects('mailpoet_post_wpi').once();
global.stubChannel(EditorApplication);
global.mailpoet_post_wpi = mock;
mock.verify(); EditorApplication.toJSON = sinon.stub().returns({});
}); EditorApplication.module("components.save").save();
});
describe('view', function() { mock.verify();
var view; });
before(function() { });
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
global.stubConfig();
view = new (EditorApplication.module('components.save').SaveView)();
});
it('renders', function() { describe('view', function() {
expect(view.render).to.not.throw(); var view;
}); before(function() {
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
global.stubConfig(EditorApplication);
view = new (EditorApplication.module('components.save').SaveView)();
});
describe('once rendered', function() { it('renders', function() {
var view; expect(view.render).to.not.throw();
beforeEach(function() { });
EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
view = new (EditorApplication.module('components.save').SaveView)();
view.render();
});
it('triggers newsletter saving when clicked on save button', function() { describe('once rendered', function() {
var mock = sinon.mock({ trigger: function() {} }).expects('trigger').once().withArgs('save'); var view;
global.stubChannel({ beforeEach(function() {
trigger: mock, EditorApplication._contentContainer = { isValid: sinon.stub().returns(true) };
}); view = new (EditorApplication.module('components.save').SaveView)();
view.$('.mailpoet_save_button').click(); view.render();
});
mock.verify(); it('triggers newsletter saving when clicked on save button', function() {
}); var mock = sinon.mock({ trigger: function() {} }).expects('trigger').once().withArgs('save');
global.stubChannel(EditorApplication, {
trigger: mock,
});
view.$('.mailpoet_save_button').click();
mock.verify();
});
it('displays saving options when clicked on save options button', function() {
view.$('.mailpoet_save_show_options').click();
expect(view.$('.mailpoet_save_options')).to.not.have.$class('mailpoet_hidden');
});
});
});
});
it('displays saving options when clicked on save options button', function() {
view.$('.mailpoet_save_show_options').click();
expect(view.$('.mailpoet_save_options')).to.not.have.$class('mailpoet_hidden');
});
});
});
}); });

View File

@ -1,182 +1,189 @@
describe('Sidebar', function() { define('test/newsletter_editor/components/sidebar', [
'newsletter_editor/App',
'newsletter_editor/components/sidebar'
], function(EditorApplication) {
describe('content view', function() { describe('Sidebar', function() {
var view;
beforeEach(function() {
view = new (EditorApplication.module('components.sidebar').SidebarWidgetsView)({
collection: new Backbone.Collection([]),
});
});
it('renders', function() { describe('content view', function() {
expect(view.render).to.not.throw(); var view;
}); beforeEach(function() {
}); view = new (EditorApplication.module('components.sidebar').SidebarWidgetsView)({
collection: new Backbone.Collection([]),
});
});
describe('layout view', function() { it('renders', function() {
var view; expect(view.render).to.not.throw();
beforeEach(function() { });
view = new (EditorApplication.module('components.sidebar').SidebarLayoutWidgetsView)({ });
collection: new Backbone.Collection([]),
});
});
it('renders', function() { describe('layout view', function() {
expect(view.render).to.not.throw(); var view;
}); beforeEach(function() {
}); view = new (EditorApplication.module('components.sidebar').SidebarLayoutWidgetsView)({
collection: new Backbone.Collection([]),
});
});
describe('styles view', function() { it('renders', function() {
var view; expect(view.render).to.not.throw();
beforeEach(function() { });
view = new (EditorApplication.module('components.sidebar').SidebarStylesView)({ });
model: new Backbone.SuperModel({}),
availableStyles: new Backbone.SuperModel({}),
});
});
it('renders', function() { describe('styles view', function() {
expect(view.render).to.not.throw(); var view;
}); beforeEach(function() {
view = new (EditorApplication.module('components.sidebar').SidebarStylesView)({
model: new Backbone.SuperModel({}),
availableStyles: new Backbone.SuperModel({}),
});
});
describe('once rendered', function() { it('renders', function() {
var model, availableStyles, view; expect(view.render).to.not.throw();
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',
},
newsletter: {
backgroundColor: '#090909',
},
background: {
backgroundColor: '#020202',
},
});
availableStyles = new Backbone.SuperModel({
fonts: ['Arial', 'Times New Roman', 'Tahoma', 'Comic Sans', 'Lucida'],
textSizes: [
'9px', '10px',
],
headingSizes: [
'10px', '12px', '14px', '16px', '18px',
],
});
view = new (EditorApplication.module('components.sidebar').SidebarStylesView)({
model: model,
availableStyles: availableStyles,
});
view.render(); describe('once rendered', function() {
}); var model, availableStyles, view;
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',
},
newsletter: {
backgroundColor: '#090909',
},
background: {
backgroundColor: '#020202',
},
});
availableStyles = new Backbone.SuperModel({
fonts: ['Arial', 'Times New Roman', 'Tahoma', 'Comic Sans', 'Lucida'],
textSizes: [
'9px', '10px',
],
headingSizes: [
'10px', '12px', '14px', '16px', '18px',
],
});
view = new (EditorApplication.module('components.sidebar').SidebarStylesView)({
model: model,
availableStyles: availableStyles,
});
it('changes model if text font color field changes', function() { view.render();
view.$('#mailpoet_text_font_color').val('#123456').change(); });
expect(model.get('text.fontColor')).to.equal('#123456');
});
it('changes model if h1 font color field changes', function() { it('changes model if text font color field changes', function() {
view.$('#mailpoet_h1_font_color').val('#123457').change(); view.$('#mailpoet_text_font_color').val('#123456').change();
expect(model.get('h1.fontColor')).to.equal('#123457'); expect(model.get('text.fontColor')).to.equal('#123456');
}); });
it('changes model if h2 font color field changes', function() { it('changes model if h1 font color field changes', function() {
view.$('#mailpoet_h2_font_color').val('#123458').change(); view.$('#mailpoet_h1_font_color').val('#123457').change();
expect(model.get('h2.fontColor')).to.equal('#123458'); expect(model.get('h1.fontColor')).to.equal('#123457');
}); });
it('changes model if h3 font color field changes', function() { it('changes model if h2 font color field changes', function() {
view.$('#mailpoet_h3_font_color').val('#123426').change(); view.$('#mailpoet_h2_font_color').val('#123458').change();
expect(model.get('h3.fontColor')).to.equal('#123426'); expect(model.get('h2.fontColor')).to.equal('#123458');
}); });
it('changes model if link font color field changes', function() { it('changes model if h3 font color field changes', function() {
view.$('#mailpoet_a_font_color').val('#323232').change(); view.$('#mailpoet_h3_font_color').val('#123426').change();
expect(model.get('link.fontColor')).to.equal('#323232'); expect(model.get('h3.fontColor')).to.equal('#123426');
}); });
it('changes model if newsletter background color field changes', function() { it('changes model if link font color field changes', function() {
view.$('#mailpoet_newsletter_background_color').val('#636237').change(); view.$('#mailpoet_a_font_color').val('#323232').change();
expect(model.get('newsletter.backgroundColor')).to.equal('#636237'); expect(model.get('link.fontColor')).to.equal('#323232');
}); });
it('changes model if background color field changes', function() { it('changes model if newsletter background color field changes', function() {
view.$('#mailpoet_background_color').val('#878587').change(); view.$('#mailpoet_newsletter_background_color').val('#636237').change();
expect(model.get('background.backgroundColor')).to.equal('#878587'); expect(model.get('newsletter.backgroundColor')).to.equal('#636237');
}); });
it('changes model if text font family field changes', function() { it('changes model if background color field changes', function() {
view.$('#mailpoet_text_font_family').val('Times New Roman').change(); view.$('#mailpoet_background_color').val('#878587').change();
expect(model.get('text.fontFamily')).to.equal('Times New Roman'); expect(model.get('background.backgroundColor')).to.equal('#878587');
}); });
it('changes model if h1 font family field changes', function() { it('changes model if text font family field changes', function() {
view.$('#mailpoet_h1_font_family').val('Comic Sans').change(); view.$('#mailpoet_text_font_family').val('Times New Roman').change();
expect(model.get('h1.fontFamily')).to.equal('Comic Sans'); expect(model.get('text.fontFamily')).to.equal('Times New Roman');
}); });
it('changes model if h2 font family field changes', function() { it('changes model if h1 font family field changes', function() {
view.$('#mailpoet_h2_font_family').val('Tahoma').change(); view.$('#mailpoet_h1_font_family').val('Comic Sans').change();
expect(model.get('h2.fontFamily')).to.equal('Tahoma'); expect(model.get('h1.fontFamily')).to.equal('Comic Sans');
}); });
it('changes model if h3 font family field changes', function() { it('changes model if h2 font family field changes', function() {
view.$('#mailpoet_h3_font_family').val('Lucida').change(); view.$('#mailpoet_h2_font_family').val('Tahoma').change();
expect(model.get('h3.fontFamily')).to.equal('Lucida'); expect(model.get('h2.fontFamily')).to.equal('Tahoma');
}); });
it('changes model if text font size field changes', function() { it('changes model if h3 font family field changes', function() {
view.$('#mailpoet_text_font_size').val('9px').change(); view.$('#mailpoet_h3_font_family').val('Lucida').change();
expect(model.get('text.fontSize')).to.equal('9px'); expect(model.get('h3.fontFamily')).to.equal('Lucida');
}); });
it('changes model if h1 font size field changes', function() { it('changes model if text font size field changes', function() {
view.$('#mailpoet_h1_font_size').val('12px').change(); view.$('#mailpoet_text_font_size').val('9px').change();
expect(model.get('h1.fontSize')).to.equal('12px'); expect(model.get('text.fontSize')).to.equal('9px');
}); });
it('changes model if h2 font size field changes', function() { it('changes model if h1 font size field changes', function() {
view.$('#mailpoet_h2_font_size').val('14px').change(); view.$('#mailpoet_h1_font_size').val('12px').change();
expect(model.get('h2.fontSize')).to.equal('14px'); expect(model.get('h1.fontSize')).to.equal('12px');
}); });
it('changes model if h3 font size field changes', function() { it('changes model if h2 font size field changes', function() {
view.$('#mailpoet_h3_font_size').val('16px').change(); view.$('#mailpoet_h2_font_size').val('14px').change();
expect(model.get('h3.fontSize')).to.equal('16px'); expect(model.get('h2.fontSize')).to.equal('14px');
}); });
it('changes model if link underline field changes', function() { it('changes model if h3 font size field changes', function() {
view.$('#mailpoet_a_font_underline').prop('checked', true).change(); view.$('#mailpoet_h3_font_size').val('16px').change();
expect(model.get('link.textDecoration')).to.equal('underline'); expect(model.get('h3.fontSize')).to.equal('16px');
}); });
});
});
describe('preview view', function() { it('changes model if link underline field changes', function() {
var view; view.$('#mailpoet_a_font_underline').prop('checked', true).change();
beforeEach(function() { expect(model.get('link.textDecoration')).to.equal('underline');
view = new (EditorApplication.module('components.sidebar').SidebarPreviewView)(); });
}); });
});
describe('preview view', function() {
var view;
beforeEach(function() {
view = new (EditorApplication.module('components.sidebar').SidebarPreviewView)();
});
it('renders', function() {
expect(view.render).to.not.throw();
});
});
});
it('renders', function() {
expect(view.render).to.not.throw();
});
});
}); });

View File

@ -1,40 +1,46 @@
describe('Styles', function () { define('test/newsletter_editor/components/config', [
it('loads and stores globally available styles', function() { 'newsletter_editor/App',
EditorApplication.module('components.styles').setGlobalStyles({ 'newsletter_editor/components/config'
testStyle: 'testValue', ], function(EditorApplication) {
});
var model = EditorApplication.module('components.styles').getGlobalStyles();
expect(model.get('testStyle')).to.equal('testValue');
});
describe('model', function() { describe('Styles', function () {
var model; it('loads and stores globally available styles', function() {
beforeEach(function() { EditorApplication.module('components.styles').setGlobalStyles({
model = new (EditorApplication.module('components.styles').StylesModel)(); testStyle: 'testValue',
}); });
var model = EditorApplication.module('components.styles').getGlobalStyles();
expect(model.get('testStyle')).to.equal('testValue');
});
it('triggers autoSave when changed', function() { describe('model', function() {
var mock = sinon.mock({ trigger: function(){}}).expects('trigger').once().withExactArgs('autoSave'); var model;
EditorApplication.getChannel = function() { beforeEach(function() {
return { model = new (EditorApplication.module('components.styles').StylesModel)();
trigger: mock, });
};
};
model.set('text.fontColor', '#123456');
mock.verify();
});
});
describe('view', function() { it('triggers autoSave when changed', function() {
var model, view; var mock = sinon.mock({ trigger: function(){}}).expects('trigger').once().withExactArgs('autoSave');
beforeEach(function() { EditorApplication.getChannel = function() {
model = new (EditorApplication.module('components.styles').StylesModel)(); return {
view = new (EditorApplication.module('components.styles').StylesView)({ model: model }); trigger: mock,
}); };
};
model.set('text.fontColor', '#123456');
mock.verify();
});
});
describe('view', function() {
var model, view;
beforeEach(function() {
model = new (EditorApplication.module('components.styles').StylesModel)();
view = new (EditorApplication.module('components.styles').StylesView)({ model: model });
});
it('renders', function() {
expect(view.render).to.not.throw();
});
});
});
it('renders', function() {
expect(view.render).to.not.throw();
});
});
}); });

View File

@ -1,94 +0,0 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, callbacks = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId])
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
/******/ while(callbacks.length)
/******/ callbacks.shift().call(null, __webpack_require__);
/******/ if(moreModules[0]) {
/******/ installedModules[0] = 0;
/******/ return __webpack_require__(0);
/******/ }
/******/ };
/******/ // The module cache
/******/ var installedModules = {};
/******/ // object to store loaded and loading chunks
/******/ // "0" means "already loaded"
/******/ // Array means "loading", array contains callbacks
/******/ var installedChunks = {
/******/ 1:0
/******/ };
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
/******/ // "0" is the signal for "already loaded"
/******/ if(installedChunks[chunkId] === 0)
/******/ return callback.call(null, __webpack_require__);
/******/ // an array means "currently loading".
/******/ if(installedChunks[chunkId] !== undefined) {
/******/ installedChunks[chunkId].push(callback);
/******/ } else {
/******/ // start chunk loading
/******/ installedChunks[chunkId] = [callback];
/******/ var head = document.getElementsByTagName('head')[0];
/******/ var script = document.createElement('script');
/******/ script.type = 'text/javascript';
/******/ script.charset = 'utf-8';
/******/ script.async = true;
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"0":"testAjax"}[chunkId]||chunkId) + ".js";
/******/ head.appendChild(script);
/******/ }
/******/ };
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ })
/************************************************************************/
/******/ ([]);

View File

@ -20,7 +20,9 @@ baseConfig = {
'backbone.marionette': 'backbone.marionette/lib/backbone.marionette', 'backbone.marionette': 'backbone.marionette/lib/backbone.marionette',
'backbone.supermodel$': 'backbone.supermodel/build/backbone.supermodel.js', 'backbone.supermodel$': 'backbone.supermodel/build/backbone.supermodel.js',
'sticky-kit': 'sticky-kit/jquery.sticky-kit', 'sticky-kit': 'sticky-kit/jquery.sticky-kit',
} 'interact$': 'interact.js/interact.js',
'spectrum$': 'spectrum-colorpicker/spectrum.js',
},
}, },
node: { node: {
fs: 'empty' fs: 'empty'
@ -47,6 +49,10 @@ baseConfig = {
include: require.resolve('handlebars'), include: require.resolve('handlebars'),
loader: 'expose-loader?Handlebars', loader: 'expose-loader?Handlebars',
}, },
{
include: require.resolve('handlebars'),
loader: 'expose-loader?Handlebars',
},
] ]
} }
}; };
@ -73,7 +79,7 @@ config.push(_.extend({}, baseConfig, {
'interact.js', 'interact.js',
'backbone.radio', 'backbone.radio',
'select2', 'select2',
'spectrum-colorpicker', 'spectrum',
'sticky-kit', 'sticky-kit',
'newsletter_editor/communicationsFix.js', 'newsletter_editor/communicationsFix.js',
@ -128,7 +134,62 @@ config.push(_.extend({}, baseConfig, {
config.push(_.extend({}, baseConfig, { config.push(_.extend({}, baseConfig, {
name: 'test', name: 'test',
entry: { entry: {
vendor: ['handlebars', 'handlebars_helpers'],
testAjax: 'testAjax.js', testAjax: 'testAjax.js',
testNewsletterEditor: [
'underscore',
'backbone',
'backbone.marionette',
'backbone.supermodel',
'backbone.radio',
'select2',
'newsletter_editor/communicationsFix.js',
'newsletter_editor/App',
'newsletter_editor/components/config.js',
'newsletter_editor/components/styles.js',
'newsletter_editor/components/sidebar.js',
'newsletter_editor/components/content.js',
'newsletter_editor/components/heading.js',
'newsletter_editor/components/save.js',
'newsletter_editor/behaviors/BehaviorsLookup.js',
'newsletter_editor/behaviors/ColorPickerBehavior.js',
'newsletter_editor/behaviors/ContainerDropZoneBehavior.js',
'newsletter_editor/behaviors/DraggableBehavior.js',
'newsletter_editor/behaviors/ResizableBehavior.js',
'newsletter_editor/behaviors/SortableBehavior.js',
'newsletter_editor/blocks/base.js',
'newsletter_editor/blocks/container.js',
'newsletter_editor/blocks/button.js',
'newsletter_editor/blocks/image.js',
'newsletter_editor/blocks/divider.js',
'newsletter_editor/blocks/text.js',
'newsletter_editor/blocks/spacer.js',
'newsletter_editor/blocks/footer.js',
'newsletter_editor/blocks/header.js',
'newsletter_editor/blocks/automatedLatestContent.js',
'newsletter_editor/blocks/posts.js',
'newsletter_editor/blocks/social.js',
'components/config.spec.js',
'components/content.spec.js',
'components/heading.spec.js',
'components/save.spec.js',
'components/sidebar.spec.js',
'components/styles.spec.js',
'blocks/automatedLatestContent.spec.js',
'blocks/button.spec.js',
'blocks/container.spec.js',
'blocks/divider.spec.js',
'blocks/footer.spec.js',
'blocks/header.spec.js',
'blocks/image.spec.js',
'blocks/posts.spec.js',
'blocks/social.spec.js',
'blocks/spacer.spec.js',
'blocks/text.spec.js',
],
}, },
output: { output: {
path: './tests/javascript/testBundles', path: './tests/javascript/testBundles',
@ -139,7 +200,18 @@ config.push(_.extend({}, baseConfig, {
'node_modules', 'node_modules',
'assets/js/src', 'assets/js/src',
'tests/javascript/newsletter_editor' 'tests/javascript/newsletter_editor'
] ],
alias: {
'sticky-kit': 'sticky-kit/jquery.sticky-kit',
'backbone.marionette': 'backbone.marionette/lib/backbone.marionette',
'backbone.supermodel$': 'backbone.supermodel/build/backbone.supermodel.js',
},
},
externals: {
'jquery': 'jQuery',
'tinymce': 'tinymce',
'interact': 'interact',
'spectrum': 'spectrum',
} }
})); }));