2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-06-24 11:46:43 -04:00
|
|
|
import {CompileDirectiveMetadata, CompileStylesheetMetadata, CompileTemplateMetadata, CompileTypeMetadata} from '@angular/compiler/src/compile_metadata';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {CompilerConfig} 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';
|
|
|
|
import {MockResourceLoader} from '@angular/compiler/testing/resource_loader_mock';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {ViewEncapsulation} from '@angular/core/src/metadata/view';
|
2016-07-28 07:54:49 -04:00
|
|
|
import {TestBed} from '@angular/core/testing';
|
2016-07-21 20:12:00 -04:00
|
|
|
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-08-17 12:24:44 -04:00
|
|
|
import {SpyResourceLoader} from './spies';
|
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 12:37:30 -04:00
|
|
|
import {TEST_COMPILER_PROVIDERS} from './test_bindings';
|
2015-09-14 18:59:09 -04:00
|
|
|
|
|
|
|
export function main() {
|
2016-01-06 17:13:44 -05:00
|
|
|
describe('DirectiveNormalizer', () => {
|
2015-09-18 13:33:23 -04:00
|
|
|
var dirType: CompileTypeMetadata;
|
2016-05-02 12:38:46 -04:00
|
|
|
var dirTypeWithHttpUrl: CompileTypeMetadata;
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2016-07-28 07:54:49 -04:00
|
|
|
beforeEach(() => { TestBed.configureCompiler({providers: TEST_COMPILER_PROVIDERS}); });
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2016-05-02 12:38:46 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
dirType = new CompileTypeMetadata({moduleUrl: 'package:some/module/a.js', name: 'SomeComp'});
|
|
|
|
dirTypeWithHttpUrl =
|
|
|
|
new CompileTypeMetadata({moduleUrl: 'http://some/module/a.js', name: 'SomeComp'});
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2016-06-24 11:46:43 -04:00
|
|
|
describe('normalizeDirective', () => {
|
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) => {
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(() => normalizer.normalizeDirective(new CompileDirectiveMetadata({
|
|
|
|
type: dirType,
|
|
|
|
isComponent: true,
|
|
|
|
template:
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []})
|
|
|
|
}))).toThrowError('No template specified for component SomeComp');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeTemplateSync', () => {
|
|
|
|
it('should store the template',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
let template = normalizer.normalizeTemplateSync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: 'a',
|
|
|
|
templateUrl: null,
|
|
|
|
styles: [],
|
|
|
|
styleUrls: []
|
2016-07-21 20:12:00 -04:00
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.template).toEqual('a');
|
|
|
|
expect(template.templateUrl).toEqual('package:some/module/a.js');
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles on the annotation against the moduleUrl',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
let template = normalizer.normalizeTemplateSync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: '',
|
|
|
|
templateUrl: null,
|
|
|
|
styles: [],
|
|
|
|
styleUrls: ['test.css']
|
2016-07-21 20:12:00 -04:00
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles in the template against the moduleUrl',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
let template =
|
|
|
|
normalizer.normalizeTemplateSync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: '<style>@import test.css</style>',
|
|
|
|
templateUrl: null,
|
|
|
|
styles: [],
|
|
|
|
styleUrls: []
|
2016-07-21 20:12:00 -04:00
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should use ViewEncapsulation.Emulated by default',
|
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
|
|
|
let template = normalizer.normalizeTemplateSync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: '',
|
|
|
|
templateUrl: null,
|
|
|
|
styles: [],
|
|
|
|
styleUrls: ['test.css']
|
2016-07-21 20:12:00 -04:00
|
|
|
}));
|
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;
|
|
|
|
let template =
|
|
|
|
normalizer.normalizeTemplateSync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: '',
|
|
|
|
templateUrl: null,
|
|
|
|
styles: [],
|
|
|
|
styleUrls: ['test.css']
|
2016-07-21 20:12:00 -04:00
|
|
|
}));
|
2016-06-24 11:46:43 -04:00
|
|
|
expect(template.encapsulation).toEqual(ViewEncapsulation.None);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('templateUrl', () => {
|
|
|
|
|
|
|
|
it('should load a template from a url that is resolved against moduleUrl',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: MockResourceLoader) => {
|
|
|
|
resourceLoader.expect('package:some/module/sometplurl.html', 'a');
|
2016-06-24 11:46:43 -04:00
|
|
|
normalizer
|
|
|
|
.normalizeTemplateAsync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: null,
|
|
|
|
templateUrl: 'sometplurl.html',
|
|
|
|
styles: [],
|
|
|
|
styleUrls: ['test.css']
|
|
|
|
}))
|
|
|
|
.then((template: CompileTemplateMetadata) => {
|
|
|
|
expect(template.template).toEqual('a');
|
|
|
|
expect(template.templateUrl).toEqual('package:some/module/sometplurl.html');
|
|
|
|
async.done();
|
|
|
|
});
|
2016-08-17 12:24:44 -04:00
|
|
|
resourceLoader.flush();
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles on the annotation against the moduleUrl',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: MockResourceLoader) => {
|
|
|
|
resourceLoader.expect('package:some/module/tpl/sometplurl.html', '');
|
2016-06-24 11:46:43 -04:00
|
|
|
normalizer
|
|
|
|
.normalizeTemplateAsync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: null,
|
|
|
|
templateUrl: 'tpl/sometplurl.html',
|
|
|
|
styles: [],
|
|
|
|
styleUrls: ['test.css']
|
|
|
|
}))
|
|
|
|
.then((template: CompileTemplateMetadata) => {
|
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/test.css']);
|
|
|
|
async.done();
|
|
|
|
});
|
2016-08-17 12:24:44 -04:00
|
|
|
resourceLoader.flush();
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve styles in the template against the templateUrl',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: MockResourceLoader) => {
|
|
|
|
resourceLoader.expect(
|
2016-06-24 11:46:43 -04:00
|
|
|
'package:some/module/tpl/sometplurl.html', '<style>@import test.css</style>');
|
|
|
|
normalizer
|
|
|
|
.normalizeTemplateAsync(dirType, new CompileTemplateMetadata({
|
|
|
|
encapsulation: null,
|
|
|
|
template: null,
|
|
|
|
templateUrl: 'tpl/sometplurl.html',
|
|
|
|
styles: [],
|
|
|
|
styleUrls: []
|
|
|
|
}))
|
|
|
|
.then((template: CompileTemplateMetadata) => {
|
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/tpl/test.css']);
|
|
|
|
async.done();
|
|
|
|
});
|
2016-08-17 12:24:44 -04:00
|
|
|
resourceLoader.flush();
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeExternalStylesheets', () => {
|
|
|
|
|
2016-08-17 12:24:44 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureCompiler(
|
|
|
|
{providers: [{provide: ResourceLoader, useClass: SpyResourceLoader}]});
|
|
|
|
});
|
2016-06-24 11:46:43 -04:00
|
|
|
|
|
|
|
it('should load an external stylesheet',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: SpyResourceLoader) => {
|
|
|
|
programResourceLoaderSpy(resourceLoader, {'package:some/module/test.css': 'a'});
|
2016-06-24 11:46:43 -04:00
|
|
|
normalizer
|
|
|
|
.normalizeExternalStylesheets(new CompileTemplateMetadata({
|
|
|
|
template: '',
|
|
|
|
templateUrl: '',
|
|
|
|
styleUrls: ['package:some/module/test.css']
|
|
|
|
}))
|
|
|
|
.then((template: CompileTemplateMetadata) => {
|
|
|
|
expect(template.externalStylesheets.length).toBe(1);
|
|
|
|
expect(template.externalStylesheets[0]).toEqual(new CompileStylesheetMetadata({
|
|
|
|
moduleUrl: 'package:some/module/test.css',
|
|
|
|
styles: ['a'],
|
|
|
|
styleUrls: []
|
|
|
|
}));
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should load stylesheets referenced by external stylesheets',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: SpyResourceLoader) => {
|
|
|
|
programResourceLoaderSpy(resourceLoader, {
|
2016-06-24 11:46:43 -04:00
|
|
|
'package:some/module/test.css': 'a@import "test2.css"',
|
|
|
|
'package:some/module/test2.css': 'b'
|
|
|
|
});
|
|
|
|
normalizer
|
|
|
|
.normalizeExternalStylesheets(new CompileTemplateMetadata({
|
|
|
|
template: '',
|
|
|
|
templateUrl: '',
|
|
|
|
styleUrls: ['package:some/module/test.css']
|
|
|
|
}))
|
|
|
|
.then((template: CompileTemplateMetadata) => {
|
|
|
|
expect(template.externalStylesheets.length).toBe(2);
|
|
|
|
expect(template.externalStylesheets[0]).toEqual(new CompileStylesheetMetadata({
|
|
|
|
moduleUrl: 'package:some/module/test.css',
|
|
|
|
styles: ['a'],
|
|
|
|
styleUrls: ['package:some/module/test2.css']
|
|
|
|
}));
|
|
|
|
expect(template.externalStylesheets[1]).toEqual(new CompileStylesheetMetadata({
|
|
|
|
moduleUrl: 'package:some/module/test2.css',
|
|
|
|
styles: ['b'],
|
|
|
|
styleUrls: []
|
|
|
|
}));
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('caching', () => {
|
|
|
|
it('should work for templateUrl',
|
|
|
|
inject(
|
2016-08-17 12:24:44 -04:00
|
|
|
[AsyncTestCompleter, DirectiveNormalizer, ResourceLoader],
|
|
|
|
(async: AsyncTestCompleter, normalizer: DirectiveNormalizer,
|
|
|
|
resourceLoader: MockResourceLoader) => {
|
|
|
|
resourceLoader.expect('package:some/module/cmp.html', 'a');
|
2016-06-24 11:46:43 -04:00
|
|
|
var templateMeta = new CompileTemplateMetadata({
|
|
|
|
templateUrl: 'cmp.html',
|
|
|
|
});
|
|
|
|
Promise
|
|
|
|
.all([
|
|
|
|
normalizer.normalizeTemplateAsync(dirType, templateMeta),
|
|
|
|
normalizer.normalizeTemplateAsync(dirType, templateMeta)
|
|
|
|
])
|
|
|
|
.then((templates: CompileTemplateMetadata[]) => {
|
|
|
|
expect(templates[0].template).toEqual('a');
|
|
|
|
expect(templates[1].template).toEqual('a');
|
|
|
|
async.done();
|
|
|
|
});
|
2016-08-17 12:24:44 -04:00
|
|
|
resourceLoader.flush();
|
2016-06-24 11:46:43 -04:00
|
|
|
}));
|
|
|
|
|
2015-09-14 18:59:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeLoadedTemplate', () => {
|
|
|
|
it('should store the viewEncapsulationin the result',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2015-09-14 18:59:09 -04:00
|
|
|
|
|
|
|
var viewEncapsulation = ViewEncapsulation.Native;
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType, new CompileTemplateMetadata(
|
|
|
|
{encapsulation: viewEncapsulation, styles: [], styleUrls: []}),
|
|
|
|
'', 'package:some/module/');
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.encapsulation).toBe(viewEncapsulation);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should keep the template as html',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}), 'a',
|
|
|
|
'package:some/module/');
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
|
|
|
'<ng-content select="a"></ng-content>', 'package:some/module/');
|
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) => {
|
2015-09-14 18:59:09 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2016-05-02 12:38:46 -04:00
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
2015-09-14 18:59:09 -04:00
|
|
|
'<ng-content></ng-content><ng-content select></ng-content><ng-content select="*"></ng-content>',
|
2015-10-01 13:07:49 -04:00
|
|
|
'package:some/module/');
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
|
|
|
'<style>a</style>', 'package:some/module/');
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.styles).toEqual(['a']);
|
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should collect styles inside in elements',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
|
|
|
'<div><style>a</style></div>', 'package:some/module/');
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(template.styles).toEqual(['a']);
|
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should collect styleUrls in the template',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
|
|
|
'<link rel="stylesheet" href="aUrl">', 'package:some/module/');
|
2015-10-01 13:07:49 -04:00
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/aUrl']);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
|
2015-09-18 13:33:23 -04:00
|
|
|
it('should collect styleUrls in elements',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2015-09-14 18:59:09 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2016-05-02 12:38:46 -04:00
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
2015-10-01 13:07:49 -04:00
|
|
|
'<div><link rel="stylesheet" href="aUrl"></div>', 'package:some/module/');
|
|
|
|
expect(template.styleUrls).toEqual(['package:some/module/aUrl']);
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
|
|
|
'<link href="b" rel="a">', 'package:some/module/');
|
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) => {
|
2015-10-14 12:39:40 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2016-05-02 12:38:46 -04:00
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
2015-12-03 18:53:44 -05:00
|
|
|
'<link href="http://some/external.css" rel="stylesheet">', 'package:some/module/');
|
2015-10-14 12:39:40 -04:00
|
|
|
expect(template.styleUrls).toEqual([]);
|
|
|
|
}));
|
|
|
|
|
2015-09-14 18:59:09 -04:00
|
|
|
it('should extract @import style urls into styleAbsUrl',
|
2016-01-06 17:13:44 -05:00
|
|
|
inject([DirectiveNormalizer], (normalizer: DirectiveNormalizer) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType, new CompileTemplateMetadata(
|
|
|
|
{encapsulation: null, styles: ['@import "test.css";'], styleUrls: []}),
|
|
|
|
'', 'package:some/module/id');
|
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-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) => {
|
2015-09-14 18:59:09 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2015-09-18 13:33:23 -04:00
|
|
|
dirType, new CompileTemplateMetadata({
|
2015-09-14 18:59:09 -04:00
|
|
|
encapsulation: null,
|
|
|
|
styles: ['.foo{background-image: url(\'double.jpg\');'],
|
2016-05-02 12:38:46 -04:00
|
|
|
styleUrls: []
|
2015-09-14 18:59:09 -04:00
|
|
|
}),
|
2015-10-01 13:07:49 -04:00
|
|
|
'', 'package:some/module/id');
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType, new CompileTemplateMetadata(
|
|
|
|
{encapsulation: null, styles: [], styleUrls: ['test.css']}),
|
|
|
|
'', 'package:some/module/id');
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirTypeWithHttpUrl, new CompileTemplateMetadata(
|
|
|
|
{encapsulation: null, styles: [], styleUrls: ['test.css']}),
|
|
|
|
'', 'http://some/module/id');
|
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) => {
|
2016-05-02 12:38:46 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
|
|
|
dirType, new CompileTemplateMetadata(
|
|
|
|
{encapsulation: ViewEncapsulation.Emulated, styles: [], styleUrls: []}),
|
|
|
|
'', 'package:some/module/id');
|
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) => {
|
2015-09-18 13:33:23 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2016-05-02 12:38:46 -04:00
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
2015-11-23 19:02:19 -05:00
|
|
|
'<div ngNonBindable><ng-content select="a"></ng-content></div>',
|
2015-10-01 13:07:49 -04:00
|
|
|
'package:some/module/');
|
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) => {
|
2015-09-18 13:33:23 -04:00
|
|
|
var template = normalizer.normalizeLoadedTemplate(
|
2016-05-02 12:38:46 -04:00
|
|
|
dirType,
|
|
|
|
new CompileTemplateMetadata({encapsulation: null, styles: [], styleUrls: []}),
|
2015-11-23 19:02:19 -05:00
|
|
|
'<div ngNonBindable><style>div {color:red}</style></div>', 'package:some/module/');
|
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-08-17 12:24:44 -04:00
|
|
|
function programResourceLoaderSpy(spy: SpyResourceLoader, results: {[key: string]: string}) {
|
2016-06-24 11:46:43 -04:00
|
|
|
spy.spy('get').andCallFake((url: string): Promise<any> => {
|
|
|
|
var result = results[url];
|
|
|
|
if (result) {
|
|
|
|
return Promise.resolve(result);
|
|
|
|
} else {
|
|
|
|
return Promise.reject(`Unknown mock url ${url}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|