Skip to content

Commit

Permalink
angular team guidelines.
Browse files Browse the repository at this point in the history
one spec file.
karma configuration.
watch configuration with ionic support.
  • Loading branch information
DAT Jean OAB committed Nov 27, 2015
1 parent f78674f commit 75186f2
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"module": false,
"spyOn": false,
"cordova": false,
"StatusBar": false
"StatusBar": false,
"_": false
}
}
3 changes: 2 additions & 1 deletion app/app.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
.module('app')
// App version from package.json
.constant('version', '@@version')
.constant('stringify', stringify);
.constant('stringify', stringify)
.constant('_', _);

// Same as `JSON.stringify` but with indentation.
function stringify(value) {
Expand Down
4 changes: 2 additions & 2 deletions app/chats/chat-detail.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
//$scope.$on('$ionicView.enter', function(e) {
//});

function ChatDetailController($stateParams, Chats) {
function ChatDetailController($stateParams, chatsService) {

var vm = this;
vm.chat = Chats.get($stateParams.chatId);
vm.chat = chatsService.get($stateParams.chatId);

}

Expand Down
6 changes: 3 additions & 3 deletions app/chats/chats.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
//$scope.$on('$ionicView.enter', function(e) {
//});

function ChatsController(Chats) {
function ChatsController(chatsService) {

var vm = this;
vm.chats = Chats.all();
vm.chats = chatsService.all();
vm.remove = remove;

////////////////

function remove(chat) {
Chats.remove(chat);
chatsService.remove(chat);
}

}
Expand Down
68 changes: 34 additions & 34 deletions app/chats/chats.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

angular
.module('app')
.factory('Chats', Chats);
.factory('chatsService', chatsService);

function Chats() {

// Some fake testing data
var chats = fakeData();
function chatsService() {

var service = {
all: all,
Expand All @@ -20,35 +17,6 @@

////////////////

function fakeData(){
return [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];
}

function all(){
return chats;
}
Expand All @@ -68,5 +36,37 @@

}

// Some fake testing data
var chats = fakeData();

function fakeData(){
return [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];
}

})();

41 changes: 41 additions & 0 deletions app/chats/chats.factory.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('chatsService: ', function () {

var chatsService;

beforeEach(module('app'));

beforeEach(inject(function (_chatsService_) {
chatsService = _chatsService_;
}));

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

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

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

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

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

});
4 changes: 4 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.1.1",
"platform.js": "platform#~1.3.0"
},
"dependencies": {
"lodash": "~3.10.1",
"angular-mocks": "~1.4.8"
}
}
3 changes: 2 additions & 1 deletion grunt/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = function () {
files: [{
dest: '<%= pub %>/js',
src: [
'ionic/js/ionic.bundle.js'
'ionic/js/ionic.bundle.js',
'lodash/lodash.js'
],
expand: true,
cwd: 'vendor',
Expand Down
8 changes: 0 additions & 8 deletions grunt/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ module.exports = function (grunt) {
grunt: true,
args: ['shell:serve']
}]
},
// Launch a karma server in watch mode and a watch server for source files.
wtest: {
options: {
stream: true,
grunt: true
},
tasks: ['karma:wdev', 'chokidar']
}
},

Expand Down
26 changes: 22 additions & 4 deletions grunt/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@ module.exports.tasks = {
// Unit tests
karma: {
options: {
configFile: 'test/karma.conf.js'
configFile: 'test/karma.conf.js',
browsers: ['PhantomJS']
},
dev: {
browsers: ['Chrome']
singleRun: true
},
'wdev': {
browsers: ['Chrome'],
wdev: {
singleRun: false
}
},

parallel: {
// Launch a karma server in watch mode and a watch server for source files.
wtest: {
options: {
stream: true,
grunt: true
},
tasks: ['karma:wdev', 'chokidar']
}
},

chokidar:{
jsSpecs: {
files: ['<%= src %>/**/*.spec.js', 'test/unit/**/*.spec.js'],
tasks: ['newer:jshint:dev', 'newer:replace']
}
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"jscs-stylish": "^0.3.1",
"jshint-stylish": "^2.0.1",
"karma": "^0.13.14",
"karma-chrome-launcher": "^0.2.1",
"karma-coverage": "^0.5.3",
"karma-firefox-launcher": "^0.1.4",
"karma-jasmine": "^0.3.5",
"karma-junit-reporter": "^0.3.8",
"karma-phantomjs-launcher": "^0.2.1",
"load-grunt-configs": "^0.4.3",
"lodash": "^3.10.1",
"node.extend": "^1.1.3",
"phantomjs": "^1.9.19",
"shelljs": "^0.3.0",
"time-grunt": "^1.2.2"
},
Expand Down
14 changes: 10 additions & 4 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ module.exports = function (config) {
files: [
// vendors
'www/js/ionic.bundle.js',
'www/js/lodash.js',
'vendor/angular-mocks/angular-mocks.js',
// app
'www/js/templates.js',
'www/js/app.js',
// specs from `app/` and `test/unit/`
// specs
'.tmp/**/*.spec.js',
'test/unit/**/*.spec.js'],
singleRun: true,
logLevel: 'INFO',
frameworks: ['jasmine'],
reporters: ['progress', 'coverage', 'junit'],
preprocessors: {
'build/gen/js/**/*.js': ['coverage']
'.tmp/**/!(*spec).js': ['coverage']
},
coverageReporter: {
type: 'html',
type: 'lcov',
dir: 'doc/test/coverage'
},
junitReporter: {
outputDir: 'doc/test/junit/'
},
browsers: ['Chrome']
browsers: ['PhantomJS'],
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
exitOnResourceError: true
}
};

config.set(configuration);
Expand Down

0 comments on commit 75186f2

Please sign in to comment.