diff --git a/.bowerrc b/.bowerrc
new file mode 100644
index 0000000..ba0accc
--- /dev/null
+++ b/.bowerrc
@@ -0,0 +1,3 @@
+{
+ "directory": "app/bower_components"
+}
diff --git a/.gitignore b/.gitignore
index c677dbc..83ee456 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
-bower_components
-node_modules
-target
+bower_components/
+node_modules/
+target/
#IDEs
#IntelliJ Idea
-.idea
+.idea/
*.iml
diff --git a/.jshintrc b/.jshintrc
index 6562015..19c0933 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -19,6 +19,14 @@
"trailing": true,
"smarttabs": true,
"globals": {
- "angular": true
+ "angular": true,
+ "describe": true,
+ "it": true,
+ "expect": true,
+ "module": true,
+ "inject": true,
+ "beforeEach": true,
+ "jasmine": true,
+ "successfulPromise": true
}
}
diff --git a/Gruntfile.js b/Gruntfile.js
index 72ff9a5..2ce0368 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,54 +1,93 @@
/*jshint camelcase:false*/
-'use strict';
-
-// # Globbing
-// for performance reasons we're only matching one level down:
-// 'test/spec/{,*/}*.js'
-// use this if you want to recursively match all subfolders:
-// 'test/spec/**/*.js'
module.exports = function (grunt)
{
+ 'use strict';
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-karma');
+ require('load-grunt-tasks')(grunt);
+
+
var config = {
app: 'app'
};
grunt.initConfig({
- config: config, watch: {
- livereload: {
- options: {
- livereload: '<%= connect.options.livereload %>'
- }, files: ['<%= config.app %>/**/*.html', '<%= config.app %>/**/*.js']
- }
- }, connect: {
- options: {
- port: 9000, livereload: 35729, hostname: 'localhost'
- }, livereload: {
- options: {
- open: true, middleware: function (connect)
- {
- return [connect().use('/bower_components', connect.static('./bower_components')), connect.static(config.app)
-
- ];
+ config: config,
+ watch: {
+ livereload: {
+ options: {
+ livereload: '<%= connect.options.livereload %>'
+ },
+ files: ['<%= config.app %>/**/*.html', '<%= config.app %>/**/*.js']
+ }
+ },
+
+ connect: {
+ options: {
+ port: 9000,
+ livereload: 35729,
+ hostname: '127.0.0.1'
+ },
+ test: {
+ options: {
+ base: ['app'],
+ port: 9001
+ }
+ },
+ livereload: {
+ options: {
+ open: true,
+ middleware: function (connect)
+ {
+ return [connect().use('/bower_components', connect.static('./bower_components')), connect.static(config.app)
+
+ ];
+ }
+ }
+ }
+ },
+ karma: {
+ options: {
+ configFile: 'test/karma.conf.js'
+ },
+ unit: {
+ singleRun: true
+ },
+ dev: {
+ singleRun: false
+ }
+ },
+ jshint: {
+ default: {
+ options: {
+ jshintrc: true
+ },
+ files: {
+ src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']
+ }
+ },
+ verify: {
+ options: {
+ jshintrc: true,
+ reporter: 'checkstyle',
+ reporterOutput: 'target/jshint.xml'
+ },
+ files: {src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']}
}
}
}
- }, karma: {
- unit: {
- configFile: 'test/karma.conf.js'
- }
- }
- });
+ );
+
+ grunt.registerTask('serve', ['connect:livereload', 'watch']);
+
+ grunt.registerTask('verify', ['jshint:verify', 'karma:unit']);
- grunt.registerTask('serve', function ()
- {
- grunt.task.run(['connect:livereload', 'watch']);
- });
+ grunt.registerTask('test:dev', ['karma:dev']);
grunt.registerTask('default', ['serve']);
};
diff --git a/README.md b/README.md
index b498e93..88df9e9 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-#Excersie 2: Bind Posts From DAO
+# Excersie 2: Bind Posts From DAO
-##Introduction
+## Introduction
This lesson is about following skills:
* dependency injection
@@ -13,19 +13,19 @@ Expected result of this exercise is an application which allows user to display
| 1 | Jack | Diving Deep with Dependency Injection |
| 2 | Jill | Practical End-to-End Testing with Protractor |
-##Before you start, read about...
+## Before you start, read about...
* AngularJS promises: [https://egghead.io/lessons/angularjs-promises ](https://egghead.io/lessons/angularjs-promises)
* $resource: [https://docs.angularjs.org/api/ngResource/service/$resource](https://docs.angularjs.org/api/ngResource/service/$resource)
-##The exercise
+## The exercise
In order to complete this exercise you will need to follow these steps:
* use `query()` function form `PostDAO.js` in `BlogPostCtrl.js` to retrieve data
* display the table
-##Setup
+## Setup
You should have installed `npm`, `bower`, `grunt` packages to run this example. First, run sequentially
```
diff --git a/app/BlogPostCtrl.js b/app/BlogPostCtrl.js
deleted file mode 100644
index f8168ba..0000000
--- a/app/BlogPostCtrl.js
+++ /dev/null
@@ -1,11 +0,0 @@
-(function ()
-{
- 'use strict';
- function BlogPostCtrl(PostDAO)
- {
-
- }
-
- var module = angular.module('exerciseApp');
- module.controller('BlogPostCtrl', ['PostDAO', BlogPostCtrl]);
-})();
diff --git a/app/DAO/PostDAO.js b/app/DAO/PostDAO.js
new file mode 100644
index 0000000..a86acf0
--- /dev/null
+++ b/app/DAO/PostDAO.js
@@ -0,0 +1,17 @@
+(function ()
+{
+ 'use strict';
+
+ function PostDAO($resource)
+ {
+ var api = $resource('/api/post', null, {});
+ return {
+ query: function ()
+ {
+ return api.query().$promise;
+ }
+ };
+ }
+
+ angular.module('app').factory('PostDAO', ['$resource', PostDAO]);
+})();
diff --git a/app/PostDAO.js b/app/PostDAO.js
deleted file mode 100644
index a614ead..0000000
--- a/app/PostDAO.js
+++ /dev/null
@@ -1,16 +0,0 @@
-(function () {
- 'use strict';
-
- function PostDAO($resource) {
- var api = $resource('/api/post', null, {
-
- });
- return {
- query: function () {
- return api.query().$promise;
- }
- };
- }
-
- angular.module('exerciseApp').factory('PostDAO', ['$resource', PostDAO]);
-})();
diff --git a/app/app.js b/app/app.js
index 74e704c..9d11459 100644
--- a/app/app.js
+++ b/app/app.js
@@ -1,12 +1,13 @@
(function ()
{
'use strict';
- var module = angular.module('exerciseApp', ['ngResource']);
- module.config(function ($provide)
+ var app = angular.module('app', ['ngResource']);
+
+ app.config(function ($provide)
{
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
});
- module.run(function ($httpBackend)
+ app.run(function ($httpBackend)
{
var posts = [
{ id: 1,
diff --git a/app/controllers/BlogPostCtrl.js b/app/controllers/BlogPostCtrl.js
new file mode 100644
index 0000000..54f98dd
--- /dev/null
+++ b/app/controllers/BlogPostCtrl.js
@@ -0,0 +1,10 @@
+(function ()
+{
+ 'use strict';
+ function BlogPostCtrl(PostDAO)
+ {
+
+ }
+
+ angular.module('app').controller('BlogPostCtrl', ['PostDAO', BlogPostCtrl]);
+})();
diff --git a/app/index.html b/app/index.html
index de248c8..20c4300 100644
--- a/app/index.html
+++ b/app/index.html
@@ -1,35 +1,38 @@
-
+
Angular Exercise 2
-
+
-
-
-
- | ID |
- Author |
- Title |
-
-
-
-
- |
- |
- |
-
-
-
+
+
+
+
+
+ | ID |
+ Author |
+ Title |
+
+
+
+
+ |
+ |
+ |
+
+
+
+
-
-
+
+
diff --git a/bower.json b/bower.json
index 79d29ee..2ee8a6f 100644
--- a/bower.json
+++ b/bower.json
@@ -8,6 +8,5 @@
},
"devDependencies": {
"angular-mocks": "1.2.16"
- },
- "appPath": "app"
+ }
}
diff --git a/package.json b/package.json
index da086a1..78e9d6b 100644
--- a/package.json
+++ b/package.json
@@ -1,25 +1,25 @@
{
- "name": "angular-exercises",
- "description": "Angular training",
- "version": "0.0.0",
- "dependencies": {},
- "devDependencies": {
- "grunt": "0.4.2",
- "grunt-contrib-jshint": "0.8.0",
- "karma-phantomjs-launcher": "0.1.4",
- "karma": "0.12.16",
- "karma-coverage": "0.2.4",
- "karma-jasmine": "0.1.5",
- "karma-spec-reporter": "0.0.13",
- "grunt-contrib-watch": "0.6.1",
- "grunt-contrib-connect": "0.7.1",
- "grunt-karma": "0.9.0"
- },
- "engines": {
- "node": ">=0.10.0"
- },
- "repository": {
- "type": "git",
- "url": "https://github.com/aniaw/angular-exercises.git"
- }
+ "name": "angular-exercises",
+ "description": "angular training",
+ "version": "0.0.0",
+ "repository": "https://github.com/Real-Skill/angular-exercises.git",
+ "dependencies": {},
+ "devDependencies": {
+ "grunt": "0.4.5",
+ "grunt-cli": "0.1.13",
+ "grunt-contrib-connect": "0.7.1",
+ "grunt-contrib-jshint": "0.11.3",
+ "grunt-contrib-watch": "0.6.1",
+ "grunt-karma": "2.0.0",
+ "karma": "1.4.1",
+ "karma-coverage": "0.3.1",
+ "karma-jasmine": "1.1.0",
+ "karma-junit-reporter": "0.2.2",
+ "karma-phantomjs-launcher": "1.0.2",
+ "karma-spec-reporter": "0.0.13",
+ "load-grunt-tasks": "0.4.0"
+ },
+ "scripts": {
+ "test": "grunt verify --force"
+ }
}
diff --git a/test/.jshintrc b/test/.jshintrc
deleted file mode 100644
index 4f0effd..0000000
--- a/test/.jshintrc
+++ /dev/null
@@ -1,44 +0,0 @@
-{
- "globals": {
- "angular": true,
- "xdescribe": true,
- "describe": true,
- "afterEach": true,
- "beforeEach": true,
- "it": true,
- "xit": true,
- "expect": true,
- "module": true,
- "inject": true,
- "jasmine": true,
- "spyOn": true,
- "mockApi": true,
- "browser": true
- },
- "browser": true,
- "camelcase": true,
- "curly": true,
- "eqeqeq": true,
- "eqnull": true,
- "forin": true,
- "freeze": true,
- "immed": true,
- "indent": 4,
- "jquery": true,
- "latedef": true,
- "newcap": true,
- "noarg": true,
- "noempty": true,
- "nonbsp": true,
- "nonew": true,
- "plusplus": false,
- "quotmark": "single",
- "undef": true,
- "unused": true,
- "strict": true,
- "trailing": true,
- "maxdepth": 2,
- "maxstatements": 0,
- "maxcomplexity": 10,
- "maxlen": 160
-}
diff --git a/test/karma.conf.js b/test/karma.conf.js
index 458aded..7ab65a6 100644
--- a/test/karma.conf.js
+++ b/test/karma.conf.js
@@ -1,7 +1,3 @@
-/**
- * Created by piniu on 05.09.14.
- */
-/*global module*/
module.exports = function (config)
{
'use strict';
@@ -17,30 +13,34 @@ module.exports = function (config)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
- files: [
- 'bower_components/angular/angular.js',
- 'bower_components/angular-mocks/angular-mocks.js',
- 'bower_components/angular-resource/angular-resource.js',
- 'app/app.js',
- 'app/**/*.js',
- 'test/testHelpers.js',
- 'test/spec/**/*.js'
- ],
+ files: ['app/bower_components/angular/angular.js',
+ 'app/bower_components/angular-mocks/angular-mocks.js',
+ 'app/bower_components/angular-resource/angular-resource.js',
+ 'app/app.js',
+ 'app/DAO/*.js',
+ 'app/controllers/*.js',
+ 'test/testHelpers.js',
+ 'test/unit/**/*.spec.js'],
// list of files / patterns to exclude
exclude: [],
- // test results reporter to use
- // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
- reporters: ['spec', 'coverage'],
+ reporters: ['spec', 'coverage', 'junit'],
preprocessors: {
- 'app/**/*.js': 'coverage'
+ 'app/*.js': 'coverage',
+ 'app/!(bower_components)/**/*.js': 'coverage'
},
coverageReporter: {
- dir: 'target/coverage/',
- type: 'html'
+ dir: 'target/',
+ type: 'cobertura',
+ file: 'coverage.xml'
+ },
+
+
+ junitReporter: {
+ outputFile: 'target/test-results.xml'
},
// web server port
@@ -54,18 +54,14 @@ module.exports = function (config)
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
- browsers: [
- 'PhantomJS'
- ],
+ browsers: ['PhantomJS'],
// Which plugins to enable
- plugins: [
- 'karma-phantomjs-launcher', 'karma-coverage', 'karma-jasmine', 'karma-spec-reporter'
- ],
+ plugins: ['karma-phantomjs-launcher', 'karma-jasmine', 'karma-spec-reporter', 'karma-junit-reporter', 'karma-coverage'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
- singleRun: false,
+ singleRun: true,
colors: true,
@@ -75,7 +71,6 @@ module.exports = function (config)
//https://github.com/karma-runner/karma/issues/895
usePolling: true
-
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
diff --git a/test/testHelpers.js b/test/testHelpers.js
index 214cece..b0f397d 100644
--- a/test/testHelpers.js
+++ b/test/testHelpers.js
@@ -3,7 +3,6 @@
/*exported successfulPromise, unsuccessfulPromise*/
function successfulPromise()
{
- 'use strict';
var theArguments = arguments;
//noinspection ReservedWordAsName
return {
@@ -43,4 +42,4 @@ function unsuccessfulPromise()
return this;
}
};
-}
\ No newline at end of file
+}
diff --git a/test/spec/BlogPostCtrl.spec.js b/test/unit/BlogPostCtrl.spec.js
similarity index 76%
rename from test/spec/BlogPostCtrl.spec.js
rename to test/unit/BlogPostCtrl.spec.js
index 599f503..e780e2b 100644
--- a/test/spec/BlogPostCtrl.spec.js
+++ b/test/unit/BlogPostCtrl.spec.js
@@ -2,37 +2,30 @@ describe('BlogPostCtrl', function ()
{
'use strict';
- beforeEach(module('exerciseApp'));
-
var blogPostCtrl;
var PostDAOMock;
var posts;
- var postList;
+
+ beforeEach(module('app'));
beforeEach(inject(function ($controller)
{
- postList = [];
posts = [
- { id: 1,
+ {
+ id: 1,
author: 'Jack',
title: 'Diving Deep with Dependency Injection'
},
- { id: 2,
+ {
+ id: 2,
author: 'Jill',
title: 'Practical End-to-End Testing with Protractor'
}
];
PostDAOMock = jasmine.createSpyObj('PostDAO', ['query']);
- PostDAOMock.query.andReturn(successfulPromise(posts));
-
+ PostDAOMock.query.and.returnValue(successfulPromise(posts));
blogPostCtrl = $controller('BlogPostCtrl', {PostDAO: PostDAOMock});
-
- angular.forEach(blogPostCtrl.posts, function (value)
- {
- this.push(value);
- }, postList);
-
}));
describe('PostDAO.query()', function ()
@@ -55,7 +48,7 @@ describe('BlogPostCtrl', function ()
});
it('should set posts properties', function ()
{
- expect(postList).toEqual(posts);
+ expect(blogPostCtrl.posts).toEqual(posts);
});
});
});