Permalink
Browse files

Revert "Revert "Merge branch 'refs/heads/unit-tests'""

This reverts commit 251bc77.
  • Loading branch information...
1 parent 9ead18c commit e6c4f77274fde5abd066c48bf27f91e3376da1bf zamrzlaj committed Nov 2, 2012
View
@@ -2,6 +2,7 @@ module.exports = function(grunt) {
// tasks
grunt.loadTasks('build/tasks');
grunt.loadNpmTasks('grunt-recess');
+ grunt.loadNpmTasks('grunt-testacular');
// configuration
grunt.initConfig({
@@ -16,7 +17,7 @@ module.exports = function(grunt) {
},
concat: {
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'
}
},
@@ -58,8 +59,8 @@ module.exports = function(grunt) {
},
watch: {
scripts: {
- files: ['grunt.js', 'src/*.js', 'src/**/*.js'],
- tasks: 'lint concat min'
+ files: ['grunt.js', 'src/*.js', 'src/**/*.js', 'test/**/*.js'],
+ tasks: 'lint concat min testacularRun'
},
styles: {
files: ['src/**/*.less'],
@@ -69,10 +70,19 @@ module.exports = function(grunt) {
files: ['src/modules/**/*.html'],
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('devel', 'testacularServer watch');
};
View
@@ -2,23 +2,21 @@
"author": "https://github.com/lmc-eu",
"name": "ngx-library",
"description": "NGX - extension library for AngularJS",
- "version": "0.0.1",
+ "version": "0.0.2",
"homepage": "http://github.com/lmc-eu/ngx-library",
"repository": {
"type": "git",
"url": "git://github.com/lmc-eu/ngx-library.git"
},
"engines": {
- "node": ">= 0.6.11"
+ "node": ">=0.8.0"
},
"dependencies": {
- "grunt": ">= 0.3.12",
+ "rimraf": ">=2.0.2",
+ "testacular": ">=0.4.0",
+ "grunt": ">=0.3.12",
"grunt-recess": ">=0.1.0",
- "rimraf": ">=2.0.2"
- },
- "devDependencies": {
- "grunt-recess": ">=0.1.0",
- "rimraf": ">=2.0.2"
+ "grunt-testacular": ">=0.2.0"
},
"scripts" : {
"test": "grunt"
View
@@ -247,12 +247,12 @@
/**
* Date validator (from phpjs.org)
- * @param m
- * @param d
- * @param y
+ * @param year
+ * @param month
+ * @param day
* @return {Boolean}
*/
- ngxDate.check = function(m, d, y) {
+ ngxDate.check = function(year, month, day) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Pyerre
@@ -265,7 +265,7 @@
// * returns 3: true
// * example 4: checkdate(1, 390, 2000);
// * 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', [])
@@ -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();
+ }));
+});
@@ -12,6 +12,7 @@
/**
* Returns items by current language
+ * @param key
* @param language
*/
function ngxDictionary(key, language) {
@@ -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);
+ }));
+
+});
@@ -24,7 +24,7 @@
* Loads external js/css files
* @param files
*/
- return function(files, onload) {
+ var ngxLoader = function(files, onload) {
var js = [],
css = [];
@@ -46,6 +46,8 @@
} else {
throw new Error('File type not supported');
}
+
+ loaded.push(file);
});
if (js.length) {
@@ -61,5 +63,15 @@
});
}
};
+
+ /**
+ * Returns loaded files
+ * @return {Array}
+ */
+ ngxLoader.getLoaded = function() {
+ return loaded;
+ };
+
+ return ngxLoader;
}]);
})(window.angular, window.head);
@@ -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');
+ }));
+
+});
@@ -60,7 +60,7 @@
if (viewValue && ctrl.$dirty) {
// parse and check date
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) {
date = new Date(pd[3], pd[2] - 1, pd[1]);
Oops, something went wrong.

0 comments on commit e6c4f77

Please sign in to comment.