diff --git a/bower.json b/bower.json index 8d1453e..18e2226 100644 --- a/bower.json +++ b/bower.json @@ -5,12 +5,13 @@ "dependencies": { "angular": "^1.5.0", "angular-route": "^1.5.0", - "angular-animate": "^1.5.0", - "angular-sanitize": "^1.5.0", + "angular-animate": "^1.5.0", + "angular-sanitize": "^1.5.0", "angular-bootstrap": "^1.1.2", "bootstrap": "^3.3.6" }, "devDependencies": { - "angular-mocks": "^1.5.0" + "angular-mocks": "^1.5.0", + "karma-read-json": "^1.1.0" } } diff --git a/gulpfile.js b/gulpfile.js index b6bc371..906312b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,9 +3,15 @@ var plugins = require('gulp-load-plugins')({}); var karma = require('karma'); gulp.task('test', function(done) { - new karma.Server({ + server = new karma.Server({ configFile: __dirname + '/test/karma.conf.js' - },done).start(); + },function(exitCode) { + console.log('coucou'); + done(exitCode); + console.log('coucou'); + process.exit(exitCode); + }); + server.start(); }); diff --git a/test/karma.conf.js b/test/karma.conf.js index 207124d..cc0055e 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -2,70 +2,78 @@ // Generated on Fri Feb 12 2016 12:00:28 GMT+0100 (CET) module.exports = function(config) { - config.set({ + config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '../', - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine'], + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], - // list of files / patterns to load in the browser - files: [ - '../webapp/js/**/*.js', - '../webapp/bower_components/angular*/**/*.js', - 'specs/**/*.js' - ], + // list of files / patterns to load in the browser + files: [ + 'webapp/bower_components/angular/angular.js', + 'webapp/bower_components/angular-mocks/angular-mocks.js', + 'webapp/bower_components/angular-route/angular-route.js', + 'webapp/bower_components/karma-read-json/karma-read-json.js', + 'webapp/js/**/*.js', + 'test/specs/**/*.js', + {pattern: 'test/data/*.json', watched: true, served:true, included: false} + ], - // list of files to exclude - exclude: [ - ], + // list of files to exclude + exclude: [ + ], - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - }, + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], - // web server port - port: 9876, + // web server port + port: 9876, - // enable / disable colors in the output (reporters and logs) - colors: true, + // enable / disable colors in the output (reporters and logs) + colors: true, - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, - // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['Chrome', 'Safari', 'Firefox'], + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [ + 'Chrome' +// 'Safari', +// 'Firefox' + ], - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - }) + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) } diff --git a/test/specs/album-service_test.js b/test/specs/album-service_test.js index b3749f6..b8f7ea1 100644 --- a/test/specs/album-service_test.js +++ b/test/specs/album-service_test.js @@ -1,5 +1,63 @@ describe('Service: albumService', function() { - + beforeEach(module('satbd.satellite.bar.services')); + + var $httpBackend,albumService; + + var albums = readJSON('test/data/albums.json') + var albumsByIDs = {}; + for ( var i = 0; i < albums.length; i++) { + albumsByIDs[albums[i].ID] = albums; + } + + beforeEach(inject(function($injector) { + $httpBackend = $injector.get('$httpBackend'); + for ( var i = 0; i < albums.length; i++) { + $httpBackend.when('GET','/api/albums/'+ albums[i].ID).respond(200,albums[i]); + } + $httpBackend.when('GET','/api/albums/1234').respond(404, 'Error not found'); + albumService = $injector.get('albumService'); + })); + + + + it('can get an album data', function() { + for ( var i = 0; i < albums.length; i++) { + var album, err; + albumService.get(albums[i].ID).then(function(data) { + album = data; + }).catch( function() { + err = 'Could not get album'; + }); + $httpBackend.flush(); + + expect(album.ID).toBe(albums[i].ID); + expect(err).toBe(undefined); + } + + var album = undefined , err = undefined; + albumService.get(1234).then(function(data) { + album = data; + }).catch( function() { + err = 'Could not get album'; + }); + $httpBackend.flush(); + + expect(album).toBe(undefined) + expect(err).toBe('Could not get album'); + }); + + it('renames non-utf-8 field to utf-8', function() { + for ( var i = 0; i < albums.length; i++) { + var album; + albumService.get(albums[i].ID) + .then(function(data) { + album = data; + }) + $httpBackend.flush(); + expect(album.serie).toBe(albums[i].série); + expect(album.série).toBe(undefined); + } + }); }); diff --git a/webapp/js/services.js b/webapp/js/services.js index bb9c8ee..88205c7 100644 --- a/webapp/js/services.js +++ b/webapp/js/services.js @@ -3,6 +3,7 @@ var services = angular.module('satbd.satellite.bar.services',[]) services.factory('albumService',['$http','$log','$q', function($http,$log,$q) { function cleanupFields(album) { album.serie = album.série; + album.série = undefined; return album; } function get(id) { @@ -16,7 +17,7 @@ services.factory('albumService',['$http','$log','$q', function($http,$log,$q) { defer.reject('Search is not implemented'); return defer.promise; } - + return { get: get, search: search