2015-05-15 19:42:52 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
describe,
|
|
|
|
dispatchEvent,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
beforeEachBindings,
|
|
|
|
it,
|
2015-05-28 18:02:20 -04:00
|
|
|
xit,
|
|
|
|
TestComponentBuilder
|
2015-05-15 19:42:52 -04:00
|
|
|
} from 'angular2/test_lib';
|
|
|
|
|
2015-09-04 01:01:36 -04:00
|
|
|
import {Injectable, NgIf} from 'angular2/core';
|
2015-05-15 19:42:52 -04:00
|
|
|
|
2015-09-04 01:01:36 -04:00
|
|
|
import {Directive, Component, View, ViewMetadata} from 'angular2/src/core/metadata';
|
2015-05-15 19:42:52 -04:00
|
|
|
|
|
|
|
@Component({selector: 'child-comp'})
|
2015-06-14 12:29:58 -04:00
|
|
|
@View({template: `<span>Original {{childBinding}}</span>`, directives: []})
|
2015-05-15 19:42:52 -04:00
|
|
|
@Injectable()
|
|
|
|
class ChildComp {
|
|
|
|
childBinding: string;
|
2015-05-28 18:02:20 -04:00
|
|
|
constructor() { this.childBinding = 'Child'; }
|
2015-05-15 19:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'child-comp'})
|
|
|
|
@View({template: `<span>Mock</span>`})
|
|
|
|
@Injectable()
|
|
|
|
class MockChildComp {
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
@Component({selector: 'parent-comp'})
|
|
|
|
@View({template: `Parent(<child-comp></child-comp>)`, directives: [ChildComp]})
|
2015-05-15 19:42:52 -04:00
|
|
|
@Injectable()
|
|
|
|
class ParentComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'my-if-comp'})
|
2015-05-28 18:02:20 -04:00
|
|
|
@View({template: `MyIf(<span *ng-if="showMore">More</span>)`, directives: [NgIf]})
|
2015-05-15 19:42:52 -04:00
|
|
|
@Injectable()
|
|
|
|
class MyIfComp {
|
|
|
|
showMore: boolean = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('test component builder', function() {
|
|
|
|
it('should instantiate a component with valid DOM',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
tcb.createAsync(ChildComp).then((rootTestComponent) => {
|
2015-05-15 19:42:52 -04:00
|
|
|
rootTestComponent.detectChanges();
|
|
|
|
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('Original Child');
|
2015-05-15 19:42:52 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
it('should allow changing members of the component',
|
2015-05-15 19:42:52 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
tcb.createAsync(MyIfComp).then((rootTestComponent) => {
|
2015-05-15 19:42:52 -04:00
|
|
|
rootTestComponent.detectChanges();
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('MyIf()');
|
2015-05-15 19:42:52 -04:00
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
rootTestComponent.componentInstance.showMore = true;
|
|
|
|
rootTestComponent.detectChanges();
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('MyIf(More)');
|
2015-05-15 19:42:52 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should override a template',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
|
|
|
|
2015-05-28 18:02:20 -04:00
|
|
|
tcb.overrideTemplate(MockChildComp, '<span>Mock</span>')
|
2015-05-15 19:42:52 -04:00
|
|
|
.createAsync(MockChildComp)
|
|
|
|
.then((rootTestComponent) => {
|
|
|
|
rootTestComponent.detectChanges();
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('Mock');
|
2015-05-15 19:42:52 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should override a view',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
|
|
|
|
|
|
|
tcb.overrideView(ChildComp,
|
2015-08-14 13:03:45 -04:00
|
|
|
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
|
2015-05-15 19:42:52 -04:00
|
|
|
.createAsync(ChildComp)
|
|
|
|
.then((rootTestComponent) => {
|
|
|
|
rootTestComponent.detectChanges();
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('Modified Child');
|
2015-05-15 19:42:52 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should override component dependencies',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
|
|
|
|
|
|
|
tcb.overrideDirective(ParentComp, ChildComp, MockChildComp)
|
|
|
|
.createAsync(ParentComp)
|
|
|
|
.then((rootTestComponent) => {
|
|
|
|
rootTestComponent.detectChanges();
|
2015-06-23 17:26:02 -04:00
|
|
|
expect(rootTestComponent.nativeElement).toHaveText('Parent(Mock)');
|
2015-05-15 19:42:52 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|