This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Remove trailing slash from routes
Adds an angular $urlRouterProvider service Rule to the Core module configuration, that removes any trailing slashes in the URL for all routes. The Rule is defined in the core routes configuration. Thus, in order for this to work on all routes in the application, we have to inject the Core module into each client module, as a dependecy in the client.module configuration. Otherwise, we'd have to define the Rule in each module's route configuration individually. Adds missing client-side route configuration tests. Tests demonstrate that the various route configurations can handle a trailing slash in the URL, and gets resolved to the correct client route. Fixes #1075
- Loading branch information
Showing
7 changed files
with
530 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
(function (app) { | ||
'use strict'; | ||
|
||
app.registerModule('articles'); | ||
app.registerModule('articles', ['core']);// The core module is required for special route handling; see /core/client/config/core.client.routes | ||
app.registerModule('articles.services'); | ||
app.registerModule('articles.routes', ['ui.router', 'articles.services']); | ||
})(ApplicationConfiguration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(function (app) { | ||
'use strict'; | ||
|
||
app.registerModule('chat'); | ||
app.registerModule('chat', ['core']); | ||
app.registerModule('chat.routes', ['ui.router']); | ||
})(ApplicationConfiguration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
describe('Chat Route Tests', function () { | ||
// Initialize global variables | ||
var $scope, | ||
Authentication; | ||
|
||
//We can start by loading the main application module | ||
beforeEach(module(ApplicationConfiguration.applicationModuleName)); | ||
|
||
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). | ||
// This allows us to inject a service but then attach it to a variable | ||
// with the same name as the service. | ||
beforeEach(inject(function ($rootScope, _Authentication_) { | ||
// Set a new global scope | ||
$scope = $rootScope.$new(); | ||
Authentication = _Authentication_; | ||
})); | ||
|
||
describe('Route Config', function () { | ||
describe('Main Route', function () { | ||
var mainstate; | ||
beforeEach(inject(function ($state) { | ||
mainstate = $state.get('chat'); | ||
})); | ||
|
||
it('Should have the correct URL', function () { | ||
expect(mainstate.url).toEqual('/chat'); | ||
}); | ||
|
||
it('Should not be abstract', function () { | ||
expect(mainstate.abstract).toBe(undefined); | ||
}); | ||
|
||
it('Should have templateUrl', function () { | ||
expect(mainstate.templateUrl).toBe('modules/chat/client/views/chat.client.view.html'); | ||
}); | ||
}); | ||
|
||
describe('Handle Trailing Slash', function () { | ||
beforeEach(inject(function ($state, $rootScope, _Authentication_) { | ||
Authentication.user = { | ||
name: 'user', | ||
roles: ['user'] | ||
}; | ||
|
||
$state.go('chat'); | ||
$rootScope.$digest(); | ||
})); | ||
|
||
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) { | ||
$location.path('chat/'); | ||
$rootScope.$digest(); | ||
|
||
expect($location.path()).toBe('/chat'); | ||
expect($state.current.templateUrl).toBe('modules/chat/client/views/chat.client.view.html'); | ||
})); | ||
}); | ||
|
||
}); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
modules/users/tests/client/users-admin.client.routes.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
describe('Users Admin Route Tests', function () { | ||
// Initialize global variables | ||
var $scope, | ||
Authentication; | ||
|
||
//We can start by loading the main application module | ||
beforeEach(module(ApplicationConfiguration.applicationModuleName)); | ||
|
||
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). | ||
// This allows us to inject a service but then attach it to a variable | ||
// with the same name as the service. | ||
beforeEach(inject(function ($rootScope, _Authentication_) { | ||
// Set a new global scope | ||
$scope = $rootScope.$new(); | ||
Authentication = _Authentication_; | ||
})); | ||
|
||
describe('Route Config', function () { | ||
describe('Main Route', function () { | ||
var mainstate; | ||
beforeEach(inject(function ($state) { | ||
mainstate = $state.get('admin.users'); | ||
})); | ||
|
||
it('Should have the correct URL', function () { | ||
expect(mainstate.url).toEqual('/users'); | ||
}); | ||
|
||
it('Should not be abstract', function () { | ||
expect(mainstate.abstract).toBe(undefined); | ||
}); | ||
|
||
it('Should have templateUrl', function () { | ||
expect(mainstate.templateUrl).toBe('modules/users/client/views/admin/list-users.client.view.html'); | ||
}); | ||
}); | ||
|
||
describe('View Route', function () { | ||
var viewstate; | ||
beforeEach(inject(function ($state) { | ||
viewstate = $state.get('admin.user'); | ||
})); | ||
|
||
it('Should have the correct URL', function () { | ||
expect(viewstate.url).toEqual('/users/:userId'); | ||
}); | ||
|
||
it('Should not be abstract', function () { | ||
expect(viewstate.abstract).toBe(undefined); | ||
}); | ||
|
||
it('Should have templateUrl', function () { | ||
expect(viewstate.templateUrl).toBe('modules/users/client/views/admin/view-user.client.view.html'); | ||
}); | ||
}); | ||
|
||
describe('Edit Route', function () { | ||
var editstate; | ||
beforeEach(inject(function ($state) { | ||
editstate = $state.get('admin.user-edit'); | ||
})); | ||
|
||
it('Should have the correct URL', function () { | ||
expect(editstate.url).toEqual('/users/:userId/edit'); | ||
}); | ||
|
||
it('Should not be abstract', function () { | ||
expect(editstate.abstract).toBe(undefined); | ||
}); | ||
|
||
it('Should have templateUrl', function () { | ||
expect(editstate.templateUrl).toBe('modules/users/client/views/admin/edit-user.client.view.html'); | ||
}); | ||
}); | ||
|
||
describe('Handle Trailing Slash', function () { | ||
beforeEach(inject(function ($state, $rootScope, _Authentication_) { | ||
Authentication.user = { | ||
name: 'user', | ||
roles: ['admin'] | ||
}; | ||
|
||
$state.go('admin.users'); | ||
$rootScope.$digest(); | ||
})); | ||
|
||
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) { | ||
$location.path('admin/users/'); | ||
$rootScope.$digest(); | ||
|
||
expect($location.path()).toBe('/admin/users'); | ||
expect($state.current.templateUrl).toBe('modules/users/client/views/admin/list-users.client.view.html'); | ||
})); | ||
}); | ||
|
||
}); | ||
}); | ||
})(); |
Oops, something went wrong.