2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 12:47:54 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2017-07-28 09:58:28 -04:00
|
|
|
import {CompileStylesheetMetadata, CompileTemplateMetadata} from '@angular/compiler/src/compile_metadata';
|
|
|
|
import {CompilerConfig, preserveWhitespacesDefault} from '@angular/compiler/src/config';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {DirectiveNormalizer} from '@angular/compiler/src/directive_normalizer';
|
2016-08-17 12:24:44 -04:00
|
|
|
import {ResourceLoader} from '@angular/compiler/src/resource_loader';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {ViewEncapsulation} from '@angular/core/src/metadata/view';
|
2020-04-08 13:14:18 -04:00
|
|
|
import {inject, TestBed} from '@angular/core/testing';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2017-05-17 18:39:08 -04:00
|
|
|
import {noUndefined} from '../src/util';
|
2017-03-24 12:59:58 -04:00
|
|
|
|
2017-08-16 12:00:03 -04:00
|
|
|
import {TEST_COMPILER_PROVIDERS} from './test_bindings';
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2016-11-10 17:07:30 -05:00
|
|
|
const SOME_MODULE_URL = 'package:some/module/a.js';
|
|
|
|
const SOME_HTTP_MODULE_URL = 'http://some/module/a.js';
|
|
|
|
|
2017-03-24 12:59:58 -04:00
|
|
|
function normalizeTemplate(normalizer: DirectiveNormalizer, o: {
|
2020-04-08 13:14:18 -04:00
|
|
|
moduleUrl?: string;
|
|
|
|
template?: string | null;
|
|
|
|
templateUrl?: string | null;
|
|
|
|
styles?: string[];
|
2017-03-24 12:59:58 -04:00
|
|
|
styleUrls?: string[];
|
|
|
|
interpolation?: [string, string] | null;
|
|
|
|
encapsulation?: ViewEncapsulation | null;
|
2017-10-04 13:51:34 -04:00
|
|
|
animations?: any[];
|
2017-07-28 09:58:28 -04:00
|
|
|
preserveWhitespaces?: boolean | null;
|
2017-03-24 12:59:58 -04:00
|
|
|
}) {
|
|
|
|
return normalizer.normalizeTemplate({
|
2017-09-12 12:40:28 -04:00
|
|
|
ngModuleType: null,
|
|
|
|
componentType: SomeComp,
|
|
|
|
moduleUrl: noUndefined(o.moduleUrl || SOME_MODULE_URL),
|
2017-03-24 12:59:58 -04:00
|
|
|
template: noUndefined(o.template),
|
|
|
|
templateUrl: noUndefined(o.templateUrl),
|
|
|
|
styles: noUndefined(o.styles),
|
|
|
|
styleUrls: noUndefined(o.styleUrls),
|
|
|
|
interpolation: noUndefined(o.interpolation),
|
|
|
|
encapsulation: noUndefined(o.encapsulation),
|
2017-07-28 09:58:28 -04:00
|
|
|
animations: noUndefined(o.animations),
|
|
|
|
preserveWhitespaces: noUndefined(o.preserveWhitespaces),
|
2017-03-24 12:59:58 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-01-06 17:13:44 -05:00
|
|
|
describe('DirectiveNormalizer', () => {
|
2017-09-12 12:40:28 -04:00
|
|
|
let resourceLoaderSpy: jasmine.Spy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
resourceLoaderSpy =
|
|
|
|
jasmine.createSpy('get').and.callFake((url: string) => `resource(${url})`);
|
|
|
|
const resourceLoader = {get: resourceLoaderSpy};
|
|
|
|
TestBed.configureCompiler({
|
2020-04-08 13:14:18 -04:00
|
|
|
providers: [...TEST_COMPILER_PROVIDERS, {provide: ResourceLoader, useValue: resourceLoader}]
|
2017-09-12 12:40:28 -04:00
|
|
|
});
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
describe('normalizeTemplate', () => {
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should throw if no template was specified',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
expect(() => normalizeTemplate(normalizer, {}))
|
2017-03-24 12:59:58 -04:00
|
|
|
.toThrowError('No template specified for component SomeComp');
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
2016-12-11 05:49:03 -05:00
|
|
|
it('should throw if template is not a string',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2020-04-08 13:14:18 -04:00
|
|
|
expect(() => normalizeTemplate(normalizer, {template: <any> {}}))
|
2017-03-24 12:59:58 -04:00
|
|
|
.toThrowError('The template specified for component SomeComp is not a string');
|
2016-12-11 05:49:03 -05:00
|
|
|
}));
|
|
|
|
it('should throw if templateUrl is not a string',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2020-04-08 13:14:18 -04:00
|
|
|
expect(() => normalizeTemplate(normalizer, {templateUrl: <any> {}}))
|
2017-03-24 12:59:58 -04:00
|
|
|
.toThrowError('The templateUrl specified for component SomeComp is not a string');
|
2016-12-11 05:49:03 -05:00
|
|
|
}));
|
2017-03-29 13:26:48 -04:00
|
|
|
it('should throw if both template and templateUrl are defined',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-03-24 12:59:58 -04:00
|
|
|
expect(() => normalizeTemplate(normalizer, {
|
|
|
|
template: '',
|
|
|
|
templateUrl: '',
|
|
|
|
}))
|
|
|
|
.toThrowError(`'SomeComp' component cannot define both template and templateUrl`);
|
2017-03-29 13:26:48 -04:00
|
|
|
}));
|
2017-07-28 09:58:28 -04:00
|
|
|
it('should throw if preserveWhitespaces is not a boolean',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
expect(() => normalizeTemplate(normalizer, {
|
|
|
|
template: '',
|
|
|
|
preserveWhitespaces: <any>'WRONG',
|
|
|
|
}))
|
|
|
|
.toThrowError(
|
|
|
|
'The preserveWhitespaces option for component SomeComp must be a boolean');
|
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
});
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
describe('inline template', () => {
|
2016-06-24 11:46:43 -04:00
|
|
|
it('should store the template',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
2016-11-10 17:07:30 -05:00
|
|
|
template: 'a',
|
|
|
|
});
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.template).toEqual('a');
|
|
|
|
expect(template.templateUrl).toEqual('package:some/module/a.js');
|
2017-03-14 12:16:15 -04:00
|
|
|
expect(template.isInline).toBe(true);
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles on the annotation against the moduleUrl',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {template: '', styleUrls: ['test.css']});
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
|
|
|
}));
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should resolve styles in the template against the moduleUrl and add them to the styles',
|
2016-06-24 11:46:43 -04:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<style>template @import test.css</style>',
|
|
|
|
styles: ['direct'],
|
2016-11-10 17:07:30 -05:00
|
|
|
});
|
2017-09-12 12:40:28 -04:00
|
|
|
expect(template.styles).toEqual([
|
|
|
|
'direct', 'template ', 'resource(package:some/module/test.css)'
|
|
|
|
]);
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should use ViewEncapsulation.Emulated by default',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {template: '', styleUrls: ['test.css']});
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.encapsulation).toEqual(ViewEncapsulation.Emulated);
|
2015-09-18 13:33:23 -04:00
|
|
|
}));
|
|
|
|
|
2016-06-24 11:46:43 -04:00
|
|
|
it('should use default encapsulation provided by CompilerConfig',
|
|
|
|
inject(
|
|
|
|
[CompilerConfig, DirectiveNormalizer],
|
|
|
|
(config: CompilerConfig, normalizer: DirectiveNormalizer) => {
|
|
|
|
config.defaultEncapsulation = ViewEncapsulation.None;
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {template: '', styleUrls: ['test.css']});
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.encapsulation).toEqual(ViewEncapsulation.None);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should load a template from a url that is resolved against moduleUrl',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {templateUrl: 'sometplurl.html', styleUrls: ['test.css']});
|
|
|
|
expect(template.template).toEqual('resource(package:some/module/sometplurl.html)');
|
|
|
|
expect(template.templateUrl).toEqual('package:some/module/sometplurl.html');
|
|
|
|
expect(template.isInline).toBe(false);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles on the annotation against the moduleUrl',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {templateUrl: 'tpl/sometplurl.html', styleUrls: ['test.css']});
|
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles in the template against the templateUrl and add them to the styles',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
resourceLoaderSpy.and.callFake((url: string) => {
|
|
|
|
switch (url) {
|
|
|
|
case 'package:some/module/tpl/sometplurl.html':
|
|
|
|
return '<style>template @import test.css</style>';
|
|
|
|
default:
|
|
|
|
return `resource(${url})`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {templateUrl: 'tpl/sometplurl.html', styles: ['direct']});
|
|
|
|
expect(template.styles).toEqual([
|
|
|
|
'direct', 'template ', 'resource(package:some/module/tpl/test.css)'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('externalStylesheets', () => {
|
2016-06-24 11:46:43 -04:00
|
|
|
it('should load an external stylesheet',
|
2017-09-12 12:40:28 -04:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {template: '', styleUrls: ['package:some/module/test.css']});
|
|
|
|
expect(template.externalStylesheets.length).toBe(1);
|
|
|
|
expect(template.externalStylesheets[0]).toEqual(new CompileStylesheetMetadata({
|
|
|
|
moduleUrl: 'package:some/module/test.css',
|
|
|
|
styles: ['resource(package:some/module/test.css)'],
|
|
|
|
}));
|
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should load stylesheets referenced by external stylesheets and inline them',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
resourceLoaderSpy.and.callFake((url: string) => {
|
|
|
|
switch (url) {
|
|
|
|
case 'package:some/module/test.css':
|
|
|
|
return 'a@import "test2.css"';
|
|
|
|
case 'package:some/module/test2.css':
|
|
|
|
return 'b';
|
|
|
|
default:
|
|
|
|
throw new Error(`Unexpected url ${url}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '',
|
|
|
|
styleUrls: ['package:some/module/test.css'],
|
|
|
|
});
|
|
|
|
expect(template.externalStylesheets.length).toBe(1);
|
|
|
|
expect(template.externalStylesheets[0])
|
|
|
|
.toEqual(new CompileStylesheetMetadata(
|
|
|
|
{moduleUrl: 'package:some/module/test.css', styles: ['a', 'b'], styleUrls: []}));
|
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('caching', () => {
|
|
|
|
it('should work for templateUrl',
|
2017-09-12 12:40:28 -04:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
const prenormMeta = {
|
|
|
|
templateUrl: 'cmp.html',
|
|
|
|
};
|
|
|
|
const template1 = <CompileTemplateMetadata>normalizeTemplate(normalizer, prenormMeta);
|
|
|
|
const template2 = <CompileTemplateMetadata>normalizeTemplate(normalizer, prenormMeta);
|
|
|
|
expect(template1.template).toEqual('resource(package:some/module/cmp.html)');
|
|
|
|
expect(template2.template).toEqual('resource(package:some/module/cmp.html)');
|
|
|
|
|
|
|
|
expect(resourceLoaderSpy).toHaveBeenCalledTimes(1);
|
|
|
|
}));
|
2015-09-14 18:59:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeLoadedTemplate', () => {
|
2017-03-22 23:24:34 -04:00
|
|
|
it('should store the viewEncapsulation in the result',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const viewEncapsulation = ViewEncapsulation.Native;
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
encapsulation: viewEncapsulation,
|
|
|
|
template: '',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.encapsulation).toBe(viewEncapsulation);
|
|
|
|
}));
|
|
|
|
|
2017-07-28 09:58:28 -04:00
|
|
|
it('should use preserveWhitespaces setting from compiler config if none provided',
|
|
|
|
inject(
|
|
|
|
[DirectiveNormalizer, CompilerConfig],
|
|
|
|
(normalizer: DirectiveNormalizer, config: CompilerConfig) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template =
|
|
|
|
<CompileTemplateMetadata>normalizeTemplate(normalizer, {template: ''});
|
2017-07-28 09:58:28 -04:00
|
|
|
expect(template.preserveWhitespaces).toBe(config.preserveWhitespaces);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should store the preserveWhitespaces=false in the result',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {preserveWhitespaces: false, template: ''});
|
2017-07-28 09:58:28 -04:00
|
|
|
expect(template.preserveWhitespaces).toBe(false);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should store the preserveWhitespaces=true in the result',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(
|
|
|
|
normalizer, {preserveWhitespaces: true, template: ''});
|
2017-07-28 09:58:28 -04:00
|
|
|
expect(template.preserveWhitespaces).toBe(true);
|
|
|
|
}));
|
|
|
|
|
2015-09-14 18:59:09 -04:00
|
|
|
it('should keep the template as html',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: 'a',
|
|
|
|
});
|
2016-07-21 20:12:00 -04:00
|
|
|
expect(template.template).toEqual('a');
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should collect ngContent',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<ng-content select="a"></ng-content>',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.ngContentSelectors).toEqual(['a']);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should normalize ngContent wildcard selector',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template:
|
|
|
|
'<ng-content></ng-content><ng-content select></ng-content><ng-content select="*"></ng-content>',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.ngContentSelectors).toEqual(['*', '*', '*']);
|
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should collect top level styles in the template',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<style>a</style>',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.styles).toEqual(['a']);
|
|
|
|
}));
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should collect styles inside elements',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<div><style>a</style></div>',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.styles).toEqual(['a']);
|
|
|
|
}));
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should collect styleUrls in the template and add them to the styles',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<link rel="stylesheet" href="aUrl">',
|
|
|
|
});
|
|
|
|
expect(template.styles).toEqual(['resource(package:some/module/aUrl)']);
|
|
|
|
expect(template.styleUrls).toEqual([]);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should collect styleUrls in elements and add them to the styles',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<div><link rel="stylesheet" href="aUrl"></div>',
|
|
|
|
});
|
|
|
|
expect(template.styles).toEqual(['resource(package:some/module/aUrl)']);
|
|
|
|
expect(template.styleUrls).toEqual([]);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should ignore link elements with non stylesheet rel attribute',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<link href="b" rel="a">',
|
|
|
|
});
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(template.styleUrls).toEqual([]);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-10-14 12:39:40 -04:00
|
|
|
it('should ignore link elements with absolute urls but non package: scheme',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<link href="http://some/external.css" rel="stylesheet">',
|
|
|
|
});
|
2015-10-14 12:39:40 -04:00
|
|
|
expect(template.styleUrls).toEqual([]);
|
|
|
|
}));
|
|
|
|
|
2017-09-12 12:40:28 -04:00
|
|
|
it('should extract @import style urls and add them to the styles',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
styles: ['@import "test.css";'],
|
|
|
|
template: '',
|
|
|
|
});
|
|
|
|
expect(template.styles).toEqual(['', 'resource(package:some/module/test.css)']);
|
|
|
|
expect(template.styleUrls).toEqual([]);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-10-14 12:39:40 -04:00
|
|
|
it('should not resolve relative urls in inline styles',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
styles: ['.foo{background-image: url(\'double.jpg\');'],
|
|
|
|
template: '',
|
|
|
|
});
|
2015-10-14 12:39:40 -04:00
|
|
|
expect(template.styles).toEqual(['.foo{background-image: url(\'double.jpg\');']);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve relative style urls in styleUrls',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
styleUrls: ['test.css'],
|
|
|
|
template: '',
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.styles).toEqual([]);
|
2015-10-01 13:07:49 -04:00
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-10-27 17:00:15 -04:00
|
|
|
it('should resolve relative style urls in styleUrls with http directive url',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
moduleUrl: SOME_HTTP_MODULE_URL,
|
|
|
|
styleUrls: ['test.css'],
|
|
|
|
template: '',
|
|
|
|
});
|
2015-10-27 17:00:15 -04:00
|
|
|
expect(template.styles).toEqual([]);
|
|
|
|
expect(template.styleUrls).toEqual(['http://some/module/test.css']);
|
|
|
|
}));
|
|
|
|
|
2015-12-16 02:47:48 -05:00
|
|
|
it('should normalize ViewEncapsulation.Emulated to ViewEncapsulation.None if there are no styles nor stylesheets',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
encapsulation: ViewEncapsulation.Emulated,
|
|
|
|
template: '',
|
|
|
|
});
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(template.encapsulation).toEqual(ViewEncapsulation.None);
|
|
|
|
}));
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2015-11-23 19:02:19 -05:00
|
|
|
it('should ignore ng-content in elements with ngNonBindable',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<div ngNonBindable><ng-content select="a"></ng-content></div>',
|
|
|
|
});
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(template.ngContentSelectors).toEqual([]);
|
|
|
|
}));
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2015-11-23 19:02:19 -05:00
|
|
|
it('should still collect <style> in elements with ngNonBindable',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2017-09-12 12:40:28 -04:00
|
|
|
const template = <CompileTemplateMetadata>normalizeTemplate(normalizer, {
|
|
|
|
template: '<div ngNonBindable><style>div {color:red}</style></div>',
|
|
|
|
});
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(template.styles).toEqual(['div {color:red}']);
|
|
|
|
}));
|
2015-09-18 13:33:23 -04:00
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
});
|
|
|
|
}
|
2016-06-24 11:46:43 -04:00
|
|
|
|
2016-12-11 05:49:03 -05:00
|
|
|
class SomeComp {}
|