feat(router): add location service

This commit is contained in:
Brian Ford
2015-04-21 11:23:23 -07:00
parent cf32213079
commit ea546f5069
5 changed files with 149 additions and 10 deletions

View File

@ -12,16 +12,47 @@ import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {RootRouter} from 'angular2/src/router/router';
import {Pipeline} from 'angular2/src/router/pipeline';
import {RouterOutlet} from 'angular2/src/router/router_outlet';
import {DummyLocation} from 'angular2/src/mock/location_mock'
export function main() {
describe('Router', () => {
var router;
var router,
location;
beforeEach(() => {
router = new RootRouter(new Pipeline());
location = new DummyLocation();
router = new RootRouter(new Pipeline(), location);
});
it('should navigate based on the initial URL state', inject([AsyncTestCompleter], (async) => {
var outlet = makeDummyRef();
router.config('/', {'component': 'Index' })
.then((_) => router.registerOutlet(outlet))
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
expect(location.urlChanges).toEqual(['/']);
async.done();
});
}));
it('should activate viewports and update URL on navigate', inject([AsyncTestCompleter], (async) => {
var outlet = makeDummyRef();
router.registerOutlet(outlet)
.then((_) => {
return router.config('/a', {'component': 'A' });
})
.then((_) => router.navigate('/a'))
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
expect(location.urlChanges).toEqual(['/a']);
async.done();
});
}));
it('should navigate after being configured', inject([AsyncTestCompleter], (async) => {
var outlet = makeDummyRef();