Implements the first specs
TDD yeah !!!
This commit is contained in:
@@ -5,12 +5,13 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"angular": "^1.5.0",
|
"angular": "^1.5.0",
|
||||||
"angular-route": "^1.5.0",
|
"angular-route": "^1.5.0",
|
||||||
"angular-animate": "^1.5.0",
|
"angular-animate": "^1.5.0",
|
||||||
"angular-sanitize": "^1.5.0",
|
"angular-sanitize": "^1.5.0",
|
||||||
"angular-bootstrap": "^1.1.2",
|
"angular-bootstrap": "^1.1.2",
|
||||||
"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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,70 +2,78 @@
|
|||||||
// Generated on Fri Feb 12 2016 12:00:28 GMT+0100 (CET)
|
// Generated on Fri Feb 12 2016 12:00:28 GMT+0100 (CET)
|
||||||
|
|
||||||
module.exports = function(config) {
|
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
|
||||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
frameworks: ['jasmine'],
|
frameworks: ['jasmine'],
|
||||||
|
|
||||||
|
|
||||||
// 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}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
// list of files to exclude
|
// list of files to exclude
|
||||||
exclude: [
|
exclude: [
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
// preprocess matching files before serving them to the browser
|
// preprocess matching files before serving them to the browser
|
||||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// test results reporter to use
|
// test results reporter to use
|
||||||
// possible values: 'dots', 'progress'
|
// possible values: 'dots', 'progress'
|
||||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||||
reporters: ['progress'],
|
reporters: ['progress'],
|
||||||
|
|
||||||
|
|
||||||
// web server port
|
// web server port
|
||||||
port: 9876,
|
port: 9876,
|
||||||
|
|
||||||
|
|
||||||
// enable / disable colors in the output (reporters and logs)
|
// enable / disable colors in the output (reporters and logs)
|
||||||
colors: true,
|
colors: true,
|
||||||
|
|
||||||
|
|
||||||
// level of logging
|
// level of logging
|
||||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||||
logLevel: config.LOG_INFO,
|
logLevel: config.LOG_INFO,
|
||||||
|
|
||||||
|
|
||||||
// enable / disable watching file and executing tests whenever any file changes
|
// enable / disable watching file and executing tests whenever any file changes
|
||||||
autoWatch: true,
|
autoWatch: true,
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
// if true, Karma captures browsers, runs the tests and exits
|
// if true, Karma captures browsers, runs the tests and exits
|
||||||
singleRun: false,
|
singleRun: false,
|
||||||
|
|
||||||
// Concurrency level
|
// Concurrency level
|
||||||
// how many browser should be started simultaneous
|
// how many browser should be started simultaneous
|
||||||
concurrency: Infinity
|
concurrency: Infinity
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -16,7 +17,7 @@ services.factory('albumService',['$http','$log','$q', function($http,$log,$q) {
|
|||||||
defer.reject('Search is not implemented');
|
defer.reject('Search is not implemented');
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get: get,
|
get: get,
|
||||||
search: search
|
search: search
|
||||||
|
|||||||
Reference in New Issue
Block a user