Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit fd6a1e8

Browse files
authored
Merge pull request #356 from janmichaelyu/ui-themes-dashboard
unit tests cleanup for gulp build
2 parents 0cf10d7 + 2a9ee6a commit fd6a1e8

File tree

8 files changed

+161
-37
lines changed

8 files changed

+161
-37
lines changed

app/templates/bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"ng-json-explorer": "8c2a0f9104",
2323
"vkbeautify-wrapper": "*",
2424
"highcharts": "^4.2",
25-
"angular-google-maps": "2.3.2"
25+
"angular-google-maps": "2.3.2",
26+
"tinymce-dist": "4.3.12"
2627
},
2728
"overrides": {
2829
"angular-highlightjs": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
22
'use strict';
33

4-
angular.module('app.create', ['ml.common', 'app.user']);
4+
angular.module('app.create', ['ml.common', 'app.user', 'ngToast']);
55
}());
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
22
'use strict';
33

4-
angular.module('app.user', ['ml.common', 'app.login']);
4+
angular.module('app.user', ['ml.common', 'app.login', 'ngToast']);
55
}());
Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* jshint -W117, -W030 */
2-
(function () {
2+
(function() {
33
'use strict';
44

5-
describe('Service: userService', function () {
5+
describe('Service: userService', function() {
66

77
var service;
88
var _user = {
@@ -33,62 +33,55 @@
3333
}
3434
});
3535

36+
bard.mockService(loginService, {
37+
getAuthenticatedStatus: $q.when(),
38+
});
39+
3640
});
3741

38-
beforeEach(inject(function (_userService_) {
42+
beforeEach(inject(function(_userService_) {
3943
service = _userService_;
4044
}));
4145

42-
it('should be defined', function () {
46+
it('should be defined', function() {
4347
expect(service).to.be.defined;
4448
});
4549

46-
it('currentUser should not be defined', function () {
50+
it('currentUser should not be defined', function() {
4751
expect(service.currentUser()).to.not.be.defined;
4852
});
4953

50-
it('should get the current logged in user - if loginService not init', function () {
54+
it('should get the current logged in user - if loginService not init', function() {
5155
service.getUser().then(function(user) {
52-
expect(user).to.deep.eq({ name: 'bob' });
56+
expect(user).to.deep.eq(null);
5357
});
54-
expect($http.get).to.have.been.calledOnce;
58+
59+
expect(loginService.getAuthenticatedStatus).to.have.been.calledOnce;
60+
5561
$rootScope.$apply();
5662
});
5763

58-
it('should set user with valid credentials', function () {
59-
loginService.login('test', 'abc').then(function(response) {
60-
expect(response.data).to.deep.eq({ authenticated: true, username: 'bob' });
61-
expect(service.currentUser()).to.deep.eq({ name: 'bob' });
62-
expect(service.getUser()).to.deep.eq({ name: 'bob' });
63-
});
64-
expect($http.post).to.have.been.calledOnce;
65-
$rootScope.$apply();
64+
it('should update the current user when logged in using loginService', function(done) {
65+
$rootScope.$broadcast('loginService:login-success', {data:_user});
66+
$rootScope.$apply(service);
67+
68+
done();
69+
expect(service.currentUser().name).to.eq('bob');
6670
});
6771

6872
it('should not set user with invalid credentials', function () {
6973
_user.data.authenticated = false;
70-
loginService.login('test', 'abcd').then(function(response) {
71-
expect(response.data.authenticated).to.be.false;
72-
expect(service.currentUser()).to.not.be.defined;
73-
});
74-
expect($http.post).to.have.been.calledOnce;
75-
$rootScope.$apply();
74+
$rootScope.$broadcast('loginService:login-success', {data:_user});
75+
$rootScope.$apply(service);
76+
77+
expect(service.currentUser().name).to.eq(undefined);
7678
});
7779

7880
it('should clear user after logout', function () {
79-
expect(service.currentUser()).to.not.be.defined;
80-
_user.data.authenticated = true;
81-
loginService.login('test', 'abcd').then(function(response) {
82-
expect(response.data).to.deep.eq({ authenticated: true, username: 'bob' });
83-
expect(service.currentUser()).to.deep.eq({ name: 'bob' });
84-
85-
loginService.logout().then(function(response) {
86-
expect(loginService.isAuthenticated()).to.be.false;
87-
expect(service.currentUser()).to.not.be.defined;
88-
});
89-
});
81+
$rootScope.$broadcast('loginService:logout-success');
82+
$rootScope.$apply(service);
9083

91-
$rootScope.$apply();
84+
expect(service.currentUser()).to.not.be.defined;
9285
});
9386
});
9487
}());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* jshint -W117, -W030 */
2+
(function() {
3+
'use strict';
4+
5+
describe('Controller: DetailCtrl', function() {
6+
7+
var controller;
8+
var doc;
9+
10+
beforeEach(function() {
11+
bard.appModule('app.detail');
12+
bard.inject('$controller', '$rootScope', 'MLUiGmapManager', 'uiGmapGoogleMapApi');
13+
14+
// stub the document
15+
var headers = function() {
16+
return 'application/json'; };
17+
doc = {
18+
headers: headers,
19+
data: {
20+
name: 'hi',
21+
location: {
22+
latitude: 1,
23+
longitude: 2
24+
}
25+
}
26+
};
27+
controller = $controller('DetailCtrl', { doc: doc });
28+
$rootScope.$apply();
29+
});
30+
31+
it('should be created successfully', function() {
32+
expect(controller).to.be.defined;
33+
});
34+
35+
it('should have the doc data we gave it', function() {
36+
expect(controller.doc).to.eq(doc.data);
37+
});
38+
39+
});
40+
}());
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('app.detail', [
5+
'app.similar',
6+
'ui.router',
7+
'app.root',
8+
'uiGmapgoogle-maps'
9+
]);
10+
}());
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* jshint -W117, -W030 */
2+
(function() {
3+
'use strict';
4+
5+
describe('Controller: SearchCtrl', function() {
6+
7+
var controller;
8+
9+
var currentUser = null;
10+
11+
var results = [{
12+
uri: 'abc',
13+
extracted: {
14+
content: [{
15+
location: {
16+
latitude: 1,
17+
longitude: 2
18+
}
19+
}]
20+
}
21+
}, {
22+
uri: 'def',
23+
extracted: {
24+
content: [{
25+
location: {
26+
latitude: 1,
27+
longitude: 2
28+
}
29+
}]
30+
}
31+
}];
32+
33+
beforeEach(function() {
34+
bard.appModule('app.search');
35+
bard.inject('$controller', '$q', '$rootScope', '$location',
36+
'userService', 'MLSearchFactory', 'MLRest', 'MLUiGmapManager', 'uiGmapGoogleMapApi');
37+
38+
bard.mockService(userService, {
39+
currentUser: $q.when(currentUser)
40+
});
41+
42+
bard.mockService(MLRest, {
43+
search: $q.when({
44+
data: {
45+
results: results
46+
}
47+
})
48+
});
49+
50+
});
51+
52+
beforeEach(function() {
53+
controller = $controller('SearchCtrl', { $scope: $rootScope.$new() });
54+
$rootScope.$apply();
55+
});
56+
57+
it('should be created successfully', function() {
58+
expect(controller).to.be.defined;
59+
});
60+
61+
it('should update the current user if it changes', function() {
62+
expect(controller.currentUser).to.not.be.defined;
63+
});
64+
65+
it('should run a search', function() {
66+
controller.search('stuff');
67+
$rootScope.$apply();
68+
expect(controller.response.results).to.eq(results);
69+
});
70+
});
71+
}());
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('app.search', ['ml.search',
5+
'app.user',
6+
'app.snippet',
7+
'app.root',
8+
'uiGmapgoogle-maps']);
9+
}());

0 commit comments

Comments
 (0)