Skip to content

Commit

Permalink
added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albanx committed Apr 28, 2017
1 parent ad7cd13 commit ea294a2
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (grunt) {
configFile: 'tests/config/karma.unit.js'
},
single: {
singleRun: true
singleRun: false
}
},

Expand Down
16 changes: 16 additions & 0 deletions imageditor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Image Editor Test</title>
<script data-main="js/main-editor" src="libs/require.js"></script>
</head>
<body>

<img id="test-image" style="width:150px;" src="test.jpg" />

<script type="text/javascript">

</script>

</body>
</html>
35 changes: 19 additions & 16 deletions js/RealUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ define(['FileObject', 'Constants', 'Utils', 'i18n'], /** @lends RealUploader */
* condition. If this function return false then the file will not be added to the list
* @constructor
*/
var RealUploader = function (querySelector, config) {
var RealUploader = function (querySelector, userConfig) {
this.fileList = {};
this.fileIndex = 0;
this.uploadQueue = [];
Expand Down Expand Up @@ -241,8 +241,10 @@ define(['FileObject', 'Constants', 'Utils', 'i18n'], /** @lends RealUploader */
beforeRenderFile: [] //runs before the file element is beeing rendered to the dom
};

if (this._setMainContainer(querySelector)) {
this.defineCheckersAndSetters(config);
var container = this._getMainContainer(querySelector);
if (container) {
this._setMainContainer(container);
this._defineCheckersAndSetters(userConfig);
this.slots = this.config.maxConnections;
new _(this.config.language);

Expand All @@ -260,7 +262,7 @@ define(['FileObject', 'Constants', 'Utils', 'i18n'], /** @lends RealUploader */
* @param userSettings settings define by the user
* @returns {Object} settings to be used
*/
defineCheckersAndSetters: function (userSettings) {
_defineCheckersAndSetters: function (userSettings) {

var me = this;
//define some getters and setters for validating settings
Expand Down Expand Up @@ -373,25 +375,26 @@ define(['FileObject', 'Constants', 'Utils', 'i18n'], /** @lends RealUploader */
}
return true;
},
_setMainContainer: function (querySelector) {
_getMainContainer: function (querySelector) {
var container = null;
if (querySelector instanceof HTMLElement) {
this.dom.container = querySelector;
container = querySelector;
} else if (typeof querySelector === 'string') {
this.dom.container = Utils.getEl(querySelector);
container = Utils.getEl(querySelector);
}

//if no DOM element container found then raise an error and stop
if (!this.dom.container) {
console.error(querySelector + _(' not found on the DOM'));
return false;
if(!container) {
console.warn(querySelector + _(' not found on the DOM'));
}

return container;
},
_setMainContainer: function (container) {
//check if the plugin has already been applied to this element
if (this.dom.container.classList.contains('ax-uploader')) {
if (container.classList.contains('ax-uploader')) {
console.warn(_('Real Uploader is already bind to this element'));
return false;
} else {
this.dom.container = container;
}
return true;
},
_addRemoveButton: function () {
var me = this;
Expand Down Expand Up @@ -494,7 +497,7 @@ define(['FileObject', 'Constants', 'Utils', 'i18n'], /** @lends RealUploader */
dropArea = me.config.dropArea;
} else if (me.config.dropArea === 'self') {
dropArea = this.dom.container;
} else if (typeof dropArea === 'string') {
} else if (typeof me.config.dropArea === 'string') {
dropArea = Utils.getEl(dropArea);
} else if (typeof me.config.dropArea === 'function') {
dropArea = me.config.dropArea.call(this);
Expand Down
18 changes: 18 additions & 0 deletions js/main-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
requirejs.config({
//By default load any module IDs from js/lib
baseUrl: 'js'
//except, if the module ID starts with "app",
//load it from the js/app directory. paths
//config is relative to the baseUrl, and
//never includes a ".js" extension since
//the paths config could be for a directory.
//paths: {
// app: '../app'
//}
});
//
//start our app here
define(['AreaSelector'], function(AreaSelector) {
var imageEditor = new AreaSelector();
return AreaSelector;
});
Binary file added test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/config/karma.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [ 'PhantomJS'],
browsers: [ 'PhantomJS', 'Chrome'],
colors: true,
singleRun: false,
autoWatch: true,
Expand Down
107 changes: 97 additions & 10 deletions tests/specs/RealUploader.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,103 @@
/**
*/
describe('The game launching', function() {
var sideGamesController;

beforeEach(function() {
});
define(['RealUploader', 'Constants'], function(RealUploader, Constants) {
console.log('1.create real uploader');

it('is defined', function() {
});
describe('RealUploader', function() {
var uploader;

it('sets the category', function() {
});
beforeEach(function() {
if(document.getElementById('uploader')) {
document.body.removeChild(document.getElementById('uploader'));
}
var div = document.createElement('div');
div.id = 'uploader';
document.body.appendChild(div);
uploader = new RealUploader('#uploader', {
allowedExtensions: ['Jpg', 'png']
});
});

it('is defined', function() {
expect(uploader instanceof RealUploader).toBe(true);
});

it('default config is ok', function() {
expect(uploader.fileList).toEqual({});
expect(uploader.fileIndex).toEqual(0);
expect(uploader.uploadQueue).toEqual([]);
expect(uploader.dom.container).toBeDefined();
expect(uploader.totalUploadedBytes).toEqual(0);
expect(uploader.checkInterval).toEqual(false);
expect(uploader.globalStatus).toEqual(Constants.AX_IDLE);
});

it('_getMainContainer', function() {
expect(uploader._getMainContainer('#uploader2')).toBe(null);
expect(uploader._getMainContainer('#uploader')).not.toBe(null);
});

it('_defineCheckersAndSetters', function() {
expect(uploader.config.accept).toBe('');
expect(uploader.config.allowedExtensions).toEqual(['jpg', 'png']);
expect(uploader.config.language).toEqual('en_US');
expect(uploader.config.maxFileSize).toEqual(10485760);
expect(uploader.config.minFileSize).toEqual(0);
expect(uploader.config.listeners).toBe(null);
expect(uploader.config.enable).toBe(true);
});

it('checkUploadSupport', function() {
expect(uploader.checkUploadSupport()).toBe(true);
});

it('_addRemoveButton', function() {
expect(uploader.dom.removeButton).toBeDefined();
expect(uploader.dom.removeButton.classList.contains('ax-clear')).toBe(true);
expect(uploader.dom.removeButton.title).toBe('Remove all');
expect(uploader.dom.removeButtonText).toBeDefined();
expect(uploader.dom.removeButtonText.classList.contains('ax-text')).toBe(true);
expect(uploader.dom.removeButtonText.innerHTML).toBe('Remove all');
});

it('_addUploadButton', function() {
expect(uploader.dom.uploadButton).toBeDefined();
expect(uploader.dom.uploadButton.classList.contains('ax-upload-all')).toBe(true);
expect(uploader.dom.uploadButton.title).toBe('Upload all files');
expect(uploader.dom.uploadButtonText).toBeDefined();
expect(uploader.dom.uploadButtonText.classList.contains('ax-text')).toBe(true);
expect(uploader.dom.uploadButtonText.innerHTML).toBe('Start upload');
});

it('_addBrowseButton', function() {
expect(uploader.dom.browseButton).toBeDefined();
expect(uploader.dom.browseButton.classList.contains('ax-browse-c')).toBe(true);
expect(uploader.dom.browseButton.title).toBe('Add files');
expect(uploader.dom.browseButtonText).toBeDefined();
expect(uploader.dom.browseButtonText.classList.contains('ax-text')).toBe(true);
expect(uploader.dom.browseButtonText.innerHTML).toBe('Add files');
});

it('_setDragAndDropTitle', function() {
expect(uploader.dom.title).toBeDefined();
expect(uploader.dom.title.classList.contains('ax-main-title')).toBe(true);
expect(uploader.dom.title.innerHTML).toBe('Select Files or Drag&amp;Drop Files');
});

it('_addBrowseInput', function() {
expect(uploader.dom.browseInput).toBeDefined();
expect(uploader.dom.browseInput.classList.contains('ax-browse')).toBe(true);
});

it('renderHtml', function() {
expect(uploader.dom.fileList).toBeDefined();
expect(uploader.dom.container).toBeDefined();
expect(uploader.dom.fileList.classList.contains('ax-file-list')).toBe(true);
expect(uploader.dom.container.classList.contains('ax-uploader')).toBe(true);
});

it('_findDropArea', function() {
expect(uploader._findDropArea()).toBeDefined(uploader.dom.container);
});
});
});

0 comments on commit ea294a2

Please sign in to comment.