2015-02-20 12:00:09 -05:00
|
|
|
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';
|
2015-04-02 12:52:00 -04:00
|
|
|
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
2015-02-20 12:00:09 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('UrlResolver', () => {
|
|
|
|
var resolver = new UrlResolver();
|
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
describe('absolute base url', () => {
|
|
|
|
it('should add a relative path to the base url', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should replace the base path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', './bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should append to the base path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', 'bar'))
|
|
|
|
.toEqual('http://www.foo.com/baz/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', './bar'))
|
|
|
|
.toEqual('http://www.foo.com/baz/bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support ".." in the path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
|
|
|
|
.toEqual('http://www.foo.com/1/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
|
|
|
|
.toEqual('http://www.foo.com/1/2/biz/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should ignore the base path when the url has a scheme', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
|
|
|
|
.toEqual('http://www.bar.com');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support absolute urls', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
});
|
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
describe('relative base url', () => {
|
|
|
|
it('should add a relative path to the base url',
|
|
|
|
() => { expect(resolver.resolve('foo/', './bar')).toEqual('foo/bar'); });
|
|
|
|
|
|
|
|
it('should replace the base path',
|
|
|
|
() => { expect(resolver.resolve('foo/baz', './bar')).toEqual('foo/bar'); });
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should support ".." in the path', () => {
|
|
|
|
expect(resolver.resolve('foo/baz', '../bar')).toEqual('bar');
|
|
|
|
expect(resolver.resolve('foo/baz', '../biz/bar')).toEqual('biz/bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support absolute urls', () => {
|
|
|
|
expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar');
|
|
|
|
expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar');
|
|
|
|
});
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
});
|
|
|
|
}
|