Skip to content

Commit 1990031

Browse files
committed
1 parent fb5822a commit 1990031

File tree

12 files changed

+136
-77
lines changed

12 files changed

+136
-77
lines changed

app/templates/_package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
"karma": "^0.13.14",
3838
"karma-coverage": "^0.5.3",
3939
"karma-jasmine": "^0.3.6",
40-
"phantomjs": "^1.9.18",
41-
"karma-phantomjs-launcher": "^0.2.1",
40+
"karma-ng-html2js-preprocessor": "^0.2.1",
41+
"karma-phantomjs2-launcher": "^0.5.0",
4242
"load-grunt-configs": "^0.4.3",
4343
"load-grunt-tasks": "^3.3.0",
44+
"phantomjs2": "^2.0.2",
4445
"protractor": "^2.5.1",
4546
"q": "^1.4.1",
4647
"time-grunt": "^1.2.2"

app/templates/app/components/about/about.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
*/
2727
function Controller(GruntfilesService) {
2828
console.log('About Controller Constructor');
29-
30-
this.GruntfilesService = GruntfilesService;
29+
ctrl = this;
30+
ctrl.name = 'About';
31+
ctrl.GruntfilesService = GruntfilesService;
3132
}
3233

3334
/**
@@ -49,8 +50,7 @@
4950
*/
5051
Controller.prototype.$onInit = function() {
5152
console.log('About Controller $onInit');
52-
53-
ctrl = this;
53+
ctrl.onInit = 'Success';
5454
var grunt = this.GruntfilesService.query().$promise;
5555
grunt
5656
.then(setlist)

app/templates/app/components/contact/contact.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
function Controller() {
2626
console.log('Contact Controller Constructor');
2727
ctrl = this;
28+
ctrl.name = 'Contact';
2829
}
2930

3031
function $canActivate() {
@@ -34,7 +35,7 @@
3435

3536
Controller.prototype.$onInit = function() {
3637
console.log('Contact Controller $onInit');
37-
38+
ctrl.onInit = 'Success';
3839
ctrl.case1 = 20;
3940
someMethod();
4041
};

app/templates/app/components/home/home.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
function Controller() {
2828
console.log('Home Controller Constructor');
2929
ctrl = this;
30+
ctrl.name = 'Home';
3031
}
3132

3233
function $canActivate() {
@@ -36,5 +37,6 @@
3637

3738
Controller.prototype.$onInit = function() {
3839
console.log('Home Controller $onInit');
40+
ctrl.onInit = 'Success';
3941
};
4042
})();

app/templates/test/components/about/about.spec.js

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,42 @@
11
(function() {
22
'use strict';
33

4-
describe('Controller: About Component', function () {
4+
describe('Component: about', function () {
5+
6+
var controller, compile, rootScope;
57

68
beforeEach(module('<%= appname %>.components.about'));
79
beforeEach(module('<%= appname %>.mock.service.gruntfiles'));
10+
beforeEach(module('templates'));
811

9-
var Controller;
10-
11-
beforeEach(inject(function ($controller) {
12-
Controller = $controller('Controller');
12+
beforeEach(inject(function($rootScope, $compile, $componentController) {
13+
controller = $componentController;
14+
compile = $compile;
15+
rootScope = $rootScope;
1316
}));
1417

15-
describe('AboutController', function() {
16-
it('Set Grunt List', function() {
17-
Controller.activate();
18-
expect(Controller.list[0].name).toEqual('connect-history-api-fallback');
19-
});
20-
});
21-
22-
describe('suite', function() {
23-
it('spec', function() {
24-
// setup
25-
var obj = {
26-
method: function() {
27-
console.log('obj#method()');
28-
}
29-
};
30-
31-
spyOn(obj, 'method');
18+
describe('About Controller', function() {
19+
it('Test Case', function () {
20+
var $scope = {};
3221

33-
// exercise
34-
obj.method();
22+
// Controllerの生成
23+
var ctrl = controller('about', {$scope: $scope});
24+
expect(ctrl.name).toEqual('About');
3525

36-
// verify
37-
expect(obj.method).toHaveBeenCalled();
26+
// $onInitの実行
27+
ctrl.$onInit();
28+
expect(ctrl.onInit).toEqual('Success');
3829
});
3930
});
4031

41-
describe('suite 2', function() {
42-
it('tracks the context', function() {
43-
var spy = jasmine.createSpy('spy');
44-
var baz = {
45-
fn: spy
46-
};
47-
var quux = {
48-
fn: spy
49-
};
50-
baz.fn(123);
51-
quux.fn(456);
52-
53-
expect(spy.calls.first().object).toBe(baz);
54-
expect(spy.calls.mostRecent().object).toBe(quux);
32+
// selector
33+
describe('About templateUrl', function() {
34+
it('Test Case', function () {
35+
var factory = compile('<about></about>');
36+
var scope = rootScope.$new();
37+
var element = factory(scope);
38+
scope.$digest();
39+
console.log(element);
5540
});
5641
});
5742
});

app/templates/test/components/contact/contact.spec.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
(function() {
22
'use strict';
33

4-
describe('Controller: Contact Component', function () {
4+
describe('Component: contact', function () {
55

6-
beforeEach(module('<%= appname %>.components.contact'));
6+
var controller, compile, rootScope;
77

8-
var Controller;
8+
beforeEach(module('<%= appname %>.components.contact'));
9+
beforeEach(module('templates'));
910

10-
beforeEach(inject(function ($controller) {
11-
Controller = $controller('ContactController');
11+
beforeEach(inject(function($rootScope, $compile, $componentController) {
12+
controller = $componentController;
13+
compile = $compile;
14+
rootScope = $rootScope;
1215
}));
1316

1417
describe('Contact Controller', function() {
1518
it('Test Case', function () {
16-
Controller.activate();
19+
var $scope = {};
20+
21+
// Controllerの生成
22+
var ctrl = controller('contact', {$scope: $scope});
23+
expect(ctrl.name).toEqual('Contact');
24+
25+
// $onInitの実行
26+
ctrl.$onInit();
27+
expect(ctrl.onInit).toEqual('Success');
28+
});
29+
});
30+
31+
// selector
32+
describe('Contact templateUrl', function() {
33+
it('Test Case', function () {
34+
var factory = compile('<contact></contact>');
35+
var scope = rootScope.$new();
36+
var element = factory(scope);
37+
scope.$digest();
38+
console.log(element);
1739
});
1840
});
1941
});

app/templates/test/components/home/home.spec.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
(function() {
22
'use strict';
33

4-
describe('Controller: HomeController', function () {
4+
describe('Component: home', function () {
55

6-
beforeEach(module('<%= appname %>.components.home'));
6+
var controller, compile, rootScope;
77

8-
var Controller;
8+
beforeEach(module('<%= appname %>.components.home'));
9+
beforeEach(module('templates'));
910

10-
beforeEach(inject(function ($controller) {
11-
Controller = $controller('HomeController');
11+
beforeEach(inject(function($rootScope, $compile, $componentController) {
12+
controller = $componentController;
13+
compile = $compile;
14+
rootScope = $rootScope;
1215
}));
1316

14-
describe('HomeController', function() {
17+
describe('Home Controller', function() {
18+
it('Test Case', function () {
19+
var $scope = {};
20+
21+
// Controllerの生成
22+
var ctrl = controller('home', {$scope: $scope});
23+
expect(ctrl.name).toEqual('Home');
24+
25+
// $onInitの実行
26+
ctrl.$onInit();
27+
expect(ctrl.onInit).toEqual('Success');
28+
});
29+
});
30+
31+
// selector
32+
describe('Home templateUrl', function() {
1533
it('Test Case', function () {
16-
Controller.activate();
34+
var factory = compile('<home></home>');
35+
var scope = rootScope.$new();
36+
var element = factory(scope);
37+
scope.$digest();
38+
console.log(element);
1739
});
1840
});
1941
});

app/templates/test/karma.conf.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module.exports = function(config) {
2020
// injector:js
2121
// endinjector
2222
'app/scripts/main.js',
23-
'test/main.spec.js'
23+
'test/main.spec.js',
24+
'app/**/*.html'
2425
],
2526

2627
// list of files to exclude
@@ -30,9 +31,15 @@ module.exports = function(config) {
3031
// preprocess matching files before serving them to the browser
3132
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3233
preprocessors: {
34+
'app/**/*.html': ['ng-html2js'],
3335
'app/**/*.js': ['coverage']
3436
},
3537

38+
ngHtml2JsPreprocessor: {
39+
stripPrefix: 'app/',
40+
moduleName: 'templates'
41+
},
42+
3643
coverageReporter: {
3744
type : 'html',
3845
dir : 'report',
@@ -59,7 +66,7 @@ module.exports = function(config) {
5966

6067
// start these browsers
6168
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62-
browsers: ['PhantomJS'],
69+
browsers: ['PhantomJS2'],
6370

6471
// Continuous Integration mode
6572
// if true, Karma captures browsers, runs the tests and exits

app/templates/test/main.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44
describe('Controller: AppController', function () {
55

66
beforeEach(module('<%= appname %>'));
7+
beforeEach(module('ngComponentRouter'));
78

89
var AppController;
910

1011
beforeEach(inject(function ($controller) {
1112
AppController = $controller('AppController');
1213
}));
13-
14-
describe('AppController', function() {
15-
it('Test Case', function () {
16-
17-
});
18-
});
1914
});
2015
})();

components/templates/_components.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
function Controller() {
2323
console.log('<%= text %> Controller Constructor');
2424
ctrl = this;
25+
ctrl.name = '<%= text %>';
2526
}
2627

2728
function $canActivate() {
@@ -31,6 +32,6 @@
3132

3233
Controller.prototype.$onInit = function() {
3334
console.log('<%= text %> Controller $onInit');
34-
ctrl.name = '<%= text %>';
35+
ctrl.onInit = '<%= text %>';
3536
};
3637
})();

0 commit comments

Comments
 (0)