Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Fix client-side tests after removing <base/>
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mleanos committed Oct 11, 2016
1 parent c065246 commit 99e5803
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
template: '<ui-view/>'
})
.state('admin.articles.list', {
url: '/',
url: '',
templateUrl: '/modules/articles/client/views/admin/list-articles.client.view.html',
controller: 'ArticlesAdminListController',
controllerAs: 'vm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
ArticlesService = _ArticlesService_;
Notification = _Notification_;

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

// create mock article
mockArticle = new ArticlesService({
_id: '525a8422f6d0f87f0e407a33',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
Authentication = _Authentication_;
ArticlesService = _ArticlesService_;

// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/articles/client/views/list-articles.client.view.html').respond(200, '');
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');

// create mock article
mockArticle = new ArticlesService({
_id: '525a8422f6d0f87f0e407a33',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
});

describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope) {
beforeEach(inject(function ($state, $rootScope, $templateCache) {
$templateCache.put('/modules/articles/client/views/list-articles.client.view.html', '');

$state.go('articles.list');
$rootScope.$digest();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
// Set POST response
$httpBackend.expectGET('/api/articles').respond(mockArticleList);

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

$httpBackend.flush();

Expand Down
10 changes: 8 additions & 2 deletions modules/chat/tests/client/chat.client.controller.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
ChatController,
$timeout,
$state,
Authentication;
Authentication,
$httpBackend;

// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
Expand Down Expand Up @@ -39,12 +40,17 @@
});

describe('when user logged in', function () {
beforeEach(inject(function ($controller, $rootScope, _Socket_, _Authentication_, _$timeout_, _$state_) {
beforeEach(inject(function ($controller, $rootScope, _$httpBackend_, _Socket_, _Authentication_, _$timeout_, _$state_) {
Authentication.user = {
name: 'user',
roles: ['user']
};

$httpBackend = _$httpBackend_;

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

ChatController = $controller('ChatController as vm', {
$scope: $scope
});
Expand Down
15 changes: 12 additions & 3 deletions modules/chat/tests/client/chat.client.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe('Chat Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;

// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
Expand Down Expand Up @@ -39,17 +40,25 @@
});

describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _$httpBackend_, _Authentication_) {
Authentication.user = {
name: 'user',
roles: ['user']
};

$httpBackend = _$httpBackend_;

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

$state.go('chat');
$rootScope.$digest();
}));

it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/chat/client/views/chat.client.view.html', '');

$location.path('chat/');
$rootScope.$digest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');

// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);

// Initialize the Authentication controller
AuthenticationController = $controller('AuthenticationController as vm', {
$scope: scope
});
}));

describe('$scope.signin()', function () {
it('should login with a correct username and password', function () {
it('should login with a correct user and password', inject(function ($templateCache) {
$templateCache.put('/modules/core/client/views/home.client.view.html', '');

// Test expected GET request
$httpBackend.when('POST', '/api/auth/signin').respond(200, { username: 'Fred' });

Expand All @@ -64,19 +70,20 @@
// Test scope value
expect(scope.vm.authentication.user.username).toEqual('Fred');
expect($location.url()).toEqual('/');
});
}));

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

scope.vm.signin(true);
$httpBackend.flush();

// Test scope value
expect(scope.vm.authentication.user.email).toEqual('[email protected]');
expect($location.url()).toEqual('/');
});
}));

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

describe('$scope.signup()', function () {
it('should register with correct data', function () {
it('should register with correct data', inject(function ($templateCache) {
$templateCache.put('/modules/core/client/views/home.client.view.html', '');

// Test expected GET request
scope.vm.authentication.user = 'Fred';
$httpBackend.when('POST', '/api/auth/signup').respond(200, { username: 'Fred' });
Expand All @@ -148,7 +157,7 @@
expect(scope.vm.authentication.user.username).toBe('Fred');
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!' });
expect($location.url()).toBe('/');
});
}));

it('should fail to register with duplicate Username', function () {
// Test expected POST request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');

// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);

// Mock logged in user
Authentication.user = {
_id: '525a8422f6d0f87f0e407a33',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
$location = _$location_;
$location.path = jasmine.createSpy().and.returnValue(true);

// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);

// Mock logged in user
_Authentication_.user = {
username: 'test',
Expand Down Expand Up @@ -74,6 +77,10 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');

// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);

// Initialize the Authentication controller
PasswordController = $controller('PasswordController as vm', {
$scope: scope
Expand Down
16 changes: 13 additions & 3 deletions modules/users/tests/client/users-admin.client.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe('Users Admin Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;

// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
Expand Down Expand Up @@ -77,17 +78,26 @@
});

describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
Authentication.user = {
name: 'user',
roles: ['admin']
};

$httpBackend = _$httpBackend_;

// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/users/client/views/admin/list-users.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);

$state.go('admin.users');
$rootScope.$digest();
}));

it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/users/client/views/admin/list-users.client.view.html', '');
$templateCache.put('/modules/core/client/views/home.client.view.html', '');

$location.path('admin/users/');
$rootScope.$digest();

Expand Down
17 changes: 14 additions & 3 deletions modules/users/tests/client/users.client.routes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe('Users Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;

// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
Expand Down Expand Up @@ -115,17 +116,27 @@
});

describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
Authentication.user = {
name: 'user',
roles: ['user']
};

$httpBackend = _$httpBackend_;

// Ignore parent template gets on state transitions
$httpBackend.whenGET('/modules/users/client/views/settings/settings.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/users/client/views/settings/edit-profile.client.view.html').respond(200);

$state.go('settings.profile');
$rootScope.$digest();
}));

it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/users/client/views/settings/settings.client.view.html', '');
$templateCache.put('/modules/users/client/views/settings/edit-profile.client.view.html', '');

$location.path('settings/profile/');
$rootScope.$digest();

Expand Down

0 comments on commit 99e5803

Please sign in to comment.