Skip to content

Commit 0847b75

Browse files
refact(*): further architectural improvements
1 parent e5b915f commit 0847b75

32 files changed

+131
-236
lines changed

.jshintrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"globalstrict": true,
33
"globals": {
4-
"angular": false
4+
"angular": false,
5+
"describe": false,
6+
"it": false,
7+
"expect": false,
8+
"beforeEach": false,
9+
"afterEach": false,
10+
"module": false,
11+
"inject": false
512
}
613
}

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ before_script:
1010
- sleep 1 # give server time to start
1111

1212
script:
13-
- node_modules/.bin/karma start test/karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox
14-
- node_modules/.bin/protractor test/protractor-conf.js --browser=firefox
13+
- node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox
14+
- node_modules/.bin/protractor e2e-tests/protractor.conf.js --browser=firefox

README.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,39 +70,33 @@ Now browse to the app at `http://localhost:8000/app/index.html`.
7070

7171
## Directory Layout
7272

73-
app/ --> all of the files to be used in production
74-
assets/ --> all static asset files
75-
css/ --> css files
76-
app.css --> default stylesheet
77-
img/ --> image files
78-
components/ --> all app specific modules
79-
directives/ --> application level directives
80-
appVersion.js --> custom directive that returns the current app version
81-
filters/ --> application level filters
82-
interpolate.js --> custom interpolation filter
83-
services/ --> application level services
84-
appVersionService.js --> custom service that returns the current app version
85-
view1/ --> a custom module for this application
86-
view1.html --> the template rendered for this module
87-
view1.js --> the application logic for this module
88-
view2/ --> a custom module for this application
89-
view2.html --> the template rendered for this module
90-
view2.js --> the application logic for this module
91-
app.js --> application
92-
index.html --> app layout file (the main html template file of the app)
93-
index-async.html --> just like index.html, but loads js files asynchronously
94-
test/ --> test config and source files
95-
protractor-conf.js --> config file for running e2e tests with Protractor
96-
e2e/ --> end-to-end specs
97-
scenarios.js
98-
karma.conf.js --> config file for running unit tests with Karma
99-
unit/ --> unit level specs/tests
100-
directivessSpec.js --> specs for application level directives
101-
filtersSpec.js --> specs for application level filters
102-
servicesSpec.js --> specs for application level services
103-
view1Spec.js --> specs for the view1 module
104-
view2Spec.js --> specs for the view2 module
105-
73+
```
74+
app/ --> all of the source files for the application
75+
app.css --> default stylesheet
76+
components/ --> all app specific modules
77+
version/ --> version related components
78+
version.js --> version module declaration and basic "version" value service
79+
version_test.js --> "version" value service tests
80+
version-directive.js --> custom directive that returns the current app version
81+
version-directive_test.js --> version directive tests
82+
interpolate-filter.js --> custom interpolation filter
83+
interpolate-filter_test.js --> interpolate filter tests
84+
view1/ --> the view1 view template and logic
85+
view1.html --> the partial template
86+
view1.js --> the controller logic
87+
view1_test.js --> tests of the controller
88+
view2/ --> the view2 view template and logic
89+
view2.html --> the partial template
90+
view2.js --> the controller logic
91+
view2_test.js --> tests of the controller
92+
app.js --> main application module
93+
index.html --> app layout file (the main html template file of the app)
94+
index-async.html --> just like index.html, but loads js files asynchronously
95+
karma.conf.js --> config file for running unit tests with Karma
96+
e2e-tests/ --> end-to-end tests
97+
protractor-conf.js --> Protractor config file
98+
scenarios.js --> end-to-end scenarios to be run by Protractor
99+
```
106100

107101
## Testing
108102

@@ -114,8 +108,8 @@ The angular-seed app comes preconfigured with unit tests. These are written in
114108
[Jasmine][jasmine], which we run with the [Karma Test Runner][karma]. We provide a Karma
115109
configuration file to run them.
116110

117-
* the configuration is found at `test/karma.conf.js`
118-
* the unit tests are found in `test/unit/`.
111+
* the configuration is found at `karma.conf.js`
112+
* the unit tests are found in next to the code they are testing and are named as `..._test.js`.
119113

120114
The easiest way to run the unit tests is to use the supplied npm script:
121115

@@ -143,8 +137,8 @@ The angular-seed app comes with end-to-end tests, again written in [Jasmine][jas
143137
are run with the [Protractor][protractor] End-to-End test runner. It uses native events and has
144138
special features for Angular applications.
145139

146-
* the configuration is found at `test/protractor-conf.js`
147-
* the end-to-end tests are found in `test/e2e/`
140+
* the configuration is found at `e2e-tests/protractor-conf.js`
141+
* the end-to-end tests are found in `e2e-tests/scenarios.js`
148142

149143
Protractor simulates interaction with our web app and verifies that the application responds
150144
correctly. Therefore, our web server needs to be serving up the application, so that Protractor
@@ -235,7 +229,7 @@ Then you can start your own development web server to serve static files from a
235229
running:
236230

237231
```
238-
http-server
232+
http-server -a localhost -p 8000
239233
```
240234

241235
Alternatively, you can choose to configure your own webserver, such as apache or nginx. Just

app/assets/css/.gitkeep

Whitespace-only changes.

app/assets/css/app.css

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/assets/img/.gitkeep

Whitespace-only changes.

app/components/directives/appVersion.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/components/filters/interpolate.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/components/services/appVersionService.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
angular.module('myApp.version.interpolate-filter', [])
4+
5+
.filter('interpolate', ['version', function(version) {
6+
return function(text) {
7+
return String(text).replace(/\%VERSION\%/mg, version);
8+
};
9+
}]);

app/components/version/version-filter_test.js renamed to app/components/version/interpolate-filter_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
describe('version filter', function() {
3+
describe('myApp.version module', function() {
44
beforeEach(module('myApp.version'));
55

6-
describe('interpolate', function() {
6+
describe('interpolate filter', function() {
77
beforeEach(module(function($provide) {
88
$provide.value('version', 'TEST_VER');
99
}));
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
angular.module('myApp.version').
4-
directive('appVersion', ['version', function(version) {
5-
return function(scope, elm, attrs) {
6-
elm.text(version);
7-
};
8-
}]);
3+
angular.module('myApp.version.version-directive', [])
4+
5+
.directive('appVersion', ['version', function(version) {
6+
return function(scope, elm, attrs) {
7+
elm.text(version);
8+
};
9+
}]);

app/components/version/version-directive_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
describe('version directives', function() {
3+
describe('myApp.version module', function() {
44
beforeEach(module('myApp.version'));
55

6-
describe('app-version', function() {
6+
describe('app-version directive', function() {
77
it('should print current version', function() {
88
module(function($provide) {
99
$provide.value('version', 'TEST_VER');

app/components/version/version-filter.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/components/version/version.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
'use strict';
22

3-
angular.module('myApp.version', []).
4-
value('version', '0.1');
3+
angular.module('myApp.version', [
4+
'myApp.version.interpolate-filter',
5+
'myApp.version.version-directive'
6+
])
7+
8+
.value('version', '0.1');

app/components/version/version_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
describe('version service', function() {
3+
describe('myApp.version module', function() {
44
beforeEach(module('myApp.version'));
55

6-
describe('version', function() {
6+
describe('version service', function() {
77
it('should return current version', inject(function(version) {
88
expect(version).toEqual('0.1');
99
}));

app/components/view1/view1.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/components/view1/view1.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/components/view2/view2.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/components/view2/view2.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/index-async.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@
3030
$script([
3131
'bower_components/angular/angular.js',
3232
'bower_components/angular-route/angular-route.js',
33-
'js/app.js',
34-
'js/services.js',
35-
'js/controllers.js',
36-
'js/filters.js',
37-
'js/directives.js'
33+
'app.js',
34+
'view1/view1.js',
35+
'view2/view2.js',
36+
'components/version/version.js',
37+
'components/version/version-directive.js',
38+
'components/version/interpolate-filter.js'
3839
], function() {
3940
// when all is done, execute bootstrap angular application
4041
angular.bootstrap(document, ['myApp']);
4142
});
4243
</script>
4344
<title>My AngularJS App</title>
44-
<link rel="stylesheet" href="css/app.css">
45+
<link rel="stylesheet" href="app.css">
4546
</head>
4647
<body ng-cloak>
4748
<ul class="menu">

app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
1212
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css">
1313
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css">
14-
<link rel="stylesheet" href="css/app.css"/>
14+
<link rel="stylesheet" href="app.css"/>
1515
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
1616
</head>
1717
<body>
@@ -38,6 +38,6 @@
3838
<script src="view2/view2.js"></script>
3939
<script src="components/version/version.js"></script>
4040
<script src="components/version/version-directive.js"></script>
41-
<script src="components/version/version-filter.js"></script>
41+
<script src="components/version/interpolate-filter.js"></script>
4242
</body>
4343
</html>

app/view1/view1.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict';
22

33
angular.module('myApp.view1', ['ngRoute'])
4-
.config(['$routeProvider', function($routeProvider) {
5-
$routeProvider.when('/view1', {
6-
templateUrl: 'view1/view1.html',
7-
controller: 'View1Ctrl'
8-
});
9-
}])
10-
.controller('View1Ctrl', [function() {
11-
12-
}]);
4+
5+
.config(['$routeProvider', function($routeProvider) {
6+
$routeProvider.when('/view1', {
7+
templateUrl: 'view1/view1.html',
8+
controller: 'View1Ctrl'
9+
});
10+
}])
11+
12+
.controller('View1Ctrl', [function() {
13+
14+
}]);

app/view1/view1_test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
'use strict';
22

3-
describe('view1 controller', function(){
3+
describe('myApp.view1 module', function() {
4+
45
beforeEach(module('myApp.view1'));
56

6-
it('should ....', inject(function($controller) {
7-
//spec body
8-
var view1Ctrl = $controller('View1Ctrl');
9-
expect(view1Ctrl).toBeDefined();
10-
}));
7+
describe('view1 controller', function(){
8+
9+
it('should ....', inject(function($controller) {
10+
//spec body
11+
var view1Ctrl = $controller('View1Ctrl');
12+
expect(view1Ctrl).toBeDefined();
13+
}));
1114

12-
});
15+
});
16+
});

0 commit comments

Comments
 (0)