Skip to content

Commit

Permalink
Update tests for jest
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed May 27, 2018
1 parent e6613c4 commit eb0f1bd
Show file tree
Hide file tree
Showing 86 changed files with 264 additions and 264 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
},
"jest": {
"modulePaths": ["./src"],
"setupFiles": ["<rootDir>/test/setup.js"],
"moduleNameMapper": {
"^jquery$": "cash-dom"
}
Expand Down
2 changes: 2 additions & 0 deletions src/asset_manager/view/AssetView.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Backbone from 'backbone';

module.exports = Backbone.View.extend({
initialize(o = {}) {
this.options = o;
Expand Down
1 change: 1 addition & 0 deletions src/asset_manager/view/AssetsView.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
var AssetView = require('./AssetView');
var AssetImageView = require('./AssetImageView');
var FileUploader = require('./FileUploader');
Expand Down
2 changes: 1 addition & 1 deletion src/block_manager/model/Block.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var Category = require('./Category');

module.exports = Backbone.Model.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/block_manager/model/Blocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var Block = require('./Block');

module.exports = Backbone.Collection.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/block_manager/model/Categories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Collection.extend({
model: require('./Category')
Expand Down
2 changes: 1 addition & 1 deletion src/block_manager/model/Category.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
defaults: {
Expand Down
4 changes: 2 additions & 2 deletions src/block_manager/view/BlocksView.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isString, isObject } from 'underscore';
import { isString, isObject, bindAll } from 'underscore';

const BlockView = require('./BlockView');
const CategoryView = require('./CategoryView');

module.exports = require('backbone').View.extend({
initialize(opts, config) {
_.bindAll(this, 'getSorter', 'onDrag', 'onDrop');
bindAll(this, 'getSorter', 'onDrag', 'onDrop');
this.config = config || {};
this.categories = opts.categories || '';
this.renderedCategories = [];
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/model/Canvas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var Frame = require('./Frame');

module.exports = Backbone.Model.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/model/Frame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
defaults: {
Expand Down
1 change: 1 addition & 0 deletions src/canvas/view/CanvasView.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
import { on, off, getElement } from 'utils/mixins';
const FrameView = require('./FrameView');
const $ = Backbone.$;
Expand Down
2 changes: 1 addition & 1 deletion src/code_manager/model/CodeMirrorEditor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var CodeMirror = require('codemirror/lib/codemirror');
var htmlMode = require('codemirror/mode/htmlmixed/htmlmixed');
var cssMode = require('codemirror/mode/css/css');
Expand Down
2 changes: 1 addition & 1 deletion src/code_manager/model/HtmlGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
build(model, opts = {}) {
Expand Down
5 changes: 3 additions & 2 deletions src/code_manager/model/JsGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Backbone = require('backbone');
import { extend } from 'underscore';
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
mapModel(model) {
Expand All @@ -11,7 +12,7 @@ module.exports = Backbone.Model.extend({
if (script) {
// If the component has scripts we need to expose his ID
var attr = model.get('attributes');
attr = _.extend({}, attr, { id });
attr = extend({}, attr, { id });
model.set('attributes', attr);
var scrStr = model.getScriptString();

Expand Down
5 changes: 3 additions & 2 deletions src/code_manager/model/JsonGenerator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var Backbone = require('backbone');
import { each } from 'underscore';
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
/** @inheritdoc */
build(model) {
var json = model.toJSON();
this.beforeEach(json);

_.each(
each(
json,
function(v, attr) {
var obj = json[attr];
Expand Down
5 changes: 3 additions & 2 deletions src/code_manager/view/EditorView.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var Backbone = require('backbone');
import { template } from 'underscore';
import Backbone from 'backbone';

module.exports = Backbone.View.extend({
template: _.template(`
template: template(`
<div class="<%= pfx %>editor" id="<%= pfx %><%= codeName %>">
<div id="<%= pfx %>title"><%= label %></div>
<div id="<%= pfx %>code"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/commands/model/Command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
defaults: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/model/Commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var Command = require('./Command');

module.exports = Backbone.Collection.extend({
Expand Down
2 changes: 2 additions & 0 deletions src/commands/view/CreateComponent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'underscore';
import Backbone from 'backbone';
const SelectPosition = require('./SelectPosition');
const $ = Backbone.$;

Expand Down
2 changes: 2 additions & 0 deletions src/commands/view/DeleteComponent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'underscore';
import Backbone from 'backbone';
const SelectComponent = require('./SelectComponent');
const $ = Backbone.$;

Expand Down
1 change: 1 addition & 0 deletions src/commands/view/ExportTemplate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
const $ = Backbone.$;

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/view/ImageComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Backbone = require('backbone');
import _ from 'underscore';
import Backbone from 'backbone';
var InsertCustom = require('./InsertCustom');

module.exports = _.extend({}, InsertCustom, {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/view/InsertCustom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Backbone = require('backbone');
import _ from 'underscore';
import Backbone from 'backbone';
var CreateComponent = require('./CreateComponent');

module.exports = _.extend({}, CreateComponent, {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/view/MoveComponent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'underscore';
import Backbone from 'backbone';
import { on, off } from 'utils/mixins';

const SelectComponent = require('./SelectComponent');
Expand Down
1 change: 1 addition & 0 deletions src/commands/view/OpenLayers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
const Layers = require('navigator');
const $ = Backbone.$;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/view/OpenStyleManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Backbone from 'backbone';
const StyleManager = require('style_manager');
const Backbone = require('backbone');
const $ = Backbone.$;

module.exports = {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/view/Preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'underscore';

module.exports = {
getPanels(editor) {
if (!this.panels) this.panels = editor.Panels.getPanelsEl();
Expand Down
1 change: 1 addition & 0 deletions src/commands/view/SelectPosition.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
const $ = Backbone.$;

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions src/commands/view/ShowOffset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
const $ = Backbone.$;

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/view/TextComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Backbone = require('backbone');
import _ from 'underscore';
import Backbone from 'backbone';
var CreateComponent = require('./CreateComponent');

module.exports = _.extend({}, CreateComponent, {
Expand Down
3 changes: 2 additions & 1 deletion src/css_composer/model/CssRule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'underscore';
import Backbone from 'backbone';
import Styleable from 'domain_abstract/model/Styleable';
import { isEmpty, forEach } from 'underscore';

var Backbone = require('backbone');
var Selectors = require('selector_manager/model/Selectors');

module.exports = Backbone.Model.extend(Styleable).extend({
Expand Down
2 changes: 1 addition & 1 deletion src/css_composer/model/CssRules.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var CssRule = require('./CssRule');

module.exports = Backbone.Collection.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/device_manager/model/Device.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';

module.exports = Backbone.Model.extend({
idAttribute: 'name',
Expand Down
2 changes: 1 addition & 1 deletion src/device_manager/model/Devices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Backbone = require('backbone');
import Backbone from 'backbone';
var Device = require('./Device');

module.exports = Backbone.Collection.extend({
Expand Down
1 change: 1 addition & 0 deletions src/utils/Dragger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
const $ = Backbone.$;

var getBoundingRect = (el, win) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/Sorter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backbone from 'backbone';
import { isString, isFunction } from 'underscore';
import { on, off, matches } from 'utils/mixins';
const $ = Backbone.$;
Expand Down
49 changes: 0 additions & 49 deletions test/helper.js

This file was deleted.

23 changes: 23 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import _ from 'underscore';
import Backbone from 'backbone';
import sinon from 'sinon';
import grapesjs from './../src';

const localStorage = {
getItem(key) {
return this[key];
},
setItem(key, value) {
this[key] = value;
},
removeItem(key, value) {
delete this[key];
}
};

global.Backbone = Backbone;
global._ = _;
global.sinon = sinon;
global.grapesjs = grapesjs;
global.$ = Backbone.$;
global.localStorage = localStorage;
4 changes: 2 additions & 2 deletions test/specs/asset_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Asset Manager', () => {
});

test('Object exists', () => {
expect(obj).toExist();
expect(obj).toBeTruthy();
});

test('No assets inside', () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Asset Manager', () => {

test('Render assets', () => {
obj.add(imgObj);
expect(obj.render()).toExist();
expect(obj.render()).toBeTruthy();
});

describe('With storage', () => {
Expand Down
10 changes: 5 additions & 5 deletions test/specs/asset_manager/model/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module.exports = {
run() {
describe('Asset', () => {
test('Object exists', () => {
expect(Asset).toExist();
expect(Asset).toBeTruthy();
});

test('Has default values', () => {
var obj = new Asset({});
expect(obj.get('type')).toNotExist();
expect(obj.get('src')).toNotExist();
expect(obj.getExtension()).toNotExist();
expect(obj.getFilename()).toNotExist();
expect(obj.get('type')).toBeFalsy();
expect(obj.get('src')).toBeFalsy();
expect(obj.getExtension()).toBeFalsy();
expect(obj.getFilename()).toBeFalsy();
});

test('Test getFilename', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/specs/asset_manager/model/AssetImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ module.exports = {
run() {
describe('AssetImage', () => {
test('Object exists', () => {
expect(AssetImage).toExist();
expect(AssetImage).toBeTruthy();
});

test('Has default values', () => {
var obj = new AssetImage({});
expect(obj.get('type')).toEqual('image');
expect(obj.get('src')).toNotExist();
expect(obj.get('src')).toBeFalsy();
expect(obj.get('unitDim')).toEqual('px');
expect(obj.get('height')).toEqual(0);
expect(obj.get('width')).toEqual(0);
expect(obj.getExtension()).toNotExist();
expect(obj.getFilename()).toNotExist();
expect(obj.getExtension()).toBeFalsy();
expect(obj.getFilename()).toBeFalsy();
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/specs/asset_manager/model/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
});

test('Object exists', () => {
expect(obj).toExist();
expect(obj).toBeTruthy();
});

test('Collection is empty', () => {
Expand Down
Loading

0 comments on commit eb0f1bd

Please sign in to comment.