Skip to content

Commit

Permalink
use jest-codemods
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed May 27, 2018
1 parent a058afe commit e6613c4
Show file tree
Hide file tree
Showing 65 changed files with 806 additions and 794 deletions.
2 changes: 1 addition & 1 deletion test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import grapesjs from './../src';

describe('Main', () => {
describe('Startup', () => {
it('Main object should be loaded', () => {
test('Main object should be loaded', () => {
expect(grapesjs).toBeTruthy();
});
});
Expand Down
18 changes: 9 additions & 9 deletions test/specs/asset_manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ describe('Asset Manager', () => {
obj = null;
});

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

it('No assets inside', () => {
test('No assets inside', () => {
expect(obj.getAll().length).toEqual(0);
});

it('Add new asset', () => {
test('Add new asset', () => {
obj.add(imgObj);
expect(obj.getAll().length).toEqual(1);
});

it('Added asset has correct data', () => {
test('Added asset has correct data', () => {
obj.add(imgObj);
var asset = obj.get(imgObj.src);
expect(asset.get('width')).toEqual(imgObj.width);
expect(asset.get('height')).toEqual(imgObj.height);
expect(asset.get('type')).toEqual(imgObj.type);
});

it('Add asset with src', () => {
test('Add asset with src', () => {
obj.add(imgObj.src);
var asset = obj.get(imgObj.src);
expect(asset.get('type')).toEqual('image');
expect(asset.get('src')).toEqual(imgObj.src);
});

it('Add asset with more src', () => {
test('Add asset with more src', () => {
obj.add([imgObj.src, imgObj.src + '2']);
expect(obj.getAll().length).toEqual(2);
var asset1 = obj.getAll().at(0);
Expand All @@ -72,13 +72,13 @@ describe('Asset Manager', () => {
expect(asset2.get('src')).toEqual(imgObj.src + '2');
});

it('Remove asset', () => {
test('Remove asset', () => {
obj.add(imgObj);
obj.remove(imgObj.src);
expect(obj.getAll().length).toEqual(0);
});

it('Render assets', () => {
test('Render assets', () => {
obj.add(imgObj);
expect(obj.render()).toExist();
});
Expand All @@ -103,7 +103,7 @@ describe('Asset Manager', () => {
storageManager = null;
});

it('Store and load data', () => {
test('Store and load data', () => {
obj.add(imgObj);
obj.store();
obj.remove(imgObj.src);
Expand Down
8 changes: 4 additions & 4 deletions test/specs/asset_manager/model/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ var Asset = require('asset_manager/model/Asset');
module.exports = {
run() {
describe('Asset', () => {
it('Object exists', () => {
test('Object exists', () => {
expect(Asset).toExist();
});

it('Has default values', () => {
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();
});

it('Test getFilename', () => {
test('Test getFilename', () => {
var obj = new Asset({ type: 'image', src: 'ch/eck/t.e.s.t' });
expect(obj.getFilename()).toEqual('t.e.s.t');
var obj = new Asset({ type: 'image', src: 'ch/eck/1234abc' });
expect(obj.getFilename()).toEqual('1234abc');
});

it('Test getExtension', () => {
test('Test getExtension', () => {
var obj = new Asset({ type: 'image', src: 'ch/eck/t.e.s.t' });
expect(obj.getExtension()).toEqual('t');
var obj = new Asset({ type: 'image', src: 'ch/eck/1234abc.' });
Expand Down
4 changes: 2 additions & 2 deletions test/specs/asset_manager/model/AssetImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ var AssetImage = require('asset_manager/model/AssetImage');
module.exports = {
run() {
describe('AssetImage', () => {
it('Object exists', () => {
test('Object exists', () => {
expect(AssetImage).toExist();
});

it('Has default values', () => {
test('Has default values', () => {
var obj = new AssetImage({});
expect(obj.get('type')).toEqual('image');
expect(obj.get('src')).toNotExist();
Expand Down
4 changes: 2 additions & 2 deletions test/specs/asset_manager/model/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ module.exports = {
obj = null;
});

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

it('Collection is empty', () => {
test('Collection is empty', () => {
expect(obj.length).toEqual(0);
});
});
Expand Down
18 changes: 9 additions & 9 deletions test/specs/asset_manager/view/AssetImageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
let obj;

describe('AssetImageView', () => {
beforeEach(function() {
beforeEach(() => {
var coll = new Assets();
var model = coll.add({ type: 'image', src: '/test' });
obj = new AssetImageView({
Expand All @@ -19,48 +19,48 @@ module.exports = {
document.body.querySelector('#fixtures').appendChild(obj.render().el);
});

afterEach(function() {
afterEach(() => {
obj = null;
document.body.innerHTML = '';
});

it('Object exists', () => {
test('Object exists', () => {
expect(AssetImageView).toExist();
});

describe('Asset should be rendered correctly', () => {
it('Has preview box', function() {
test('Has preview box', () => {
var $asset = obj.$el;
expect($asset.find('.preview').length).toEqual(1);
});

it('Has meta box', function() {
test('Has meta box', () => {
var $asset = obj.$el;
expect($asset.find('.meta').length).toEqual(1);
});

it('Has close button', function() {
test('Has close button', () => {
var $asset = obj.$el;
expect($asset.find('[data-toggle=asset-remove]').length).toEqual(1);
});
});

it('Could be selected', function() {
test('Could be selected', () => {
var spy = expect.spyOn(obj, 'updateTarget');
obj.$el.trigger('click');
expect(obj.$el.attr('class')).toInclude('highlight');
expect(spy).toHaveBeenCalled();
});

it('Could be chosen', function() {
test('Could be chosen', () => {
sinon.stub(obj, 'updateTarget');
var spy = expect.spyOn(obj, 'updateTarget');
obj.$el.trigger('dblclick');
expect(spy).toHaveBeenCalled();
//obj.updateTarget.calledOnce.should.equal(true);
});

it('Could be removed', function() {
test('Could be removed', () => {
var spy = sinon.spy();
obj.model.on('remove', spy);
obj.onRemove({ stopImmediatePropagation() {} });
Expand Down
22 changes: 14 additions & 8 deletions test/specs/asset_manager/view/AssetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ var Assets = require('asset_manager/model/Assets');
module.exports = {
run() {
describe('AssetView', () => {
beforeEach(function() {
let testContext;

beforeEach(() => {
testContext = {};
});

beforeEach(() => {
var coll = new Assets();
var model = coll.add({ src: 'test' });
this.view = new AssetView({
testContext.view = new AssetView({
config: {},
model
});
document.body.innerHTML = '<div id="fixtures"></div>';
document.body
.querySelector('#fixtures')
.appendChild(this.view.render().el);
.appendChild(testContext.view.render().el);
});

afterEach(function() {
this.view.remove();
afterEach(() => {
testContext.view.remove();
});

it('Object exists', () => {
test('Object exists', () => {
expect(AssetView).toExist();
});

it('Has correct prefix', function() {
expect(this.view.pfx).toEqual('');
test('Has correct prefix', () => {
expect(testContext.view.pfx).toEqual('');
});
});
}
Expand Down
24 changes: 12 additions & 12 deletions test/specs/asset_manager/view/AssetsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
var obj;
var coll;

beforeEach(function() {
beforeEach(() => {
coll = new Assets([]);
obj = new AssetsView({
config: {},
Expand All @@ -22,59 +22,59 @@ module.exports = {
document.body.querySelector('#fixtures').appendChild(obj.el);
});

afterEach(function() {
afterEach(() => {
obj.collection.reset();
});

it('Object exists', () => {
test('Object exists', () => {
expect(AssetsView).toExist();
});

it('Collection is empty', function() {
test('Collection is empty', () => {
expect(obj.getAssetsEl().innerHTML).toNotExist();
});

it('Add new asset', function() {
test('Add new asset', () => {
sinon.stub(obj, 'addAsset');
coll.add({ src: 'test' });
expect(obj.addAsset.calledOnce).toEqual(true);
});

it('Render new asset', function() {
test('Render new asset', () => {
coll.add({ src: 'test' });
expect(obj.getAssetsEl().innerHTML).toExist();
});

it('Render correctly new image asset', function() {
test('Render correctly new image asset', () => {
coll.add({ type: 'image', src: 'test' });
var asset = obj.getAssetsEl().firstChild;
expect(asset.tagName).toEqual('DIV');
expect(asset.innerHTML).toExist();
});

it('Clean collection from asset', function() {
test('Clean collection from asset', () => {
var model = coll.add({ src: 'test' });
coll.remove(model);
expect(obj.getAssetsEl().innerHTML).toNotExist();
});

it('Deselect works', function() {
test('Deselect works', () => {
coll.add([{}, {}]);
var $asset = obj.$el.children().first();
$asset.attr('class', obj.pfx + 'highlight');
coll.trigger('deselectAll');
expect($asset.attr('class')).toNotExist();
});

it('Returns not empty assets element', () => {
test('Returns not empty assets element', () => {
expect(obj.getAssetsEl()).toExist();
});

it('Returns not empty url input', () => {
test('Returns not empty url input', () => {
expect(obj.getAddInput()).toExist();
});

it('Add image asset from input string', () => {
test('Add image asset from input string', () => {
obj.getAddInput().value = 'test';
obj.handleSubmit({
preventDefault() {}
Expand Down
22 changes: 11 additions & 11 deletions test/specs/asset_manager/view/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@ module.exports = {
describe('File Uploader', () => {
let obj;

beforeEach(function() {
beforeEach(() => {
obj = new FileUploader({ config: {} });
document.body.innerHTML = '<div id="fixtures"></div>';
document.body.querySelector('#fixtures').appendChild(obj.render().el);
});

afterEach(function() {
afterEach(() => {
obj.remove();
});

it('Object exists', () => {
test('Object exists', () => {
expect(FileUploader).toExist();
});

it('Has correct prefix', function() {
test('Has correct prefix', () => {
expect(obj.pfx).toNotExist();
});

describe('Should be rendered correctly', () => {
it('Has title', function() {
test('Has title', () => {
expect(obj.$el.find('#title').length).toEqual(1);
});

it('Title is empty', function() {
test('Title is empty', () => {
expect(obj.$el.find('#title').html()).toEqual('');
});

it('Has file input', function() {
test('Has file input', () => {
expect(obj.$el.find('input[type=file]').length).toEqual(1);
});

it('File input is enabled', function() {
test('File input is enabled', () => {
expect(obj.$el.find('input[type=file]').prop('disabled')).toEqual(
true
);
});
});

describe('Interprets configurations correctly', () => {
it('Has correct title', () => {
test('Has correct title', () => {
var view = new FileUploader({
config: {
uploadText: 'Test'
Expand All @@ -54,7 +54,7 @@ module.exports = {
expect(view.$el.find('#title').html()).toEqual('Test');
});

it('Could be disabled', () => {
test('Could be disabled', () => {
var view = new FileUploader({
config: {
disableUpload: true,
Expand All @@ -67,7 +67,7 @@ module.exports = {
);
});

it('Handles embedAsBase64 parameter', () => {
test('Handles embedAsBase64 parameter', () => {
var view = new FileUploader({
config: {
embedAsBase64: true
Expand Down
Loading

0 comments on commit e6613c4

Please sign in to comment.