Implements the first specs

TDD yeah !!!
This commit is contained in:
2016-02-12 14:01:33 +01:00
parent 0dd8219c4a
commit a9ca878be1
5 changed files with 123 additions and 49 deletions

View File

@@ -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"
}
}

View File

@@ -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();
});

View File

@@ -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
})
}

View File

@@ -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);
}
});
});

View File

@@ -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