Implements the first specs
TDD yeah !!!
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"bootstrap": "^3.3.6"
|
"bootstrap": "^3.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"angular-mocks": "^1.5.0"
|
"angular-mocks": "^1.5.0",
|
||||||
|
"karma-read-json": "^1.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
gulpfile.js
10
gulpfile.js
@@ -3,9 +3,15 @@ var plugins = require('gulp-load-plugins')({});
|
|||||||
var karma = require('karma');
|
var karma = require('karma');
|
||||||
|
|
||||||
gulp.task('test', function(done) {
|
gulp.task('test', function(done) {
|
||||||
new karma.Server({
|
server = new karma.Server({
|
||||||
configFile: __dirname + '/test/karma.conf.js'
|
configFile: __dirname + '/test/karma.conf.js'
|
||||||
},done).start();
|
},function(exitCode) {
|
||||||
|
console.log('coucou');
|
||||||
|
done(exitCode);
|
||||||
|
console.log('coucou');
|
||||||
|
process.exit(exitCode);
|
||||||
|
});
|
||||||
|
server.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module.exports = function(config) {
|
|||||||
config.set({
|
config.set({
|
||||||
|
|
||||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||||
basePath: '',
|
basePath: '../',
|
||||||
|
|
||||||
|
|
||||||
// frameworks to use
|
// frameworks to use
|
||||||
@@ -15,9 +15,13 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
// list of files / patterns to load in the browser
|
// list of files / patterns to load in the browser
|
||||||
files: [
|
files: [
|
||||||
'../webapp/js/**/*.js',
|
'webapp/bower_components/angular/angular.js',
|
||||||
'../webapp/bower_components/angular*/**/*.js',
|
'webapp/bower_components/angular-mocks/angular-mocks.js',
|
||||||
'specs/**/*.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}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +61,11 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
// start these browsers
|
// start these browsers
|
||||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||||
browsers: ['Chrome', 'Safari', 'Firefox'],
|
browsers: [
|
||||||
|
'Chrome'
|
||||||
|
// 'Safari',
|
||||||
|
// 'Firefox'
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
// Continuous Integration mode
|
// Continuous Integration mode
|
||||||
|
|||||||
@@ -1,5 +1,63 @@
|
|||||||
describe('Service: albumService', function() {
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ var services = angular.module('satbd.satellite.bar.services',[])
|
|||||||
services.factory('albumService',['$http','$log','$q', function($http,$log,$q) {
|
services.factory('albumService',['$http','$log','$q', function($http,$log,$q) {
|
||||||
function cleanupFields(album) {
|
function cleanupFields(album) {
|
||||||
album.serie = album.série;
|
album.serie = album.série;
|
||||||
|
album.série = undefined;
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
function get(id) {
|
function get(id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user