2015-09-14 18:59:09 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
xdescribe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
inject,
|
2015-11-02 19:03:42 -05:00
|
|
|
beforeEachProviders
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-09-14 18:59:09 -04:00
|
|
|
|
2015-11-06 20:34:07 -05:00
|
|
|
import {stringify} from 'angular2/src/facade/lang';
|
2015-11-05 17:07:57 -05:00
|
|
|
import {RuntimeMetadataResolver} from 'angular2/src/compiler/runtime_metadata';
|
2015-10-02 10:37:23 -04:00
|
|
|
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/interfaces';
|
2015-09-14 18:59:09 -04:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
View,
|
|
|
|
Directive,
|
|
|
|
ViewEncapsulation,
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
OnChanges,
|
|
|
|
OnInit,
|
|
|
|
DoCheck,
|
|
|
|
OnDestroy,
|
|
|
|
AfterContentInit,
|
|
|
|
AfterContentChecked,
|
|
|
|
AfterViewInit,
|
2015-09-23 14:43:31 -04:00
|
|
|
AfterViewChecked,
|
2015-11-02 19:03:42 -05:00
|
|
|
SimpleChange,
|
|
|
|
provide
|
2015-09-14 18:59:09 -04:00
|
|
|
} from 'angular2/core';
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
import {TEST_PROVIDERS} from './test_bindings';
|
2015-11-05 17:07:57 -05:00
|
|
|
import {MODULE_SUFFIX} from 'angular2/src/compiler/util';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {IS_DART} from 'angular2/src/facade/lang';
|
2015-11-09 17:33:22 -05:00
|
|
|
import {PLATFORM_DIRECTIVES} from 'angular2/src/core/platform_directives_and_pipes';
|
2015-09-14 18:59:09 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('RuntimeMetadataResolver', () => {
|
2015-11-02 19:03:42 -05:00
|
|
|
beforeEachProviders(() => TEST_PROVIDERS);
|
2015-09-14 18:59:09 -04:00
|
|
|
|
|
|
|
describe('getMetadata', () => {
|
|
|
|
it('should read metadata',
|
|
|
|
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
|
|
|
var meta = resolver.getMetadata(ComponentWithEverything);
|
|
|
|
expect(meta.selector).toEqual('someSelector');
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(meta.exportAs).toEqual('someExportAs');
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(meta.isComponent).toBe(true);
|
|
|
|
expect(meta.dynamicLoadable).toBe(true);
|
|
|
|
expect(meta.type.runtime).toBe(ComponentWithEverything);
|
|
|
|
expect(meta.type.name).toEqual(stringify(ComponentWithEverything));
|
2015-10-01 13:07:49 -04:00
|
|
|
expect(meta.type.moduleUrl).toEqual(`package:someModuleId${MODULE_SUFFIX}`);
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(meta.lifecycleHooks).toEqual(LIFECYCLE_HOOKS_VALUES);
|
|
|
|
expect(meta.changeDetection).toBe(ChangeDetectionStrategy.CheckAlways);
|
2015-09-30 23:59:23 -04:00
|
|
|
expect(meta.inputs).toEqual({'someProp': 'someProp'});
|
|
|
|
expect(meta.outputs).toEqual({'someEvent': 'someEvent'});
|
2015-09-18 13:33:23 -04:00
|
|
|
expect(meta.hostListeners).toEqual({'someHostListener': 'someHostListenerExpr'});
|
|
|
|
expect(meta.hostProperties).toEqual({'someHostProp': 'someHostPropExpr'});
|
|
|
|
expect(meta.hostAttributes).toEqual({'someHostAttr': 'someHostAttrValue'});
|
2015-09-14 18:59:09 -04:00
|
|
|
expect(meta.template.encapsulation).toBe(ViewEncapsulation.Emulated);
|
|
|
|
expect(meta.template.styles).toEqual(['someStyle']);
|
|
|
|
expect(meta.template.styleUrls).toEqual(['someStyleUrl']);
|
|
|
|
expect(meta.template.template).toEqual('someTemplate');
|
|
|
|
expect(meta.template.templateUrl).toEqual('someTemplateUrl');
|
|
|
|
}));
|
|
|
|
|
2015-10-01 13:07:49 -04:00
|
|
|
it('should use the moduleUrl from the reflector if none is given',
|
2015-09-14 18:59:09 -04:00
|
|
|
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
2015-10-01 13:07:49 -04:00
|
|
|
var value: string = resolver.getMetadata(DirectiveWithoutModuleId).type.moduleUrl;
|
|
|
|
var expectedEndValue =
|
2015-11-05 17:07:57 -05:00
|
|
|
IS_DART ? 'base/dist/dart/angular2/test/compiler/runtime_metadata_spec.dart' : './';
|
2015-10-01 13:07:49 -04:00
|
|
|
expect((<any>value).endsWith(expectedEndValue)).toBe(true);
|
2015-09-14 18:59:09 -04:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getViewDirectivesMetadata', () => {
|
|
|
|
|
|
|
|
it('should return the directive metadatas',
|
|
|
|
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
|
|
|
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
|
|
|
.toEqual([resolver.getMetadata(DirectiveWithoutModuleId)]);
|
|
|
|
}));
|
2015-11-02 19:03:42 -05:00
|
|
|
|
2015-11-09 17:33:22 -05:00
|
|
|
describe("platform directives", () => {
|
|
|
|
beforeEachProviders(() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective]})]);
|
2015-11-02 19:03:42 -05:00
|
|
|
|
2015-11-09 17:33:22 -05:00
|
|
|
it('should include platform directives when available',
|
2015-11-02 19:03:42 -05:00
|
|
|
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
|
|
|
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
|
|
|
.toEqual([
|
|
|
|
resolver.getMetadata(ADirective),
|
|
|
|
resolver.getMetadata(DirectiveWithoutModuleId)
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
});
|
2015-09-14 18:59:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-02 19:03:42 -05:00
|
|
|
@Directive({selector: 'a-directive'})
|
|
|
|
class ADirective {
|
|
|
|
}
|
|
|
|
|
2015-09-14 18:59:09 -04:00
|
|
|
@Directive({selector: 'someSelector'})
|
|
|
|
class DirectiveWithoutModuleId {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'someSelector',
|
2015-09-30 23:59:23 -04:00
|
|
|
inputs: ['someProp'],
|
|
|
|
outputs: ['someEvent'],
|
2015-09-14 18:59:09 -04:00
|
|
|
host: {
|
|
|
|
'[someHostProp]': 'someHostPropExpr',
|
|
|
|
'(someHostListener)': 'someHostListenerExpr',
|
|
|
|
'someHostAttr': 'someHostAttrValue'
|
|
|
|
},
|
2015-09-18 13:33:23 -04:00
|
|
|
exportAs: 'someExportAs',
|
2015-09-14 18:59:09 -04:00
|
|
|
moduleId: 'someModuleId',
|
|
|
|
changeDetection: ChangeDetectionStrategy.CheckAlways
|
|
|
|
})
|
|
|
|
@View({
|
|
|
|
template: 'someTemplate',
|
|
|
|
templateUrl: 'someTemplateUrl',
|
|
|
|
encapsulation: ViewEncapsulation.Emulated,
|
|
|
|
styles: ['someStyle'],
|
|
|
|
styleUrls: ['someStyleUrl'],
|
|
|
|
directives: [DirectiveWithoutModuleId]
|
|
|
|
})
|
|
|
|
class ComponentWithEverything implements OnChanges,
|
|
|
|
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
|
|
|
|
AfterViewChecked {
|
2015-10-02 19:47:54 -04:00
|
|
|
onChanges(changes: {[key: string]: SimpleChange}): void {}
|
2015-09-14 18:59:09 -04:00
|
|
|
onInit(): void {}
|
|
|
|
doCheck(): void {}
|
|
|
|
onDestroy(): void {}
|
|
|
|
afterContentInit(): void {}
|
|
|
|
afterContentChecked(): void {}
|
|
|
|
afterViewInit(): void {}
|
|
|
|
afterViewChecked(): void {}
|
|
|
|
}
|