Skip to content

Commit

Permalink
New unit tests for characters service.
Browse files Browse the repository at this point in the history
New way to define expected xhr responses.
Repaired phantomjs installation.
Added chrome launcher to ease debugging.
Removed unused cordova plugins.
  • Loading branch information
jeandat committed Feb 8, 2016
1 parent b54bb8f commit 00a9a80
Show file tree
Hide file tree
Showing 11 changed files with 6,196 additions and 116 deletions.
6 changes: 4 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"ionic": false,
"H": false,
"defaultTranslations": true,
"md5": false
"md5": false,
"readJSON": false,
"fixturesPath": true
}
}
}
53 changes: 53 additions & 0 deletions app/characters/characters.factory.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('charactersService: ', function () {

var charactersService, $httpBackend;

beforeEach(module('app'));

beforeEach(inject(function ($injector) {
charactersService = $injector.get('charactersService');
$httpBackend = $injector.get('$httpBackend');
}));

afterEach(function() {
$httpBackend.verifyNoOutstandingRequest();
});

it('should have 4 results', function (done) {
var fixture = readJSON(fixturesPath + '/characters/Deadpool.json');
$httpBackend.expectGET(/\/characters/).respond(fixture);
charactersService.findByName('Deadpool').then(function (results) {
expect(results).toBeTruthy();
expect(results.length).toBe(4);
done();
});
$httpBackend.flush();
});

it('should have multiple pages', function (done) {
var fixture1 = readJSON(fixturesPath + '/characters/s_0.json');
var fixture2 = readJSON(fixturesPath + '/characters/s_20.json');
$httpBackend.expectGET(/\/characters/).respond(fixture1);
$httpBackend.expectGET(/\/characters/).respond(fixture2);
var prefix = 'sp';
var offset = 0;
var list = [];
charactersService.findByName(prefix).then(function (results) {
expect(results).toBeTruthy();
expect(results.length).toBe(20);
list = list.concat(results);
}).then(function () {
offset = 20;
return charactersService.findByName(prefix, offset);
}).then(function (results) {
expect(results).toBeTruthy();
expect(results.length).toBe(13);
expect(list[0].id).not.toBe(results[0].id);
list = list.concat(results);
expect(list.length).toBe(33);
done();
});
$httpBackend.flush();
});

});
30 changes: 0 additions & 30 deletions app/comics/comics.factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,4 @@ describe('comicsService: ', function () {
comicsService = _comicsService_;
}));

it('should have a Ben Sparrow item', function () {
var comics = comicsService.all();
var ben = _.find(comics, {name:'Ben Sparrow'});
expect(ben).toBeTruthy();
expect(ben.id).toBe(0);
});

it('should have one less comic', function(){
var comics = comicsService.all();
expect(comics.length).toBe(5);
var ben = _.find(comics, {name:'Ben Sparrow'});
comicsService.remove(ben);
comics = comicsService.all();
expect(comics.length).toBe(4);
ben = _.find(comics, {name:'Ben Sparrow'});
expect(ben).toBeUndefined();
});

it('should find ben', function(){
var max = comicsService.get('1');
expect(max).toBeTruthy();
expect(max.id).toBe(1);

var nil = comicsService.get('10');
expect(nil).toBeNull();

nil = comicsService.get('-1');
expect(nil).toBeNull();
});

});
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"ngCordova": "~0.1.24-alpha",
"angular-local-storage": "~0.2.3",
"jquery": "~2.2.0",
"angular-cache": "~4.5.0"
"angular-cache": "~4.5.0",
"karma-read-json": "^1.1.0"
},
"resolutions": {
"angular": "~1.4.9"
Expand Down
5 changes: 2 additions & 3 deletions grunt/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module.exports.tasks = {
// Unit tests
karma: {
options: {
configFile: 'test/karma.conf.js',
browsers: ['PhantomJS']
configFile: 'test/karma.conf.js'
},
dev: {
singleRun: true
Expand All @@ -33,4 +32,4 @@ module.exports.tasks = {
tasks: ['newer:replace', 'newer:jshint:dev']
}
}
};
};
156 changes: 78 additions & 78 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
{
"name": "learning-ionic",
"version": "0.3.0",
"description": "Project to learn ionic of course",
"devDependencies": {
"autoprefixer": "^6.3.1",
"bower": "^1.7.7",
"grunt": "^0.4.5",
"grunt-bump": "^0.7.0",
"grunt-chokidar": "^1.0.0",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jade": "^0.15.0",
"grunt-contrib-jshint": "^0.12.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-groc": "^0.6.0",
"grunt-html2js": "^0.3.5",
"grunt-jscs": "^2.6.0",
"grunt-karma": "^0.12.1",
"grunt-newer": "^1.1.1",
"grunt-ng-annotate": "^1.0.1",
"grunt-parallel": "^0.4.1",
"grunt-plato": "^1.2.1",
"grunt-postcss": "^0.7.1",
"grunt-replace": "^0.11.0",
"grunt-sass": "^1.1.0",
"grunt-sass-compile-imports": "^0.2.1",
"grunt-shell": "^1.1.2",
"jasmine-core": "^2.4.1",
"jit-grunt": "^0.9.1",
"js-yaml": "^3.5.2",
"jscs-stylish": "^0.3.1",
"jshint-stylish": "^2.1.0",
"karma": "^0.13.19",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.6",
"karma-junit-reporter": "^0.3.8",
"karma-phantomjs-launcher": "^1.0.0",
"load-grunt-configs": "^0.4.3",
"lodash": "^4.0.1",
"node.extend": "^1.1.5",
"phantomjs": "^2.1.3",
"shelljs": "^0.5.3",
"time-grunt": "^1.3.0"
},
"cordovaPlugins": [
"cordova-plugin-console",
"cordova-plugin-crosswalk-webview",
"cordova-plugin-device",
"cordova-plugin-dialogs",
"cordova-plugin-google-analytics",
"cordova-plugin-statusbar",
"cordova-plugin-whitelist",
"ionic-plugin-keyboard",
"cordova-plugin-splashscreen",
{
"locator": "https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git",
"id": "cordova-plugin-x-toast"
},
"cordova-plugin-network-information"
],
"cordovaPlatforms": [
"android",
"ios"
],
"scripts": {
"prestart": "npm install",
"postinstall": "bower install",
"start": "npm run serve",
"serve": "grunt dev --mock true --proxy true && grunt serve --mock true --proxy true",
"android": "grunt dev && ionic run android",
"android-lr": "grunt dev --proxy true && grunt run:android -l --proxy true",
"ios": "grunt dev && ionic run ios",
"ios-lr": "grunt dev --proxy true && grunt run:ios -l --proxy true",
"test": "grunt dev --mock true && grunt karma:dev",
"wtest": "grunt dev --mock true && grunt parallel:wtest --mock true",
"doc": "grunt clean:doc groc plato",
"build": "grunt dev && ionic build"
"name": "learning-ionic",
"version": "0.3.0",
"description": "Project to learn ionic of course",
"devDependencies": {
"autoprefixer": "^6.3.1",
"bower": "^1.7.7",
"grunt": "^0.4.5",
"grunt-bump": "^0.7.0",
"grunt-chokidar": "^1.0.0",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jade": "^0.15.0",
"grunt-contrib-jshint": "^0.12.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-groc": "^0.6.0",
"grunt-html2js": "^0.3.5",
"grunt-jscs": "^2.6.0",
"grunt-karma": "^0.12.1",
"grunt-newer": "^1.1.1",
"grunt-ng-annotate": "^1.0.1",
"grunt-parallel": "^0.4.1",
"grunt-plato": "^1.2.1",
"grunt-postcss": "^0.7.1",
"grunt-replace": "^0.11.0",
"grunt-sass": "^1.1.0",
"grunt-sass-compile-imports": "^0.2.1",
"grunt-shell": "^1.1.2",
"jasmine-core": "^2.4.1",
"jit-grunt": "^0.9.1",
"js-yaml": "^3.5.2",
"jscs-stylish": "^0.3.1",
"jshint-stylish": "^2.1.0",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.6",
"karma-junit-reporter": "^0.3.8",
"karma-phantomjs-launcher": "^1.0.0",
"load-grunt-configs": "^0.4.3",
"lodash": "^4.0.1",
"node.extend": "^1.1.5",
"phantomjs": "^2.1.3",
"phantomjs-prebuilt": "^2.1.4",
"shelljs": "^0.5.3",
"time-grunt": "^1.3.0"
},
"cordovaPlugins": [
"cordova-plugin-console",
"cordova-plugin-crosswalk-webview",
"cordova-plugin-device",
"cordova-plugin-google-analytics",
"cordova-plugin-statusbar",
"cordova-plugin-whitelist",
"ionic-plugin-keyboard",
"cordova-plugin-splashscreen",
{
"locator": "https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git",
"id": "cordova-plugin-x-toast"
}
],
"cordovaPlatforms": [
"android",
"ios"
],
"scripts": {
"prestart": "npm install",
"postinstall": "bower install",
"start": "npm run serve",
"serve": "grunt dev --mock true --proxy true && grunt serve --mock true --proxy true",
"android": "grunt dev && ionic run android",
"android-lr": "grunt dev --proxy true && grunt run:android -l --proxy true",
"ios": "grunt dev && ionic run ios",
"ios-lr": "grunt dev --proxy true && grunt run:ios -l --proxy true",
"test": "grunt dev --mock true && grunt karma:dev",
"wtest": "grunt dev --mock true && grunt parallel:wtest --mock true",
"doc": "grunt clean:doc groc plato",
"build": "grunt dev && ionic build"
}
}
9 changes: 7 additions & 2 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function (config) {
'www/js/angular-ui-router.js',
'www/js/ionic-angular.js',
'www/js/lodash.js',
'vendor/karma-read-json/karma-read-json.js',
'vendor/angular-mocks/angular-mocks.js',
'www/js/ng-cordova-mocks.js',
'www/js/angular-local-storage.js',
Expand All @@ -24,7 +25,10 @@ module.exports = function (config) {
'www/js/templates.js',
'.tmp/**/*.module.js',
'.tmp/**/!(*.spec).js',
'bower_components/angular-markdown-directive/markdown.js',
// globals for tests
'test/unit/global.js',
// fixtures used in tests
{pattern: 'test/unit/fixtures/**/*.json', included: false},
// specs from `app/` and `test/unit/`
'.tmp/**/*.spec.js',
'test/unit/**/*.spec.js'],
Expand All @@ -46,6 +50,7 @@ module.exports = function (config) {
outputFile: 'TESTS-xunit.xml',
useBrowserName: false
},
//browsers: ['Chrome'],
browsers: ['PhantomJS'],
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
Expand All @@ -54,4 +59,4 @@ module.exports = function (config) {
};

config.set(configuration);
};
};
Loading

0 comments on commit 00a9a80

Please sign in to comment.