Tests vars-on-top
This commit is contained in:
@ -20,7 +20,6 @@
|
||||
"no-underscore-dangle": 0,
|
||||
"no-shadow": 0,
|
||||
"padded-blocks": 0,
|
||||
"vars-on-top": 0,
|
||||
"space-before-blocks": 0,
|
||||
"object-curly-spacing": 0,
|
||||
"func-names": 0,
|
||||
|
@ -3,6 +3,7 @@ var sinon = require('sinon');
|
||||
var sinonChai = require('sinon-chai');
|
||||
var chaiJq = require('chai-jq');
|
||||
var _ = require('underscore');
|
||||
var jsdom = require('jsdom').jsdom;
|
||||
|
||||
chai.use(sinonChai);
|
||||
chai.use(chaiJq);
|
||||
@ -11,7 +12,6 @@ global.expect = chai.expect;
|
||||
global.sinon = sinon;
|
||||
|
||||
if (!global.document || !global.window) {
|
||||
var jsdom = require('jsdom').jsdom;
|
||||
|
||||
global.document = jsdom('<html><head><script></script></head><body></body></html>', {}, {
|
||||
FetchExternalResources: ['script'],
|
||||
|
@ -21,6 +21,8 @@ define([
|
||||
|
||||
describe('Automated Latest Content Supervisor', function() {
|
||||
var model;
|
||||
var mock;
|
||||
var module;
|
||||
beforeEach(function() {
|
||||
model = new AutomatedLatestContentBlock.ALCSupervisor();
|
||||
});
|
||||
@ -29,16 +31,16 @@ define([
|
||||
global.stubChannel(EditorApplication);
|
||||
EditorApplication.findModels = sinon.stub().returns([new Backbone.SuperModel()]);
|
||||
|
||||
var mock = sinon.mock({ getBulkTransformedPosts: function() {} })
|
||||
mock = sinon.mock({ getBulkTransformedPosts: function() {} })
|
||||
.expects('getBulkTransformedPosts').once().returns(jQuery.Deferred());
|
||||
|
||||
var module = AutomatedLatestContentInjector({
|
||||
module = AutomatedLatestContentInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
getBulkTransformedPosts: mock
|
||||
}
|
||||
});
|
||||
|
||||
var model = new module.ALCSupervisor();
|
||||
model = new module.ALCSupervisor();
|
||||
model.refresh();
|
||||
|
||||
mock.verify();
|
||||
@ -173,6 +175,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
automatedLatestContent: {
|
||||
@ -220,7 +223,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (module.AutomatedLatestContentBlockModel)();
|
||||
model = new (module.AutomatedLatestContentBlockModel)();
|
||||
|
||||
expect(model.get('amount')).to.equal('17');
|
||||
expect(model.get('contentType')).to.equal('mailpoet_page');
|
||||
@ -252,8 +255,9 @@ define([
|
||||
});
|
||||
|
||||
it('accepts displayable posts', function() {
|
||||
var model;
|
||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(ContainerBlock.ContainerBlockModel);
|
||||
var model = new (module.AutomatedLatestContentBlockModel)();
|
||||
model = new (module.AutomatedLatestContentBlockModel)();
|
||||
|
||||
model.updatePosts([{
|
||||
type: 'someCustomType'
|
||||
@ -293,8 +297,8 @@ define([
|
||||
});
|
||||
|
||||
describe('replaceAllButtonStyles', function () {
|
||||
var model;
|
||||
var onStub;
|
||||
var view;
|
||||
|
||||
beforeEach(function () {
|
||||
onStub = sinon.stub();
|
||||
@ -302,8 +306,7 @@ define([
|
||||
global.stubConfig(EditorApplication);
|
||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
|
||||
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
|
||||
model = {set: sinon.stub()};
|
||||
new (AutomatedLatestContentBlock.AutomatedLatestContentBlockView)({model: model});
|
||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockView)({model: {set: sinon.stub()}});
|
||||
});
|
||||
|
||||
it('listens to the event', function () {
|
||||
@ -321,8 +324,8 @@ define([
|
||||
}
|
||||
};
|
||||
callback(data);
|
||||
expect(model.set).to.have.been.callCount(1);
|
||||
expect(model.set).to.have.been.calledWithMatch(sinon.match.has('readMoreButton', data));
|
||||
expect(view.model.set).to.have.been.callCount(1);
|
||||
expect(view.model.set).to.have.been.calledWithMatch(sinon.match.has('readMoreButton', data));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -108,6 +108,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
button: {
|
||||
@ -131,7 +132,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (ButtonBlock.ButtonBlockModel)();
|
||||
model = new (ButtonBlock.ButtonBlockModel)();
|
||||
|
||||
expect(model.get('text')).to.equal('Some new text');
|
||||
expect(model.get('url')).to.equal('http://somenewurl.com');
|
||||
|
@ -13,8 +13,9 @@ define([
|
||||
|
||||
describe('model', function () {
|
||||
describe('by default', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication);
|
||||
var model = new ModelClass();
|
||||
model = new ModelClass();
|
||||
|
||||
it('has container type', function () {
|
||||
expect(model.get('type')).to.equal('container');
|
||||
@ -33,6 +34,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
container: {
|
||||
@ -44,7 +46,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (ContainerBlock.ContainerBlockModel)();
|
||||
model = new (ContainerBlock.ContainerBlockModel)();
|
||||
|
||||
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
|
||||
});
|
||||
@ -107,10 +109,12 @@ define([
|
||||
});
|
||||
|
||||
describe('block view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication);
|
||||
var model = new (ContainerBlock.ContainerBlockModel)();
|
||||
var view = new (ContainerBlock.ContainerBlockView)({model: model});
|
||||
model = new (ContainerBlock.ContainerBlockModel)();
|
||||
view = new (ContainerBlock.ContainerBlockView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
@ -187,10 +191,12 @@ define([
|
||||
});
|
||||
|
||||
describe('settings view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication);
|
||||
var model = new (ContainerBlock.ContainerBlockModel)();
|
||||
var view = new (ContainerBlock.ContainerBlockSettingsView)({model: model});
|
||||
model = new (ContainerBlock.ContainerBlockModel)();
|
||||
view = new (ContainerBlock.ContainerBlockSettingsView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
|
@ -70,6 +70,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
divider: {
|
||||
@ -85,7 +86,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (DividerBlock.DividerBlockModel)();
|
||||
model = new (DividerBlock.DividerBlockModel)();
|
||||
|
||||
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
|
||||
expect(model.get('styles.block.padding')).to.equal('37px');
|
||||
@ -137,13 +138,15 @@ define([
|
||||
});
|
||||
|
||||
describe('settings view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication, {
|
||||
dividers: ['solid', 'inset']
|
||||
});
|
||||
var model = new (DividerBlock.DividerBlockModel)();
|
||||
var view = new (DividerBlock.DividerBlockSettingsView)({model: model});
|
||||
model = new (DividerBlock.DividerBlockModel)();
|
||||
view = new (DividerBlock.DividerBlockSettingsView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
|
@ -79,6 +79,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
footer: {
|
||||
@ -101,7 +102,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (FooterBlock.FooterBlockModel)();
|
||||
model = new (FooterBlock.FooterBlockModel)();
|
||||
|
||||
expect(model.get('text')).to.equal('some custom config text');
|
||||
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
|
||||
@ -116,11 +117,12 @@ define([
|
||||
});
|
||||
|
||||
describe('block view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication);
|
||||
var model = new (FooterBlock.FooterBlockModel)();
|
||||
var view;
|
||||
model = new (FooterBlock.FooterBlockModel)();
|
||||
|
||||
beforeEach(function () {
|
||||
global.stubChannel(EditorApplication);
|
||||
@ -134,13 +136,15 @@ define([
|
||||
});
|
||||
|
||||
describe('settings view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication, {
|
||||
fonts: ['Arial', 'Tahoma'],
|
||||
textSizes: ['16px', '20px']
|
||||
});
|
||||
var model = new (FooterBlock.FooterBlockModel)();
|
||||
var view = new (FooterBlock.FooterBlockSettingsView)({model: model});
|
||||
model = new (FooterBlock.FooterBlockModel)();
|
||||
view = new (FooterBlock.FooterBlockSettingsView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
|
@ -79,6 +79,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
header: {
|
||||
@ -101,7 +102,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (HeaderBlock.HeaderBlockModel)();
|
||||
model = new (HeaderBlock.HeaderBlockModel)();
|
||||
|
||||
expect(model.get('text')).to.equal('some custom config text');
|
||||
expect(model.get('styles.block.backgroundColor')).to.equal('#123456');
|
||||
@ -115,11 +116,12 @@ define([
|
||||
});
|
||||
|
||||
describe('block view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication);
|
||||
var model = new (HeaderBlock.HeaderBlockModel)();
|
||||
var view;
|
||||
model = new (HeaderBlock.HeaderBlockModel)();
|
||||
|
||||
beforeEach(function () {
|
||||
global.stubChannel(EditorApplication);
|
||||
@ -133,14 +135,16 @@ define([
|
||||
});
|
||||
|
||||
describe('settings view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication, {
|
||||
fonts: ['Arial', 'Tahoma'],
|
||||
textSizes: ['16px', '20px']
|
||||
});
|
||||
var model = new (HeaderBlock.HeaderBlockModel)();
|
||||
var view = new (HeaderBlock.HeaderBlockSettingsView)({model: model});
|
||||
model = new (HeaderBlock.HeaderBlockModel)();
|
||||
view = new (HeaderBlock.HeaderBlockSettingsView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
|
@ -74,6 +74,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
image: {
|
||||
@ -91,7 +92,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (ImageBlock.ImageBlockModel)();
|
||||
model = new (ImageBlock.ImageBlockModel)();
|
||||
|
||||
expect(model.get('link')).to.equal('http://example.org/customConfigPage');
|
||||
expect(model.get('src')).to.equal('http://example.org/someCustomConfigImage.png');
|
||||
@ -104,11 +105,12 @@ define([
|
||||
});
|
||||
|
||||
describe('block view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
global.stubAvailableStyles(EditorApplication);
|
||||
var model = new (ImageBlock.ImageBlockModel)();
|
||||
var view;
|
||||
model = new (ImageBlock.ImageBlockModel)();
|
||||
|
||||
beforeEach(function () {
|
||||
view = new (ImageBlock.ImageBlockView)({model: model});
|
||||
|
@ -132,6 +132,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
posts: {
|
||||
@ -179,7 +180,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (PostsBlock.PostsBlockModel)();
|
||||
model = new (PostsBlock.PostsBlockModel)();
|
||||
|
||||
expect(model.get('amount')).to.equal('17');
|
||||
expect(model.get('contentType')).to.equal('mailpoet_page');
|
||||
|
@ -29,6 +29,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
social: {
|
||||
@ -36,7 +37,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (SocialBlock.SocialBlockModel)();
|
||||
model = new (SocialBlock.SocialBlockModel)();
|
||||
|
||||
expect(model.get('iconSet')).to.equal('customConfigIconSet');
|
||||
});
|
||||
|
@ -55,6 +55,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
spacer: {
|
||||
@ -67,7 +68,7 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (SpacerBlock.SpacerBlockModel)();
|
||||
model = new (SpacerBlock.SpacerBlockModel)();
|
||||
|
||||
expect(model.get('styles.block.backgroundColor')).to.equal('#567890');
|
||||
expect(model.get('styles.block.height')).to.equal('19px');
|
||||
@ -119,11 +120,12 @@ define([
|
||||
});
|
||||
|
||||
describe('settings view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubChannel(EditorApplication);
|
||||
global.stubConfig(EditorApplication);
|
||||
|
||||
var model = new (SpacerBlock.SpacerBlockModel)();
|
||||
var view;
|
||||
model = new (SpacerBlock.SpacerBlockModel)();
|
||||
|
||||
beforeEach(function () {
|
||||
global.stubChannel(EditorApplication);
|
||||
|
@ -23,6 +23,7 @@ define([
|
||||
});
|
||||
|
||||
it('uses defaults from config when they are set', function () {
|
||||
var model;
|
||||
global.stubConfig(EditorApplication, {
|
||||
blockDefaults: {
|
||||
text: {
|
||||
@ -30,16 +31,18 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
var model = new (TextBlock.TextBlockModel)();
|
||||
model = new (TextBlock.TextBlockModel)();
|
||||
|
||||
expect(model.get('text')).to.equal('some custom config text');
|
||||
});
|
||||
});
|
||||
|
||||
describe('block view', function () {
|
||||
var model;
|
||||
var view;
|
||||
global.stubConfig(EditorApplication);
|
||||
var model = new (TextBlock.TextBlockModel)();
|
||||
var view = new (TextBlock.TextBlockView)({model: model});
|
||||
model = new (TextBlock.TextBlockModel)();
|
||||
view = new (TextBlock.TextBlockView)({model: model});
|
||||
|
||||
it('renders', function () {
|
||||
expect(view.render).to.not.throw();
|
||||
|
@ -7,10 +7,11 @@ define([
|
||||
|
||||
describe('Config', function () {
|
||||
it('loads and stores configuration', function() {
|
||||
var model;
|
||||
ConfigComponent.setConfig({
|
||||
testConfig: 'testValue'
|
||||
});
|
||||
var model = ConfigComponent.getConfig();
|
||||
model = ConfigComponent.getConfig();
|
||||
expect(model.get('testConfig')).to.equal('testValue');
|
||||
});
|
||||
});
|
||||
|
@ -78,6 +78,7 @@ define([
|
||||
|
||||
describe('transformation to json', function() {
|
||||
it('includes content, globalStyles and initial newsletter fields', function() {
|
||||
var json;
|
||||
var dataField = {
|
||||
containerModelField: 'containerModelValue'
|
||||
};
|
||||
@ -106,7 +107,7 @@ define([
|
||||
}
|
||||
};
|
||||
};
|
||||
var json = ContentComponent.toJSON();
|
||||
json = ContentComponent.toJSON();
|
||||
expect(json).to.deep.equal(_.extend({
|
||||
body: {
|
||||
content: dataField,
|
||||
|
@ -38,6 +38,7 @@ define([
|
||||
});
|
||||
|
||||
it('triggers afterEditorSave event', function() {
|
||||
var module;
|
||||
var spy = sinon.spy();
|
||||
var promise = jQuery.Deferred();
|
||||
global.stubChannel(EditorApplication, {
|
||||
@ -48,7 +49,7 @@ define([
|
||||
type: 'container'
|
||||
}
|
||||
});
|
||||
var module = SaveInjector({
|
||||
module = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
saveNewsletter: sinon.stub().returns(promise)
|
||||
}
|
||||
@ -74,6 +75,7 @@ define([
|
||||
});
|
||||
|
||||
it('encodes newsletter body in JSON format', function() {
|
||||
var module;
|
||||
var body = {type: 'testType'};
|
||||
var mock = sinon.mock()
|
||||
.once()
|
||||
@ -86,7 +88,7 @@ define([
|
||||
EditorApplication.toJSON = sinon.stub().returns({
|
||||
body: body
|
||||
});
|
||||
var module = SaveInjector({
|
||||
module = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
saveNewsletter: mock
|
||||
}
|
||||
@ -136,13 +138,15 @@ define([
|
||||
it('triggers template saving when clicked on "save as template" button', function() {
|
||||
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(jQuery.Deferred());
|
||||
var html2canvasMock = jQuery.Deferred();
|
||||
var module;
|
||||
var view;
|
||||
|
||||
html2canvasMock.resolve({
|
||||
toDataURL: function() { return 'somedataurl'; }
|
||||
});
|
||||
|
||||
EditorApplication.getBody = sinon.stub();
|
||||
var module = SaveInjector({
|
||||
module = SaveInjector({
|
||||
mailpoet: {
|
||||
Ajax: {
|
||||
post: mock
|
||||
@ -163,7 +167,7 @@ define([
|
||||
};
|
||||
}
|
||||
});
|
||||
var view = new (module.SaveView)();
|
||||
view = new (module.SaveView)();
|
||||
view.render();
|
||||
|
||||
view.$('.mailpoet_save_as_template_name').val('A sample template');
|
||||
@ -175,6 +179,7 @@ define([
|
||||
|
||||
it('saves newsletter when clicked on "next" button', function() {
|
||||
var spy = sinon.spy();
|
||||
var view;
|
||||
var module = SaveInjector({
|
||||
'newsletter_editor/components/communication': {
|
||||
saveNewsletter: function() {
|
||||
@ -185,7 +190,7 @@ define([
|
||||
global.stubChannel(EditorApplication, {
|
||||
trigger: spy
|
||||
});
|
||||
var view = new (module.SaveView)();
|
||||
view = new (module.SaveView)();
|
||||
view.render();
|
||||
|
||||
view.$('.mailpoet_save_next').click();
|
||||
|
@ -9,10 +9,11 @@ define([
|
||||
|
||||
describe('Styles', function () {
|
||||
it('loads and stores globally available styles', function() {
|
||||
var model;
|
||||
StylesComponent.setGlobalStyles({
|
||||
testStyle: 'testValue'
|
||||
});
|
||||
var model = StylesComponent.getGlobalStyles();
|
||||
model = StylesComponent.getGlobalStyles();
|
||||
expect(model.get('testStyle')).to.equal('testValue');
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user