feat(core): provide support for relative assets for components
Assets defined for `templateUrl` and `styleUrls` can now be loaded in relative to where the component file is placed so long as the `moduleId` is set within the component annotation. Closes #5634
This commit is contained in:
@ -1,4 +1,15 @@
|
||||
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/testing_internal';
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
iit,
|
||||
xit,
|
||||
el,
|
||||
inject
|
||||
} from 'angular2/testing_internal';
|
||||
import {IS_DART} from 'angular2/src/facade/lang';
|
||||
import {UrlResolver} from 'angular2/src/compiler/url_resolver';
|
||||
|
||||
export function main() {
|
||||
@ -69,14 +80,50 @@ export function main() {
|
||||
expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar');
|
||||
expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('corner and error cases', () => {
|
||||
it('should encode URLs before resolving', () => {
|
||||
expect(resolver.resolve('foo/baz', `<p #p>Hello
|
||||
</p>`))
|
||||
.toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E');
|
||||
it('should not resolve urls against the baseUrl when the url contains a scheme', () => {
|
||||
resolver = new UrlResolver('my_packages_dir');
|
||||
expect(resolver.resolve("base/", 'package:file')).toEqual('my_packages_dir/file');
|
||||
expect(resolver.resolve("base/", 'http:super_file')).toEqual('http:super_file');
|
||||
expect(resolver.resolve("base/", './mega_file')).toEqual('base/mega_file');
|
||||
});
|
||||
});
|
||||
|
||||
describe('packages',
|
||||
() => {
|
||||
it('should resolve a url based on the application package', () => {
|
||||
resolver = new UrlResolver('my_packages_dir');
|
||||
expect(resolver.resolve(null, 'package:some/dir/file.txt'))
|
||||
.toEqual('my_packages_dir/some/dir/file.txt');
|
||||
expect(resolver.resolve(null, 'some/dir/file.txt')).toEqual('some/dir/file.txt');
|
||||
});
|
||||
|
||||
it('should contain a default value of "/packages" when nothing is provided for DART',
|
||||
inject([UrlResolver], (resolver) => {
|
||||
if (IS_DART) {
|
||||
expect(resolver.resolve(null, 'package:file')).toEqual('/packages/file');
|
||||
}
|
||||
}));
|
||||
|
||||
it('should contain a default value of "/" when nothing is provided for TS/ESM',
|
||||
inject([UrlResolver], (resolver) => {
|
||||
if (!IS_DART) {
|
||||
expect(resolver.resolve(null, 'package:file')).toEqual('/file');
|
||||
}
|
||||
}));
|
||||
|
||||
it('should resolve a package value when present within the baseurl', () => {
|
||||
resolver = new UrlResolver('/my_special_dir');
|
||||
expect(resolver.resolve('package:some_dir/', 'matias.html'))
|
||||
.toEqual('/my_special_dir/some_dir/matias.html');
|
||||
});
|
||||
})
|
||||
|
||||
describe('corner and error cases', () => {
|
||||
it('should encode URLs before resolving', () => {
|
||||
expect(resolver.resolve('foo/baz', `<p #p>Hello
|
||||
</p>`)).toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -65,5 +65,59 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripLeft', () => {
|
||||
it('should strip the first character of the string if it matches the provided input', () => {
|
||||
var input = "~angular2 is amazing";
|
||||
var expectedOutput = "angular2 is amazing";
|
||||
|
||||
expect(StringWrapper.stripLeft(input, "~")).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should keep stripping characters from the start until the first unmatched character',
|
||||
() => {
|
||||
var input = "#####hello";
|
||||
var expectedOutput = "hello";
|
||||
expect(StringWrapper.stripLeft(input, "#")).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should not alter the provided input if the first charater does not match the provided input',
|
||||
() => {
|
||||
var input = "+angular2 is amazing";
|
||||
expect(StringWrapper.stripLeft(input, "*")).toEqual(input);
|
||||
});
|
||||
|
||||
it('should not do any alterations when an empty string or null value is passed in', () => {
|
||||
expect(StringWrapper.stripLeft("", "S")).toEqual("");
|
||||
expect(StringWrapper.stripLeft(null, "S")).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripRight', () => {
|
||||
it('should strip the first character of the string if it matches the provided input', () => {
|
||||
var input = "angular2 is amazing!";
|
||||
var expectedOutput = "angular2 is amazing";
|
||||
|
||||
expect(StringWrapper.stripRight(input, "!")).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should not alter the provided input if the first charater does not match the provided input',
|
||||
() => {
|
||||
var input = "angular2 is amazing+";
|
||||
|
||||
expect(StringWrapper.stripRight(input, "*")).toEqual(input);
|
||||
});
|
||||
|
||||
it('should keep stripping characters from the end until the first unmatched character',
|
||||
() => {
|
||||
var input = "hi&!&&&&&";
|
||||
var expectedOutput = "hi&!";
|
||||
expect(StringWrapper.stripRight(input, "&")).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should not do any alterations when an empty string or null value is passed in', () => {
|
||||
expect(StringWrapper.stripRight("", "S")).toEqual("");
|
||||
expect(StringWrapper.stripRight(null, "S")).toEqual(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1196,6 +1196,9 @@ var NG_ALL = [
|
||||
'UpperCasePipe.transform()',
|
||||
'UrlResolver',
|
||||
'UrlResolver.resolve()',
|
||||
'getUrlScheme()',
|
||||
'PACKAGE_ROOT_URL',
|
||||
'DEFAULT_PACKAGE_URL_PROVIDER',
|
||||
'Validators#compose()',
|
||||
'Validators#composeAsync()',
|
||||
'Validators#nullValidator()',
|
||||
|
Reference in New Issue
Block a user