Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Revert "Revert "Merge branch 'refs/heads/unit-tests'""
Browse files Browse the repository at this point in the history
This reverts commit 251bc77.
  • Loading branch information
zamrzlaj committed Nov 2, 2012
1 parent 9ead18c commit e6c4f77
Show file tree
Hide file tree
Showing 13 changed files with 2,048 additions and 20 deletions.
20 changes: 15 additions & 5 deletions grunt.js
Expand Up @@ -2,6 +2,7 @@ module.exports = function(grunt) {
// tasks // tasks
grunt.loadTasks('build/tasks'); grunt.loadTasks('build/tasks');
grunt.loadNpmTasks('grunt-recess'); grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-testacular');


// configuration // configuration
grunt.initConfig({ grunt.initConfig({
Expand All @@ -16,7 +17,7 @@ module.exports = function(grunt) {
}, },
concat: { concat: {
dist: { dist: {
src: ['<banner:meta.banner>', 'src/ngx.js', 'src/**/!(lang)/*.js', 'src/**/lang/*.js'], src: ['<banner:meta.banner>', 'src/ngx.js', 'src/**/!(lang|test)/*.js', 'src/**/lang/*.js'],
dest: 'dist/ngx.js' dest: 'dist/ngx.js'
} }
}, },
Expand Down Expand Up @@ -58,8 +59,8 @@ module.exports = function(grunt) {
}, },
watch: { watch: {
scripts: { scripts: {
files: ['grunt.js', 'src/*.js', 'src/**/*.js'], files: ['grunt.js', 'src/*.js', 'src/**/*.js', 'test/**/*.js'],
tasks: 'lint concat min' tasks: 'lint concat min testacularRun'
}, },
styles: { styles: {
files: ['src/**/*.less'], files: ['src/**/*.less'],
Expand All @@ -69,10 +70,19 @@ module.exports = function(grunt) {
files: ['src/modules/**/*.html'], files: ['src/modules/**/*.html'],
tasks: 'copy' tasks: 'copy'
} }
},
testacularServer: {
unit: {
configFile: 'test/unit/config.js'
}
},
testacularRun: {
unit: {
runnerPort: 9100
}
} }
}); });


// default task
grunt.registerTask('default', 'lint clean concat copy min recess'); grunt.registerTask('default', 'lint clean concat copy min recess');

grunt.registerTask('devel', 'testacularServer watch');
}; };
14 changes: 6 additions & 8 deletions package.json
Expand Up @@ -2,23 +2,21 @@
"author": "https://github.com/lmc-eu", "author": "https://github.com/lmc-eu",
"name": "ngx-library", "name": "ngx-library",
"description": "NGX - extension library for AngularJS", "description": "NGX - extension library for AngularJS",
"version": "0.0.1", "version": "0.0.2",
"homepage": "http://github.com/lmc-eu/ngx-library", "homepage": "http://github.com/lmc-eu/ngx-library",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/lmc-eu/ngx-library.git" "url": "git://github.com/lmc-eu/ngx-library.git"
}, },
"engines": { "engines": {
"node": ">= 0.6.11" "node": ">=0.8.0"
}, },
"dependencies": { "dependencies": {
"grunt": ">= 0.3.12", "rimraf": ">=2.0.2",
"testacular": ">=0.4.0",
"grunt": ">=0.3.12",
"grunt-recess": ">=0.1.0", "grunt-recess": ">=0.1.0",
"rimraf": ">=2.0.2" "grunt-testacular": ">=0.2.0"
},
"devDependencies": {
"grunt-recess": ">=0.1.0",
"rimraf": ">=2.0.2"
}, },
"scripts" : { "scripts" : {
"test": "grunt" "test": "grunt"
Expand Down
10 changes: 5 additions & 5 deletions src/modules/date/date.js
Expand Up @@ -247,12 +247,12 @@


/** /**
* Date validator (from phpjs.org) * Date validator (from phpjs.org)
* @param m * @param year
* @param d * @param month
* @param y * @param day
* @return {Boolean} * @return {Boolean}
*/ */
ngxDate.check = function(m, d, y) { ngxDate.check = function(year, month, day) {
// http://kevin.vanzonneveld.net // http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Pyerre // + improved by: Pyerre
Expand All @@ -265,7 +265,7 @@
// * returns 3: true // * returns 3: true
// * example 4: checkdate(1, 390, 2000); // * example 4: checkdate(1, 390, 2000);
// * returns 4: false // * returns 4: false
return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate(); return (month > 0 && month < 13 && year > 0 && year < 32768 && day > 0 && day <= (new Date(year, month, 0)).getDate());
}; };


angular.module('ngx.date', []) angular.module('ngx.date', [])
Expand Down
15 changes: 15 additions & 0 deletions src/modules/date/test/date.test.js
@@ -0,0 +1,15 @@
describe('ngx.date', function() {
beforeEach(module('ngx.date', 'ngx.config'));

it('should format datetime', inject(function(ngxDate) {
expect(ngxDate.format('Y-m-d', 1351375200)).toEqual('2012-10-28');
expect(ngxDate.format('j.n.Y H:i:s', 1348815030)).toEqual('28.9.2012 08:50:30');
}));

it('should check datetime', inject(function(ngxDate) {
expect(ngxDate.check(2012, 12, 21)).toBeTruthy();
expect(ngxDate.check(2000, 1, 1)).toBeTruthy();
expect(ngxDate.check(2010, 13, 10)).toBeFalsy();
expect(ngxDate.check(1980, 2, 31)).toBeFalsy();
}));
});
1 change: 1 addition & 0 deletions src/modules/dictionary/dictionary.js
Expand Up @@ -12,6 +12,7 @@


/** /**
* Returns items by current language * Returns items by current language
* @param key
* @param language * @param language
*/ */
function ngxDictionary(key, language) { function ngxDictionary(key, language) {
Expand Down
47 changes: 47 additions & 0 deletions src/modules/dictionary/test/dictionary.test.js
@@ -0,0 +1,47 @@
describe('ngx.dictionary', function() {
var items = {
en: {
dictionary: 'dictionary',
item: 'item',
test: 'should register items'
},
cz: {
dictionary: 'slovník',
item: 'položka',
test: 'měl by zaregistrovat položky'
}
};

beforeEach(function() {
module('ngx.dictionary');

// change default angular english $locale to czech
inject(function($locale) {
$locale.id = 'cz-cs';
});

inject(function(ngxDictionary) {
ngxDictionary.addItems('en', items.en);
ngxDictionary.addItems('cz', items.cz);
});
});

it('should return item by default $locale language', inject(function(ngxDictionary) {
// default angular locale is english
expect(ngxDictionary('test')).toEqual(items.cz.test);
expect(ngxDictionary('item')).toEqual(items.cz.item);
expect(ngxDictionary('dictionary')).toEqual(items.cz.dictionary);
}));

it('should return item by specified/set language', inject(function(ngxDictionary) {
expect(ngxDictionary('test')).toEqual(items.cz.test);
expect(ngxDictionary('dictionary', 'en')).toEqual(items.en.dictionary);

// change default language
ngxDictionary.setLanguage('en');
expect(ngxDictionary('item')).toEqual(items.en.item);
expect(ngxDictionary('test', 'cz')).toEqual(items.cz.test);
expect(ngxDictionary('test', 'en')).toEqual(items.en.test);
}));

});
14 changes: 13 additions & 1 deletion src/modules/loader/loader.js
Expand Up @@ -24,7 +24,7 @@
* Loads external js/css files * Loads external js/css files
* @param files * @param files
*/ */
return function(files, onload) { var ngxLoader = function(files, onload) {
var js = [], var js = [],
css = []; css = [];


Expand All @@ -46,6 +46,8 @@
} else { } else {
throw new Error('File type not supported'); throw new Error('File type not supported');
} }

loaded.push(file);
}); });


if (js.length) { if (js.length) {
Expand All @@ -61,5 +63,15 @@
}); });
} }
}; };

/**
* Returns loaded files
* @return {Array}
*/
ngxLoader.getLoaded = function() {
return loaded;
};

return ngxLoader;
}]); }]);
})(window.angular, window.head); })(window.angular, window.head);
19 changes: 19 additions & 0 deletions src/modules/loader/test/loader.test.js
@@ -0,0 +1,19 @@
describe('ngx.loader', function() {
beforeEach(function() {
module('ngx.loader');
});

it('should not load same files twice', inject(function(ngxLoader) {
ngxLoader(['test1.js', 'test2.js', 'test1.js'], waitsFor(function() {
expect(ngxLoader.getLoaded().length).toEqual(2);
return true;
}));
}));

it('should throw an exception on unsupported type', inject(function(ngxLoader) {
expect(function() {
ngxLoader('image.jpg');
}).toThrow('File type not supported');
}));

});
2 changes: 1 addition & 1 deletion src/modules/ui/dateInput/dateInput.js
Expand Up @@ -60,7 +60,7 @@
if (viewValue && ctrl.$dirty) { if (viewValue && ctrl.$dirty) {
// parse and check date // parse and check date
var pd = new RegExp('^([0-9]{1,2}). ?([0-9]{1,2}). ?([0-9]{4})').exec(viewValue); var pd = new RegExp('^([0-9]{1,2}). ?([0-9]{1,2}). ?([0-9]{4})').exec(viewValue);
valid = (pd && ngxDate.check(pd[2], pd[1], pd[3])); valid = (pd && ngxDate.check(pd[3], pd[2], pd[1]));


if (valid) { if (valid) {
date = new Date(pd[3], pd[2] - 1, pd[1]); date = new Date(pd[3], pd[2] - 1, pd[1]);
Expand Down

0 comments on commit e6c4f77

Please sign in to comment.