Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update unit test, npm packages, clean #49

Open
wants to merge 4 commits into
base: exercise2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "app/bower_components"
}
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bower_components
node_modules
target
bower_components/
node_modules/
target/

#IDEs
#IntelliJ Idea
.idea
.idea/
*.iml
10 changes: 9 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
105 changes: 72 additions & 33 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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']);
};
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

```
Expand Down
11 changes: 0 additions & 11 deletions app/BlogPostCtrl.js

This file was deleted.

17 changes: 17 additions & 0 deletions app/DAO/PostDAO.js
Original file line number Diff line number Diff line change
@@ -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]);
})();
16 changes: 0 additions & 16 deletions app/PostDAO.js

This file was deleted.

7 changes: 4 additions & 3 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/BlogPostCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(function ()
{
'use strict';
function BlogPostCtrl(PostDAO)
{

}

angular.module('app').controller('BlogPostCtrl', ['PostDAO', BlogPostCtrl]);
})();
43 changes: 23 additions & 20 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
<!DOCTYPE html>
<html ng-app="exerciseApp">
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title>Angular Exercise 2</title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
</head>
<body class="container">
<body>
<div ng-controller="BlogPostCtrl as blogPosts">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Author</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</tbody>
</table>
<div class="container">
<h2 class="page-header">How to use DAO?</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Author</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</tbody>
</table>
</div>
</div>

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-mocks/angular-mocks.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="app.js"></script>
<script src="PostDAO.js"></script>
<script src="BlogPostCtrl.js"></script>
<script src="DAO/PostDAO.js"></script>
<script src="controllers/BlogPostCtrl.js"></script>
</body>
</html>
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
},
"devDependencies": {
"angular-mocks": "1.2.16"
},
"appPath": "app"
}
}
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading