2015-05-06 21:28:24 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
describe,
|
|
|
|
proxy,
|
2015-05-29 17:58:41 -04:00
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
ddescribe,
|
|
|
|
expect,
|
|
|
|
inject,
|
|
|
|
beforeEach,
|
|
|
|
beforeEachBindings,
|
|
|
|
SpyObject
|
|
|
|
} from 'angular2/test_lib';
|
2015-05-06 21:28:24 -04:00
|
|
|
|
2015-06-15 18:41:09 -04:00
|
|
|
import {Injector, bind} from 'angular2/di';
|
|
|
|
import {CONST_EXPR} from 'angular2/src/facade/lang';
|
|
|
|
import {Location, appBaseHrefToken} from 'angular2/src/router/location';
|
2015-05-06 21:28:24 -04:00
|
|
|
import {BrowserLocation} from 'angular2/src/router/browser_location';
|
2015-06-15 18:41:09 -04:00
|
|
|
import {DummyBrowserLocation} from 'angular2/src/mock/browser_location_mock';
|
2015-05-06 21:28:24 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('Location', () => {
|
|
|
|
|
|
|
|
var browserLocation, location;
|
|
|
|
|
2015-06-15 18:41:09 -04:00
|
|
|
function makeLocation(baseHref: string = '/my/app', binding: any = CONST_EXPR([])): Location {
|
2015-05-06 21:28:24 -04:00
|
|
|
browserLocation = new DummyBrowserLocation();
|
2015-06-15 18:41:09 -04:00
|
|
|
browserLocation.internalBaseHref = baseHref;
|
|
|
|
let injector = Injector.resolveAndCreate(
|
|
|
|
[Location, bind(BrowserLocation).toValue(browserLocation), binding]);
|
|
|
|
return location = injector.get(Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(makeLocation);
|
2015-05-06 21:28:24 -04:00
|
|
|
|
2015-05-11 17:49:55 -04:00
|
|
|
it('should normalize relative urls on navigate', () => {
|
|
|
|
location.go('user/btford');
|
2015-06-15 18:41:09 -04:00
|
|
|
expect(browserLocation.path()).toEqual('/my/app/user/btford');
|
2015-05-11 17:49:55 -04:00
|
|
|
});
|
|
|
|
|
2015-06-12 14:29:31 -04:00
|
|
|
it('should not prepend urls with starting slash when an empty URL is provided',
|
2015-06-15 18:41:09 -04:00
|
|
|
() => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.getBaseHref()); });
|
2015-06-12 14:29:31 -04:00
|
|
|
|
2015-06-12 15:57:35 -04:00
|
|
|
it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
|
2015-06-15 18:41:09 -04:00
|
|
|
let location = makeLocation('/my/slashed/app/');
|
2015-06-12 15:57:35 -04:00
|
|
|
expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page');
|
|
|
|
});
|
|
|
|
|
2015-05-11 17:49:55 -04:00
|
|
|
it('should not append urls with leading slash on navigate', () => {
|
2015-05-06 21:28:24 -04:00
|
|
|
location.go('/my/app/user/btford');
|
2015-06-15 18:41:09 -04:00
|
|
|
expect(browserLocation.path()).toEqual('/my/app/user/btford');
|
2015-05-06 21:28:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove index.html from base href', () => {
|
2015-06-15 18:41:09 -04:00
|
|
|
let location = makeLocation('/my/app/index.html');
|
2015-05-11 17:49:55 -04:00
|
|
|
location.go('user/btford');
|
2015-06-15 18:41:09 -04:00
|
|
|
expect(browserLocation.path()).toEqual('/my/app/user/btford');
|
2015-05-06 21:28:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
|
2015-05-29 17:58:41 -04:00
|
|
|
browserLocation.simulatePopState('/my/app/user/btford');
|
|
|
|
location.subscribe((ev) => {
|
|
|
|
expect(ev['url']).toEqual('/user/btford');
|
|
|
|
async.done();
|
|
|
|
})
|
|
|
|
}));
|
2015-05-06 21:28:24 -04:00
|
|
|
|
|
|
|
it('should normalize location path', () => {
|
|
|
|
browserLocation.internalPath = '/my/app/user/btford';
|
|
|
|
expect(location.path()).toEqual('/user/btford');
|
|
|
|
});
|
|
|
|
|
2015-06-15 18:41:09 -04:00
|
|
|
it('should use optional base href param', () => {
|
|
|
|
let location = makeLocation('/', bind(appBaseHrefToken).toValue('/my/custom/href'));
|
|
|
|
location.go('user/btford');
|
|
|
|
expect(browserLocation.path()).toEqual('/my/custom/href/user/btford');
|
|
|
|
});
|
|
|
|
});
|
2015-05-06 21:28:24 -04:00
|
|
|
}
|