Skip to content

Commit db4962f

Browse files
author
welcome-dev
committed
Fix client-side tests after removing <base/>
Fixes the client-side tests after the removal of the <base/> tag from the main layout. These fixes aren't ideal. At the moment, they will suffice. This comment (angular-ui/ui-router#212 (comment)), among others in that issue, led me to choose this method as the fix to avoid having to change any other core code.
1 parent 8d2ebbc commit db4962f

12 files changed

+87
-20
lines changed

modules/articles/client/config/articles-admin.client.routes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
template: '<ui-view/>'
1616
})
1717
.state('admin.articles.list', {
18-
url: '/',
18+
url: '',
1919
templateUrl: '/modules/articles/client/views/admin/list-articles.client.view.html',
2020
controller: 'ArticlesAdminListController',
2121
controllerAs: 'vm',

modules/articles/tests/client/admin.articles.client.controller.tests.js

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
ArticlesService = _ArticlesService_;
4949
Notification = _Notification_;
5050

51+
// Ignore parent template get on state transitions
52+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
53+
5154
// create mock article
5255
mockArticle = new ArticlesService({
5356
_id: '525a8422f6d0f87f0e407a33',

modules/articles/tests/client/admin.list.articles.client.controller.tests.js

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
Authentication = _Authentication_;
4747
ArticlesService = _ArticlesService_;
4848

49+
// Ignore parent template get on state transitions
50+
$httpBackend.whenGET('/modules/articles/client/views/list-articles.client.view.html').respond(200, '');
51+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
52+
4953
// create mock article
5054
mockArticle = new ArticlesService({
5155
_id: '525a8422f6d0f87f0e407a33',

modules/articles/tests/client/articles.client.routes.tests.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
});
110110

111111
describe('Handle Trailing Slash', function () {
112-
beforeEach(inject(function ($state, $rootScope) {
112+
beforeEach(inject(function ($state, $rootScope, $templateCache) {
113+
$templateCache.put('/modules/articles/client/views/list-articles.client.view.html', '');
114+
113115
$state.go('articles.list');
114116
$rootScope.$digest();
115117
}));

modules/articles/tests/client/list-articles.client.controller.tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
// Set POST response
7979
$httpBackend.expectGET('/api/articles').respond(mockArticleList);
8080

81+
// Ignore parent template get on state transition
82+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
8183

8284
$httpBackend.flush();
8385

modules/chat/tests/client/chat.client.controller.tests.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
ChatController,
1212
$timeout,
1313
$state,
14-
Authentication;
14+
Authentication,
15+
$httpBackend;
1516

1617
// Load the main application module
1718
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -39,12 +40,17 @@
3940
});
4041

4142
describe('when user logged in', function () {
42-
beforeEach(inject(function ($controller, $rootScope, _Socket_, _Authentication_, _$timeout_, _$state_) {
43+
beforeEach(inject(function ($controller, $rootScope, _$httpBackend_, _Socket_, _Authentication_, _$timeout_, _$state_) {
4344
Authentication.user = {
4445
name: 'user',
4546
roles: ['user']
4647
};
4748

49+
$httpBackend = _$httpBackend_;
50+
51+
// Ignore parent template get on state transitions
52+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
53+
4854
ChatController = $controller('ChatController as vm', {
4955
$scope: $scope
5056
});

modules/chat/tests/client/chat.client.routes.tests.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
describe('Chat Route Tests', function () {
55
// Initialize global variables
66
var $scope,
7-
Authentication;
7+
Authentication,
8+
$httpBackend;
89

910
// We can start by loading the main application module
1011
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -39,17 +40,25 @@
3940
});
4041

4142
describe('Handle Trailing Slash', function () {
42-
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
43+
beforeEach(inject(function ($state, $rootScope, _$httpBackend_, _Authentication_) {
4344
Authentication.user = {
4445
name: 'user',
4546
roles: ['user']
4647
};
4748

49+
$httpBackend = _$httpBackend_;
50+
51+
// Ignore parent template get on state transition
52+
$httpBackend.whenGET('/modules/chat/client/views/chat.client.view.html').respond(200);
53+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
54+
4855
$state.go('chat');
4956
$rootScope.$digest();
5057
}));
5158

52-
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
59+
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
60+
$templateCache.put('/modules/chat/client/views/chat.client.view.html', '');
61+
5362
$location.path('chat/');
5463
$rootScope.$digest();
5564

modules/users/tests/client/authentication.client.controller.tests.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@
4747
spyOn(Notification, 'error');
4848
spyOn(Notification, 'success');
4949

50+
// Ignore parent template get on state transitions
51+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
52+
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
53+
5054
// Initialize the Authentication controller
5155
AuthenticationController = $controller('AuthenticationController as vm', {
5256
$scope: scope
5357
});
5458
}));
5559

5660
describe('$scope.signin()', function () {
57-
it('should login with a correct username and password', function () {
61+
it('should login with a correct user and password', inject(function ($templateCache) {
62+
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
63+
5864
// Test expected GET request
5965
$httpBackend.when('POST', '/api/auth/signin').respond(200, { username: 'Fred' });
6066

@@ -64,19 +70,20 @@
6470
// Test scope value
6571
expect(scope.vm.authentication.user.username).toEqual('Fred');
6672
expect($location.url()).toEqual('/');
67-
});
73+
}));
6874

69-
it('should login with a correct email and password', function () {
75+
it('should login with a correct email and password', inject(function ($templateCache) {
76+
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
7077
// Test expected GET request
71-
$httpBackend.when('POST', 'api/auth/signin').respond(200, { email: '[email protected]' });
78+
$httpBackend.when('POST', '/api/auth/signin').respond(200, { email: '[email protected]' });
7279

7380
scope.vm.signin(true);
7481
$httpBackend.flush();
7582

7683
// Test scope value
7784
expect(scope.vm.authentication.user.email).toEqual('[email protected]');
7885
expect($location.url()).toEqual('/');
79-
});
86+
}));
8087

8188
it('should be redirected to previous state after successful login',
8289
inject(function (_$state_) {
@@ -136,7 +143,9 @@
136143
});
137144

138145
describe('$scope.signup()', function () {
139-
it('should register with correct data', function () {
146+
it('should register with correct data', inject(function ($templateCache) {
147+
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
148+
140149
// Test expected GET request
141150
scope.vm.authentication.user = 'Fred';
142151
$httpBackend.when('POST', '/api/auth/signup').respond(200, { username: 'Fred' });
@@ -148,7 +157,7 @@
148157
expect(scope.vm.authentication.user.username).toBe('Fred');
149158
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!' });
150159
expect($location.url()).toBe('/');
151-
});
160+
}));
152161

153162
it('should fail to register with duplicate Username', function () {
154163
// Test expected POST request

modules/users/tests/client/edit-profile.client.controller.tests.js

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
spyOn(Notification, 'error');
5252
spyOn(Notification, 'success');
5353

54+
// Ignore parent template gets on state transition
55+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
56+
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
57+
5458
// Mock logged in user
5559
Authentication.user = {
5660
_id: '525a8422f6d0f87f0e407a33',

modules/users/tests/client/password.client.controller.tests.js

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
$location = _$location_;
4141
$location.path = jasmine.createSpy().and.returnValue(true);
4242

43+
// Ignore parent template gets on state transition
44+
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);
45+
4346
// Mock logged in user
4447
_Authentication_.user = {
4548
username: 'test',
@@ -74,6 +77,10 @@
7477
spyOn(Notification, 'error');
7578
spyOn(Notification, 'success');
7679

80+
// Ignore parent template gets on state transition
81+
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);
82+
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
83+
7784
// Initialize the Authentication controller
7885
PasswordController = $controller('PasswordController as vm', {
7986
$scope: scope

modules/users/tests/client/users-admin.client.routes.tests.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
describe('Users Admin Route Tests', function () {
55
// Initialize global variables
66
var $scope,
7-
Authentication;
7+
Authentication,
8+
$httpBackend;
89

910
// We can start by loading the main application module
1011
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -77,17 +78,26 @@
7778
});
7879

7980
describe('Handle Trailing Slash', function () {
80-
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
81+
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
8182
Authentication.user = {
8283
name: 'user',
8384
roles: ['admin']
8485
};
8586

87+
$httpBackend = _$httpBackend_;
88+
89+
// Ignore parent template gets on state transition
90+
$httpBackend.whenGET('/modules/users/client/views/admin/list-users.client.view.html').respond(200);
91+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
92+
8693
$state.go('admin.users');
8794
$rootScope.$digest();
8895
}));
8996

90-
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
97+
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
98+
$templateCache.put('/modules/users/client/views/admin/list-users.client.view.html', '');
99+
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
100+
91101
$location.path('admin/users/');
92102
$rootScope.$digest();
93103

modules/users/tests/client/users.client.routes.tests.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
describe('Users Route Tests', function () {
55
// Initialize global variables
66
var $scope,
7-
Authentication;
7+
Authentication,
8+
$httpBackend;
89

910
// We can start by loading the main application module
1011
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -115,17 +116,27 @@
115116
});
116117

117118
describe('Handle Trailing Slash', function () {
118-
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
119+
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
119120
Authentication.user = {
120121
name: 'user',
121122
roles: ['user']
122123
};
123124

125+
$httpBackend = _$httpBackend_;
126+
127+
// Ignore parent template gets on state transitions
128+
$httpBackend.whenGET('/modules/users/client/views/settings/settings.client.view.html').respond(200);
129+
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
130+
$httpBackend.whenGET('/modules/users/client/views/settings/edit-profile.client.view.html').respond(200);
131+
124132
$state.go('settings.profile');
125133
$rootScope.$digest();
126134
}));
127135

128-
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
136+
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
137+
$templateCache.put('/modules/users/client/views/settings/settings.client.view.html', '');
138+
$templateCache.put('/modules/users/client/views/settings/edit-profile.client.view.html', '');
139+
129140
$location.path('settings/profile/');
130141
$rootScope.$digest();
131142

0 commit comments

Comments
 (0)