2016-04-12 16:40:37 +00:00
|
|
|
import {
|
|
|
|
|
describe,
|
|
|
|
|
it,
|
|
|
|
|
iit,
|
|
|
|
|
ddescribe,
|
|
|
|
|
expect,
|
|
|
|
|
inject,
|
|
|
|
|
beforeEach,
|
|
|
|
|
beforeEachProviders,
|
2016-04-29 00:50:03 +00:00
|
|
|
} from '@angular/core/testing/testing_internal';
|
|
|
|
|
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
2015-05-07 01:28:24 +00:00
|
|
|
|
2016-04-29 00:50:03 +00:00
|
|
|
import {Injector, provide, ReflectiveInjector} from '@angular/core';
|
|
|
|
|
import {Location, LocationStrategy, APP_BASE_HREF} from '@angular/common';
|
|
|
|
|
import {MockLocationStrategy} from '@angular/common/testing';
|
2015-05-07 01:28:24 +00:00
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
|
describe('Location', () => {
|
|
|
|
|
|
2016-06-08 22:45:15 +00:00
|
|
|
var locationStrategy: any /** TODO #9100 */, location: any /** TODO #9100 */;
|
2015-05-07 01:28:24 +00:00
|
|
|
|
2016-04-26 04:47:33 +00:00
|
|
|
function makeLocation(baseHref: string = '/my/app',
|
|
|
|
|
provider: any = /*@ts2dart_const*/[]): Location {
|
2015-06-22 19:14:19 +00:00
|
|
|
locationStrategy = new MockLocationStrategy();
|
|
|
|
|
locationStrategy.internalBaseHref = baseHref;
|
2016-04-14 19:35:24 +00:00
|
|
|
let injector = ReflectiveInjector.resolveAndCreate(
|
2016-06-03 00:30:40 +00:00
|
|
|
[Location, {provide: LocationStrategy, useValue: locationStrategy}, provider]);
|
2015-06-15 22:41:09 +00:00
|
|
|
return location = injector.get(Location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(makeLocation);
|
2015-05-07 01:28:24 +00:00
|
|
|
|
2015-06-12 18:29:31 +00:00
|
|
|
it('should not prepend urls with starting slash when an empty URL is provided',
|
2015-10-26 13:57:41 +00:00
|
|
|
() => { expect(location.prepareExternalUrl('')).toEqual(locationStrategy.getBaseHref()); });
|
2015-06-12 18:29:31 +00:00
|
|
|
|
2015-06-12 19:57:35 +00:00
|
|
|
it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
|
2015-06-15 22:41:09 +00:00
|
|
|
let location = makeLocation('/my/slashed/app/');
|
2015-10-26 13:57:41 +00:00
|
|
|
expect(location.prepareExternalUrl('/page')).toEqual('/my/slashed/app/page');
|
2015-06-12 19:57:35 +00:00
|
|
|
});
|
|
|
|
|
|
2015-05-11 21:49:55 +00:00
|
|
|
it('should not append urls with leading slash on navigate', () => {
|
2015-05-07 01:28:24 +00:00
|
|
|
location.go('/my/app/user/btford');
|
2015-06-22 19:14:19 +00:00
|
|
|
expect(locationStrategy.path()).toEqual('/my/app/user/btford');
|
2015-05-07 01:28:24 +00:00
|
|
|
});
|
|
|
|
|
|
2016-06-09 18:04:15 +00:00
|
|
|
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
2016-05-26 16:34:04 +00:00
|
|
|
|
2016-06-08 22:45:15 +00:00
|
|
|
location.subscribe((ev: any /** TODO #9100 */) => {
|
2015-05-29 21:58:41 +00:00
|
|
|
expect(ev['url']).toEqual('/user/btford');
|
|
|
|
|
async.done();
|
2016-05-26 16:34:04 +00:00
|
|
|
});
|
|
|
|
|
locationStrategy.simulatePopState('/my/app/user/btford');
|
2015-09-09 14:41:11 +00:00
|
|
|
}));
|
2015-05-07 01:28:24 +00:00
|
|
|
|
2015-07-29 03:19:56 +00:00
|
|
|
it('should revert to the previous path when a back() operation is executed', () => {
|
|
|
|
|
var locationStrategy = new MockLocationStrategy();
|
|
|
|
|
var location = new Location(locationStrategy);
|
|
|
|
|
|
2016-06-08 22:45:15 +00:00
|
|
|
function assertUrl(path: any /** TODO #9100 */) { expect(location.path()).toEqual(path); }
|
2015-07-28 05:46:09 +00:00
|
|
|
|
2015-07-29 03:19:56 +00:00
|
|
|
location.go('/ready');
|
|
|
|
|
assertUrl('/ready');
|
|
|
|
|
|
|
|
|
|
location.go('/ready/set');
|
|
|
|
|
assertUrl('/ready/set');
|
|
|
|
|
|
|
|
|
|
location.go('/ready/set/go');
|
|
|
|
|
assertUrl('/ready/set/go');
|
|
|
|
|
|
|
|
|
|
location.back();
|
|
|
|
|
assertUrl('/ready/set');
|
|
|
|
|
|
|
|
|
|
location.back();
|
|
|
|
|
assertUrl('/ready');
|
|
|
|
|
});
|
2015-10-07 23:56:35 +00:00
|
|
|
|
|
|
|
|
it('should incorporate the provided query values into the location change', () => {
|
|
|
|
|
var locationStrategy = new MockLocationStrategy();
|
|
|
|
|
var location = new Location(locationStrategy);
|
|
|
|
|
|
2016-04-12 16:40:37 +00:00
|
|
|
location.go('/home', "key=value");
|
|
|
|
|
expect(location.path()).toEqual("/home?key=value");
|
2015-10-07 23:56:35 +00:00
|
|
|
});
|
2015-06-15 22:41:09 +00:00
|
|
|
});
|
2015-05-07 01:28:24 +00:00
|
|
|
}
|