X Tutup
Skip to content

Commit fb6d791

Browse files
test(angular1_router): check that link generation works with baseHref
Closes angular#7489
1 parent 0f8efce commit fb6d791

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

modules/angular1_router/test/ng_link_spec.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@
33
describe('ngLink', function () {
44

55
describe('html5Mode enabled', function () {
6-
runHrefTestsAndExpectPrefix(true);
6+
runHrefTestsAndExpectPrefix('/', true);
77
});
88

99
describe('html5Mode disabled', function () {
10-
runHrefTestsAndExpectPrefix(false, '');
10+
runHrefTestsAndExpectPrefix('', false, '');
1111
});
1212

1313
describe('html5Mode disabled, with hash prefix', function () {
14-
runHrefTestsAndExpectPrefix(false, '!');
14+
runHrefTestsAndExpectPrefix('', false, '!');
1515
});
1616

17-
function runHrefTestsAndExpectPrefix(html5Mode, hashPrefix) {
17+
describe('html5Mode enabled', function () {
18+
runHrefTestsAndExpectPrefix('/moo', true);
19+
});
20+
21+
describe('html5Mode disabled', function () {
22+
runHrefTestsAndExpectPrefix('/moo', false, '');
23+
});
24+
25+
describe('html5Mode disabled, with hash prefix', function () {
26+
runHrefTestsAndExpectPrefix('/moo', false, '!');
27+
});
28+
29+
function runHrefTestsAndExpectPrefix(baseHref, html5Mode, hashPrefix) {
1830
var prefix = html5Mode ? '.' : '#' + hashPrefix;
1931

2032
it('should allow linking from the parent to the child', function () {
21-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
33+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
2234
configureRouter([
2335
{ path: '/a', component: 'oneCmp' },
2436
{ path: '/b', component: 'twoCmp', name: 'Two' }
@@ -30,7 +42,7 @@ describe('ngLink', function () {
3042
});
3143

3244
it('should allow linking from the child and the parent', function () {
33-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
45+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
3446
configureRouter([
3547
{ path: '/a', component: 'oneCmp' },
3648
{ path: '/b', component: 'twoCmp', name: 'Two' }
@@ -43,7 +55,7 @@ describe('ngLink', function () {
4355

4456

4557
it('should allow params in routerLink directive', function () {
46-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
58+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
4759
registerComponent('twoLinkCmp', '<div><a ng-link="[\'/Two\', {param: \'lol\'}]">{{twoLinkCmp.number}}</a></div>', function () {this.number = 'two'});
4860
configureRouter([
4961
{ path: '/a', component: 'twoLinkCmp' },
@@ -57,7 +69,7 @@ describe('ngLink', function () {
5769

5870

5971
it('should update the href of links with bound params', function () {
60-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
72+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
6173
registerComponent('twoLinkCmp', '<div><a ng-link="[\'/Two\', {param: $ctrl.number}]">{{$ctrl.number}}</a></div>', function () {this.number = 43});
6274
configureRouter([
6375
{ path: '/a', component: 'twoLinkCmp' },
@@ -72,7 +84,7 @@ describe('ngLink', function () {
7284

7385

7486
it('should navigate on left-mouse click when a link url matches a route', function () {
75-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
87+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
7688
configureRouter([
7789
{ path: '/', component: 'oneCmp' },
7890
{ path: '/two', component: 'twoCmp', name: 'Two'}
@@ -89,7 +101,7 @@ describe('ngLink', function () {
89101

90102

91103
it('should not navigate on non-left mouse click when a link url matches a route', function() {
92-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
104+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
93105
configureRouter([
94106
{ path: '/', component: 'oneCmp' },
95107
{ path: '/two', component: 'twoCmp', name: 'Two'}
@@ -105,7 +117,7 @@ describe('ngLink', function () {
105117

106118
// See https://github.com/angular/router/issues/206
107119
it('should not navigate a link without an href', function () {
108-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
120+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
109121
configureRouter([
110122
{ path: '/', component: 'oneCmp' },
111123
{ path: '/two', component: 'twoCmp', name: 'Two'}
@@ -119,7 +131,7 @@ describe('ngLink', function () {
119131
});
120132

121133
it('should add an ng-link-active class on the current link', function() {
122-
setup({html5Mode: html5Mode, hashPrefix: hashPrefix});
134+
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
123135
configureRouter([
124136
{ path: '/', component: 'oneCmp', name: 'One' }
125137
]);
@@ -140,7 +152,13 @@ describe('ngLink', function () {
140152
}
141153

142154
function setup(config) {
143-
module('ngComponentRouter')
155+
module(function($provide) {
156+
$provide.decorator('$browser', function($delegate) {
157+
$delegate.baseHref = function() { return config.baseHref; };
158+
return $delegate;
159+
});
160+
});
161+
module('ngComponentRouter');
144162
module(function($locationProvider) {
145163
$locationProvider.html5Mode(config.html5Mode);
146164
$locationProvider.hashPrefix(config.hashPrefix);

0 commit comments

Comments
 (0)
X Tutup