Tests one-var

This commit is contained in:
Amine Ben hammou
2017-09-26 12:57:13 +00:00
parent 651c9f5692
commit 69c540288b
19 changed files with 187 additions and 158 deletions

View File

@ -9,7 +9,6 @@
}, },
"rules": { "rules": {
"import/no-amd": 0, "import/no-amd": 0,
"one-var": 0,
"no-whitespace-before-property": 0, "no-whitespace-before-property": 0,
"global-require": 0, "global-require": 0,
"keyword-spacing": 0, "keyword-spacing": 0,

View File

@ -1,8 +1,8 @@
var fs = require('fs'); var fs = require('fs');
module.exports = { module.exports = {
loadFileToContainer: function (path, window, containerTagName, opts) { loadFileToContainer: function (path, window, containerTagName, opts) {
var contents = fs.readFileSync(path), var contents = fs.readFileSync(path);
container = window.document.createElement(containerTagName); var container = window.document.createElement(containerTagName);
var options = opts || {}; var options = opts || {};
container.innerHTML = contents; container.innerHTML = contents;

View File

@ -45,17 +45,17 @@ define([
}); });
it('refreshes posts for given blocks', function() { it('refreshes posts for given blocks', function() {
var block1 = new Backbone.SuperModel(), var block1 = new Backbone.SuperModel();
block2 = new Backbone.SuperModel(), var block2 = new Backbone.SuperModel();
postsSet1 = [ var postsSet1 = [
{ type: 'customTypeOne' } { type: 'customTypeOne' }
], ];
postsSet2 = [ var postsSet2 = [
{ type: 'customTypeTwo' }, { type: 'customTypeTwo' },
{ type: 'customTypeTwo' } { type: 'customTypeTwo' }
], ];
mock1 = sinon.mock(block1), var mock1 = sinon.mock(block1);
mock2 = sinon.mock(block2); var mock2 = sinon.mock(block2);
mock1.expects('trigger').once().withArgs('refreshPosts', postsSet1); mock1.expects('trigger').once().withArgs('refreshPosts', postsSet1);
mock2.expects('trigger').once().withArgs('refreshPosts', postsSet2); mock2.expects('trigger').once().withArgs('refreshPosts', postsSet2);
@ -69,7 +69,8 @@ define([
describe('Automated latest content', function () { describe('Automated latest content', function () {
describe('model', function () { describe('model', function () {
var model, module; var model;
var module;
before(function() { before(function() {
module = AutomatedLatestContentBlock; module = AutomatedLatestContentBlock;
@ -264,7 +265,9 @@ define([
}); });
describe('block view', function () { describe('block view', function () {
var model, view, module; var model;
var view;
var module;
before(function() { before(function() {
module = AutomatedLatestContentBlock; module = AutomatedLatestContentBlock;
@ -290,7 +293,10 @@ define([
}); });
describe('replaceAllButtonStyles', function () { describe('replaceAllButtonStyles', function () {
var model, view, module, onStub; var model;
var view;
var module;
var onStub;
before(function() { before(function() {
module = AutomatedLatestContentBlock; module = AutomatedLatestContentBlock;
@ -327,7 +333,9 @@ define([
}); });
describe('block settings view', function () { describe('block settings view', function () {
var model, view, module; var model;
var view;
var module;
before(function() { before(function() {
module = AutomatedLatestContentInjector({ module = AutomatedLatestContentInjector({
@ -496,7 +504,8 @@ define([
}); });
describe('when "title only" display type is selected', function() { describe('when "title only" display type is selected', function() {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
@ -509,7 +518,8 @@ define([
}); });
describe('when "title as list" is selected', function() { describe('when "title as list" is selected', function() {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
model = new (module.AutomatedLatestContentBlockModel)(); model = new (module.AutomatedLatestContentBlockModel)();
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model}); view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});

View File

@ -173,7 +173,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
before(function () { before(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -264,8 +265,9 @@ define([
}); });
describe('replaceAllButtonStyles', function () { describe('replaceAllButtonStyles', function () {
var model, view, onStub; var model;
var view;
var onStub;
beforeEach(function () { beforeEach(function () {
onStub = sinon.stub(); onStub = sinon.stub();
@ -317,7 +319,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
before(function() { before(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);

View File

@ -54,8 +54,8 @@ define([
var testModel = { var testModel = {
type: 'sampleType', type: 'sampleType',
someField: 'Some Content' someField: 'Some Content'
}, };
model; var model;
it('will recursively create children', function () { it('will recursively create children', function () {
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model); EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
@ -109,8 +109,8 @@ define([
describe('block view', function () { describe('block view', function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
var model = new (ContainerBlock.ContainerBlockModel)(), var model = new (ContainerBlock.ContainerBlockModel)();
view = new (ContainerBlock.ContainerBlockView)({model: model}); var view = new (ContainerBlock.ContainerBlockView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
@ -119,8 +119,8 @@ define([
describe('once rendered', function () { describe('once rendered', function () {
describe('on root level', function () { describe('on root level', function () {
var model = new (ContainerBlock.ContainerBlockModel)(), var model = new (ContainerBlock.ContainerBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -151,8 +151,8 @@ define([
}); });
describe.skip('on non-root levels', function () { describe.skip('on non-root levels', function () {
var model = new (ContainerBlock.ContainerBlockModel)(), var model = new (ContainerBlock.ContainerBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -189,15 +189,16 @@ define([
describe('settings view', function () { describe('settings view', function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
var model = new (ContainerBlock.ContainerBlockModel)(), var model = new (ContainerBlock.ContainerBlockModel)();
view = new (ContainerBlock.ContainerBlockSettingsView)({model: model}); var view = new (ContainerBlock.ContainerBlockSettingsView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);

View File

@ -142,8 +142,8 @@ define([
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {
dividers: ['solid', 'inset'] dividers: ['solid', 'inset']
}); });
var model = new (DividerBlock.DividerBlockModel)(), var model = new (DividerBlock.DividerBlockModel)();
view = new (DividerBlock.DividerBlockSettingsView)({model: model}); var view = new (DividerBlock.DividerBlockSettingsView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
@ -151,7 +151,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
before(function() { before(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);

View File

@ -119,8 +119,8 @@ define([
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
var model = new (FooterBlock.FooterBlockModel)(), var model = new (FooterBlock.FooterBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -139,8 +139,8 @@ define([
fonts: ['Arial', 'Tahoma'], fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'] textSizes: ['16px', '20px']
}); });
var model = new (FooterBlock.FooterBlockModel)(), var model = new (FooterBlock.FooterBlockModel)();
view = new (FooterBlock.FooterBlockSettingsView)({model: model}); var view = new (FooterBlock.FooterBlockSettingsView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
@ -148,7 +148,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);

View File

@ -118,8 +118,8 @@ define([
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
var model = new (HeaderBlock.HeaderBlockModel)(), var model = new (HeaderBlock.HeaderBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -139,8 +139,8 @@ define([
fonts: ['Arial', 'Tahoma'], fonts: ['Arial', 'Tahoma'],
textSizes: ['16px', '20px'] textSizes: ['16px', '20px']
}); });
var model = new (HeaderBlock.HeaderBlockModel)(), var model = new (HeaderBlock.HeaderBlockModel)();
view = new (HeaderBlock.HeaderBlockSettingsView)({model: model}); var view = new (HeaderBlock.HeaderBlockSettingsView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
@ -148,7 +148,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);

View File

@ -107,8 +107,8 @@ define([
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
global.stubAvailableStyles(EditorApplication); global.stubAvailableStyles(EditorApplication);
var model = new (ImageBlock.ImageBlockModel)(), var model = new (ImageBlock.ImageBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
view = new (ImageBlock.ImageBlockView)({model: model}); view = new (ImageBlock.ImageBlockView)({model: model});
@ -158,7 +158,8 @@ define([
}); });
describe('block settings view', function () { describe('block settings view', function () {
var model, view; var model;
var view;
var newWidth = 123; var newWidth = 123;
var newHeight = 456; var newHeight = 456;
var newLink = 'http://example.org/someNewLink'; var newLink = 'http://example.org/someNewLink';

View File

@ -261,7 +261,8 @@ define([
}); });
describe('block view', function () { describe('block view', function () {
var model, view; var model;
var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -285,7 +286,8 @@ define([
}); });
describe('block settings view', function () { describe('block settings view', function () {
var model, view; var model;
var view;
before(function () { before(function () {
CommunicationComponent.getPostTypes = function() { CommunicationComponent.getPostTypes = function() {
@ -421,7 +423,8 @@ define([
}); });
describe('when "title only" display type is selected', function() { describe('when "title only" display type is selected', function() {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
model = new (PostsBlock.PostsBlockModel)(); model = new (PostsBlock.PostsBlockModel)();
model.request = sinon.stub().returns({$el: {}}); model.request = sinon.stub().returns({$el: {}});

View File

@ -130,7 +130,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
before(function () { before(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -215,7 +216,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model, view; var model;
var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubAvailableStyles(EditorApplication, { global.stubAvailableStyles(EditorApplication, {

View File

@ -122,8 +122,8 @@ define([
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
var model = new (SpacerBlock.SpacerBlockModel)(), var model = new (SpacerBlock.SpacerBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
@ -135,7 +135,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var view, model; var view;
var model;
beforeEach(function() { beforeEach(function() {
global.stubChannel(EditorApplication); global.stubChannel(EditorApplication);
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);

View File

@ -38,8 +38,8 @@ define([
describe('block view', function () { describe('block view', function () {
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);
var model = new (TextBlock.TextBlockModel)(), var model = new (TextBlock.TextBlockModel)();
view = new (TextBlock.TextBlockView)({model: model}); var view = new (TextBlock.TextBlockView)({model: model});
it('renders', function () { it('renders', function () {
expect(view.render).to.not.throw(); expect(view.render).to.not.throw();
@ -47,8 +47,8 @@ define([
}); });
describe('once rendered', function () { describe('once rendered', function () {
var model = new (TextBlock.TextBlockModel)(), var model = new (TextBlock.TextBlockModel)();
view; var view;
beforeEach(function () { beforeEach(function () {
global.stubConfig(EditorApplication); global.stubConfig(EditorApplication);

View File

@ -32,9 +32,9 @@ define([
}); });
it('caches results', function() { it('caches results', function() {
var deferred = jQuery.Deferred(), var deferred = jQuery.Deferred();
mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred);
module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: mock post: mock
@ -54,16 +54,16 @@ define([
describe('getTaxonomies', function() { describe('getTaxonomies', function() {
it('sends post type to endpoint', function() { it('sends post type to endpoint', function() {
var spy, var spy;
post = function(params) { var post = function(params) {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({ deferred.resolve({
category: 'val1', category: 'val1',
post_tag: 'val2' post_tag: 'val2'
}); });
return deferred; return deferred;
}, };
module; var module;
spy = sinon.spy(post); spy = sinon.spy(post);
module = CommunicationInjector({ module = CommunicationInjector({
mailpoet: { mailpoet: {
@ -99,9 +99,9 @@ define([
}); });
it('caches results', function() { it('caches results', function() {
var deferred = jQuery.Deferred(), var deferred = jQuery.Deferred();
mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred);
module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: mock post: mock
@ -163,9 +163,9 @@ define([
}); });
it('caches results', function() { it('caches results', function() {
var deferred = jQuery.Deferred(), var deferred = jQuery.Deferred();
mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred);
module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: mock post: mock
@ -182,13 +182,13 @@ define([
describe('getPosts', function() { describe('getPosts', function() {
it('sends options to endpoint', function() { it('sends options to endpoint', function() {
var spy, var spy;
post = function(params) { var post = function(params) {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({}); deferred.resolve({});
return deferred; return deferred;
}, };
module; var module;
spy = sinon.spy(post); spy = sinon.spy(post);
module = CommunicationInjector({ module = CommunicationInjector({
mailpoet: { mailpoet: {
@ -231,9 +231,9 @@ define([
}); });
it('caches results', function() { it('caches results', function() {
var deferred = jQuery.Deferred(), var deferred = jQuery.Deferred();
mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred);
module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: mock post: mock
@ -253,13 +253,13 @@ define([
describe('getTransformedPosts', function() { describe('getTransformedPosts', function() {
it('sends options to endpoint', function() { it('sends options to endpoint', function() {
var spy, var spy;
post = function(params) { var post = function(params) {
var deferred = jQuery.Deferred(); var deferred = jQuery.Deferred();
deferred.resolve({}); deferred.resolve({});
return deferred; return deferred;
}, };
module; var module;
spy = sinon.spy(post); spy = sinon.spy(post);
module = CommunicationInjector({ module = CommunicationInjector({
mailpoet: { mailpoet: {
@ -302,9 +302,9 @@ define([
}); });
it('caches results', function() { it('caches results', function() {
var deferred = jQuery.Deferred(), var deferred = jQuery.Deferred();
mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(deferred);
module = CommunicationInjector({ var module = CommunicationInjector({
mailpoet: { mailpoet: {
Ajax: { Ajax: {
post: mock post: mock

View File

@ -65,8 +65,8 @@ define([
describe('block types', function() { describe('block types', function() {
it('registers a block type view and model', function() { it('registers a block type view and model', function() {
var blockModel = new Backbone.SuperModel(), var blockModel = new Backbone.SuperModel();
blockView = new Backbone.View(); var blockView = new Backbone.View();
ContentComponent.registerBlockType('testType', { ContentComponent.registerBlockType('testType', {
blockModel: blockModel, blockModel: blockModel,
blockView: blockView blockView: blockView
@ -80,9 +80,11 @@ define([
it('includes content, globalStyles and initial newsletter fields', function() { it('includes content, globalStyles and initial newsletter fields', function() {
var dataField = { var dataField = {
containerModelField: 'containerModelValue' containerModelField: 'containerModelValue'
}, stylesField = { };
var stylesField = {
globalStylesField: 'globalStylesValue' globalStylesField: 'globalStylesValue'
}, newsletterFields = { };
var newsletterFields = {
subject: 'test newsletter subject' subject: 'test newsletter subject'
}; };
EditorApplication._contentContainer = { EditorApplication._contentContainer = {

View File

@ -23,7 +23,8 @@ define([
}); });
describe('once rendered', function() { describe('once rendered', function() {
var view, model; var view;
var model;
beforeEach(function() { beforeEach(function() {
model = new Backbone.SuperModel({ model = new Backbone.SuperModel({
subject: 'a test subject', subject: 'a test subject',

View File

@ -38,8 +38,8 @@ define([
}); });
it('triggers afterEditorSave event', function() { it('triggers afterEditorSave event', function() {
var spy = sinon.spy(), var spy = sinon.spy();
promise = jQuery.Deferred(); var promise = jQuery.Deferred();
global.stubChannel(EditorApplication, { global.stubChannel(EditorApplication, {
trigger: spy trigger: spy
}); });
@ -74,8 +74,8 @@ define([
}); });
it('encodes newsletter body in JSON format', function() { it('encodes newsletter body in JSON format', function() {
var body = {type: 'testType'}, var body = {type: 'testType'};
mock = sinon.mock() var mock = sinon.mock()
.once() .once()
.withArgs({ .withArgs({
body: JSON.stringify(body) body: JSON.stringify(body)
@ -134,8 +134,8 @@ define([
}); });
it('triggers template saving when clicked on "save as template" button', function() { it('triggers template saving when clicked on "save as template" button', function() {
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(jQuery.Deferred()), var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(jQuery.Deferred());
html2canvasMock = jQuery.Deferred(); var html2canvasMock = jQuery.Deferred();
html2canvasMock.resolve({ html2canvasMock.resolve({
toDataURL: function() { return 'somedataurl'; } toDataURL: function() { return 'somedataurl'; }
@ -174,8 +174,8 @@ define([
}); });
it('saves newsletter when clicked on "next" button', function() { it('saves newsletter when clicked on "next" button', function() {
var spy = sinon.spy(), var spy = sinon.spy();
module = SaveInjector({ var module = SaveInjector({
'newsletter_editor/components/communication': { 'newsletter_editor/components/communication': {
saveNewsletter: function() { saveNewsletter: function() {
return jQuery.Deferred(); return jQuery.Deferred();

View File

@ -47,7 +47,9 @@ define([
}); });
describe('once rendered', function() { describe('once rendered', function() {
var model, availableStyles, view; var model;
var availableStyles;
var view;
before(function() { before(function() {
model = new Backbone.SuperModel({ model = new Backbone.SuperModel({
text: { text: {

View File

@ -35,7 +35,8 @@ define([
}); });
describe('view', function() { describe('view', function() {
var model, view; var model;
var view;
beforeEach(function() { beforeEach(function() {
model = new (StylesComponent.StylesModel)(); model = new (StylesComponent.StylesModel)();
view = new (StylesComponent.StylesView)({ model: model }); view = new (StylesComponent.StylesView)({ model: model });