Skip to content

Commit 75186f2

Browse files
author
DAT Jean OAB
committed
angular team guidelines.
one spec file. karma configuration. watch configuration with ionic support.
1 parent f78674f commit 75186f2

File tree

12 files changed

+124
-60
lines changed

12 files changed

+124
-60
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"module": false,
3232
"spyOn": false,
3333
"cordova": false,
34-
"StatusBar": false
34+
"StatusBar": false,
35+
"_": false
3536
}
3637
}

app/app.constant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
.module('app')
66
// App version from package.json
77
.constant('version', '@@version')
8-
.constant('stringify', stringify);
8+
.constant('stringify', stringify)
9+
.constant('_', _);
910

1011
// Same as `JSON.stringify` but with indentation.
1112
function stringify(value) {

app/chats/chat-detail.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
//$scope.$on('$ionicView.enter', function(e) {
1515
//});
1616

17-
function ChatDetailController($stateParams, Chats) {
17+
function ChatDetailController($stateParams, chatsService) {
1818

1919
var vm = this;
20-
vm.chat = Chats.get($stateParams.chatId);
20+
vm.chat = chatsService.get($stateParams.chatId);
2121

2222
}
2323

app/chats/chats.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
//$scope.$on('$ionicView.enter', function(e) {
1515
//});
1616

17-
function ChatsController(Chats) {
17+
function ChatsController(chatsService) {
1818

1919
var vm = this;
20-
vm.chats = Chats.all();
20+
vm.chats = chatsService.all();
2121
vm.remove = remove;
2222

2323
////////////////
2424

2525
function remove(chat) {
26-
Chats.remove(chat);
26+
chatsService.remove(chat);
2727
}
2828

2929
}

app/chats/chats.factory.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
angular
55
.module('app')
6-
.factory('Chats', Chats);
6+
.factory('chatsService', chatsService);
77

8-
function Chats() {
9-
10-
// Some fake testing data
11-
var chats = fakeData();
8+
function chatsService() {
129

1310
var service = {
1411
all: all,
@@ -20,35 +17,6 @@
2017

2118
////////////////
2219

23-
function fakeData(){
24-
return [{
25-
id: 0,
26-
name: 'Ben Sparrow',
27-
lastText: 'You on your way?',
28-
face: 'img/ben.png'
29-
}, {
30-
id: 1,
31-
name: 'Max Lynx',
32-
lastText: 'Hey, it\'s me',
33-
face: 'img/max.png'
34-
}, {
35-
id: 2,
36-
name: 'Adam Bradleyson',
37-
lastText: 'I should buy a boat',
38-
face: 'img/adam.jpg'
39-
}, {
40-
id: 3,
41-
name: 'Perry Governor',
42-
lastText: 'Look at my mukluks!',
43-
face: 'img/perry.png'
44-
}, {
45-
id: 4,
46-
name: 'Mike Harrington',
47-
lastText: 'This is wicked good ice cream.',
48-
face: 'img/mike.png'
49-
}];
50-
}
51-
5220
function all(){
5321
return chats;
5422
}
@@ -68,5 +36,37 @@
6836

6937
}
7038

39+
// Some fake testing data
40+
var chats = fakeData();
41+
42+
function fakeData(){
43+
return [{
44+
id: 0,
45+
name: 'Ben Sparrow',
46+
lastText: 'You on your way?',
47+
face: 'img/ben.png'
48+
}, {
49+
id: 1,
50+
name: 'Max Lynx',
51+
lastText: 'Hey, it\'s me',
52+
face: 'img/max.png'
53+
}, {
54+
id: 2,
55+
name: 'Adam Bradleyson',
56+
lastText: 'I should buy a boat',
57+
face: 'img/adam.jpg'
58+
}, {
59+
id: 3,
60+
name: 'Perry Governor',
61+
lastText: 'Look at my mukluks!',
62+
face: 'img/perry.png'
63+
}, {
64+
id: 4,
65+
name: 'Mike Harrington',
66+
lastText: 'This is wicked good ice cream.',
67+
face: 'img/mike.png'
68+
}];
69+
}
70+
7171
})();
7272

app/chats/chats.factory.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
describe('chatsService: ', function () {
2+
3+
var chatsService;
4+
5+
beforeEach(module('app'));
6+
7+
beforeEach(inject(function (_chatsService_) {
8+
chatsService = _chatsService_;
9+
}));
10+
11+
it('should have a Ben Sparrow item', function () {
12+
var chats = chatsService.all();
13+
var ben = _.find(chats, {name:'Ben Sparrow'});
14+
expect(ben).toBeTruthy();
15+
expect(ben.id).toBe(0);
16+
});
17+
18+
it('should have one less chat', function(){
19+
var chats = chatsService.all();
20+
expect(chats.length).toBe(5);
21+
var ben = _.find(chats, {name:'Ben Sparrow'});
22+
chatsService.remove(ben);
23+
chats = chatsService.all();
24+
expect(chats.length).toBe(4);
25+
ben = _.find(chats, {name:'Ben Sparrow'});
26+
expect(ben).toBeUndefined();
27+
});
28+
29+
it('should find ben', function(){
30+
var max = chatsService.get('1');
31+
expect(max).toBeTruthy();
32+
expect(max.id).toBe(1);
33+
34+
var nil = chatsService.get('10');
35+
expect(nil).toBeNull();
36+
37+
nil = chatsService.get('-1');
38+
expect(nil).toBeNull();
39+
});
40+
41+
});

bower.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"devDependencies": {
66
"ionic": "driftyco/ionic-bower#1.1.1",
77
"platform.js": "platform#~1.3.0"
8+
},
9+
"dependencies": {
10+
"lodash": "~3.10.1",
11+
"angular-mocks": "~1.4.8"
812
}
913
}

grunt/script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = function () {
1010
files: [{
1111
dest: '<%= pub %>/js',
1212
src: [
13-
'ionic/js/ionic.bundle.js'
13+
'ionic/js/ionic.bundle.js',
14+
'lodash/lodash.js'
1415
],
1516
expand: true,
1617
cwd: 'vendor',

grunt/serve.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ module.exports = function (grunt) {
1818
grunt: true,
1919
args: ['shell:serve']
2020
}]
21-
},
22-
// Launch a karma server in watch mode and a watch server for source files.
23-
wtest: {
24-
options: {
25-
stream: true,
26-
grunt: true
27-
},
28-
tasks: ['karma:wdev', 'chokidar']
2921
}
3022
},
3123

grunt/test.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,32 @@ module.exports.tasks = {
55
// Unit tests
66
karma: {
77
options: {
8-
configFile: 'test/karma.conf.js'
8+
configFile: 'test/karma.conf.js',
9+
browsers: ['PhantomJS']
910
},
1011
dev: {
11-
browsers: ['Chrome']
12+
singleRun: true
1213
},
13-
'wdev': {
14-
browsers: ['Chrome'],
14+
wdev: {
1515
singleRun: false
1616
}
17+
},
18+
19+
parallel: {
20+
// Launch a karma server in watch mode and a watch server for source files.
21+
wtest: {
22+
options: {
23+
stream: true,
24+
grunt: true
25+
},
26+
tasks: ['karma:wdev', 'chokidar']
27+
}
28+
},
29+
30+
chokidar:{
31+
jsSpecs: {
32+
files: ['<%= src %>/**/*.spec.js', 'test/unit/**/*.spec.js'],
33+
tasks: ['newer:jshint:dev', 'newer:replace']
34+
}
1735
}
1836
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
"jscs-stylish": "^0.3.1",
3333
"jshint-stylish": "^2.0.1",
3434
"karma": "^0.13.14",
35-
"karma-chrome-launcher": "^0.2.1",
3635
"karma-coverage": "^0.5.3",
37-
"karma-firefox-launcher": "^0.1.4",
3836
"karma-jasmine": "^0.3.5",
3937
"karma-junit-reporter": "^0.3.8",
38+
"karma-phantomjs-launcher": "^0.2.1",
4039
"load-grunt-configs": "^0.4.3",
4140
"lodash": "^3.10.1",
4241
"node.extend": "^1.1.3",
42+
"phantomjs": "^1.9.19",
4343
"shelljs": "^0.3.0",
4444
"time-grunt": "^1.2.2"
4545
},

test/karma.conf.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,33 @@ module.exports = function (config) {
77
files: [
88
// vendors
99
'www/js/ionic.bundle.js',
10+
'www/js/lodash.js',
11+
'vendor/angular-mocks/angular-mocks.js',
1012
// app
1113
'www/js/templates.js',
1214
'www/js/app.js',
13-
// specs from `app/` and `test/unit/`
15+
// specs
1416
'.tmp/**/*.spec.js',
1517
'test/unit/**/*.spec.js'],
1618
singleRun: true,
1719
logLevel: 'INFO',
1820
frameworks: ['jasmine'],
1921
reporters: ['progress', 'coverage', 'junit'],
2022
preprocessors: {
21-
'build/gen/js/**/*.js': ['coverage']
23+
'.tmp/**/!(*spec).js': ['coverage']
2224
},
2325
coverageReporter: {
24-
type: 'html',
26+
type: 'lcov',
2527
dir: 'doc/test/coverage'
2628
},
2729
junitReporter: {
2830
outputDir: 'doc/test/junit/'
2931
},
30-
browsers: ['Chrome']
32+
browsers: ['PhantomJS'],
33+
phantomjsLauncher: {
34+
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
35+
exitOnResourceError: true
36+
}
3137
};
3238

3339
config.set(configuration);

0 commit comments

Comments
 (0)