| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   el, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   SpyObject, | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {MapWrapper} from 'angular2/src/facade/collection'; | 
					
						
							|  |  |  | import {DOM} from 'angular2/src/dom/dom_adapter'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  | import {DomTestbed, TestView, elRef} from './dom_testbed'; | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {ViewDefinition, DirectiveMetadata, RenderViewRef} from 'angular2/src/render/api'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('DomRenderer integration', () => { | 
					
						
							|  |  |  |     beforeEachBindings(() => [DomTestbed]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should create and destroy root host views while using the given elements in place', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |          tb.compiler.compileHost(someComponent) | 
					
						
							|  |  |  |              .then((hostProtoViewDto) => { | 
					
						
							|  |  |  |                var view = | 
					
						
							|  |  |  |                    new TestView(tb.renderer.createRootHostView(hostProtoViewDto.render, '#root')); | 
					
						
							|  |  |  |                expect(view.rawView.rootNodes[0]).toEqual(tb.rootEl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tb.renderer.destroyView(view.viewRef); | 
					
						
							|  |  |  |                // destroying a root view should not disconnect it!
 | 
					
						
							|  |  |  |                expect(tb.rootEl.parentNode).toBeTruthy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should attach and detach component views', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							| 
									
										
										
										
											2015-06-03 13:42:57 -07:00
										 |  |  |              new ViewDefinition({componentId: 'someComponent', template: 'hello', directives: []}) | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText('hello'); | 
					
						
							|  |  |  |                tb.destroyComponentView(rootView.viewRef, 0, cmpView.viewRef); | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText(''); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-10 15:54:10 -07:00
										 |  |  |     it('should not create LightDom instances if the host element is empty', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							|  |  |  |              new ViewDefinition({ | 
					
						
							| 
									
										
										
										
											2015-06-12 07:50:45 -07:00
										 |  |  |                componentId: 'someComponent', | 
					
						
							|  |  |  |                template: '<some-comp>  <!-- comment -->\n </some-comp>', | 
					
						
							|  |  |  |                directives: [someComponent] | 
					
						
							| 
									
										
										
										
											2015-06-10 15:54:10 -07:00
										 |  |  |              }) | 
					
						
							|  |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  |                expect(cmpView.rawView.proto.elementBinders[0].componentId).toBe('someComponent'); | 
					
						
							|  |  |  |                expect(cmpView.rawView.boundElements[0].lightDom).toBe(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |     it('should update text nodes', inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							| 
									
										
										
										
											2015-06-03 13:42:57 -07:00
										 |  |  |              new ViewDefinition({componentId: 'someComponent', template: '{{a}}', directives: []}) | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tb.renderer.setText(cmpView.viewRef, 0, 'hello'); | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText('hello'); | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |     it('should update any element property/attributes/class/style independent of the compilation', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							|  |  |  |              new ViewDefinition({ | 
					
						
							|  |  |  |                componentId: 'someComponent', | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                template: '<input [title]="y" style="position:absolute">', | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |                directives: [] | 
					
						
							|  |  |  |              }) | 
					
						
							|  |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                var el = DOM.childNodes(tb.rootEl)[0]; | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementProperty(elRef(cmpView.viewRef, 0), 'value', 'hello'); | 
					
						
							| 
									
										
										
										
											2015-06-30 17:38:33 -07:00
										 |  |  |                expect((<HTMLInputElement>el).value).toEqual('hello'); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementClass(elRef(cmpView.viewRef, 0), 'a', true); | 
					
						
							| 
									
										
										
										
											2015-06-30 17:38:33 -07:00
										 |  |  |                expect((<HTMLInputElement>DOM.childNodes(tb.rootEl)[0]).value).toEqual('hello'); | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementClass(elRef(cmpView.viewRef, 0), 'a', false); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                expect(DOM.hasClass(el, 'a')).toBe(false); | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementStyle(elRef(cmpView.viewRef, 0), 'width', '10px'); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                expect(DOM.getStyle(el, 'width')).toEqual('10px'); | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementStyle(elRef(cmpView.viewRef, 0), 'width', null); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                expect(DOM.getStyle(el, 'width')).toEqual(''); | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                tb.renderer.setElementAttribute(elRef(cmpView.viewRef, 0), 'someAttr', 'someValue'); | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                expect(DOM.getAttribute(el, 'some-attr')).toEqual('someValue'); | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |     if (DOM.supportsDOMEvents()) { | 
					
						
							|  |  |  |       it('should call actions on the element independent of the compilation', | 
					
						
							|  |  |  |          inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |            tb.compileAll([ | 
					
						
							|  |  |  |                someComponent, | 
					
						
							|  |  |  |                new ViewDefinition({ | 
					
						
							|  |  |  |                  componentId: 'someComponent', | 
					
						
							|  |  |  |                  template: '<input [title]="y"></input>', | 
					
						
							|  |  |  |                  directives: [] | 
					
						
							|  |  |  |                }) | 
					
						
							|  |  |  |              ]) | 
					
						
							|  |  |  |                .then((protoViewDtos) => { | 
					
						
							|  |  |  |                  var views = tb.createRootViews(protoViewDtos); | 
					
						
							|  |  |  |                  var componentView = views[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 11:21:56 -07:00
										 |  |  |                  tb.renderer.invokeElementMethod(elRef(componentView.viewRef, 0), 'setAttribute', | 
					
						
							| 
									
										
										
										
											2015-06-18 15:44:44 -07:00
										 |  |  |                                                  ['a', 'b']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  expect(DOM.getAttribute(DOM.childNodes(tb.rootEl)[0], 'a')).toEqual('b'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should add and remove views to and from containers', | 
					
						
							|  |  |  |        inject([AsyncTestCompleter, DomTestbed], (async, tb) => { | 
					
						
							|  |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							|  |  |  |              new ViewDefinition({ | 
					
						
							|  |  |  |                componentId: 'someComponent', | 
					
						
							|  |  |  |                template: '<template>hello</template>', | 
					
						
							|  |  |  |                directives: [] | 
					
						
							|  |  |  |              }) | 
					
						
							|  |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                var childProto = protoViewDtos[1].elementBinders[0].nestedProtoView; | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText(''); | 
					
						
							|  |  |  |                var childView = tb.createViewInContainer(cmpView.viewRef, 0, 0, childProto); | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText('hello'); | 
					
						
							|  |  |  |                tb.destroyViewInContainer(cmpView.viewRef, 0, 0, childView.viewRef); | 
					
						
							|  |  |  |                expect(tb.rootEl).toHaveText(''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should handle events', inject([AsyncTestCompleter, DomTestbed], (async, tb: DomTestbed) => { | 
					
						
							|  |  |  |          tb.compileAll([ | 
					
						
							|  |  |  |              someComponent, | 
					
						
							|  |  |  |              new ViewDefinition({ | 
					
						
							|  |  |  |                componentId: 'someComponent', | 
					
						
							|  |  |  |                template: '<input (change)="doSomething()">', | 
					
						
							|  |  |  |                directives: [] | 
					
						
							|  |  |  |              }) | 
					
						
							|  |  |  |            ]) | 
					
						
							|  |  |  |              .then((protoViewDtos) => { | 
					
						
							|  |  |  |                var rootView = tb.createRootView(protoViewDtos[0]); | 
					
						
							|  |  |  |                var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tb.triggerEvent(cmpView.viewRef, 0, 'change'); | 
					
						
							|  |  |  |                var eventEntry = cmpView.events[0]; | 
					
						
							|  |  |  |                // bound element index
 | 
					
						
							|  |  |  |                expect(eventEntry[0]).toEqual(0); | 
					
						
							|  |  |  |                // event type
 | 
					
						
							|  |  |  |                expect(eventEntry[1]).toEqual('change'); | 
					
						
							|  |  |  |                // actual event
 | 
					
						
							| 
									
										
										
										
											2015-06-17 16:21:40 -07:00
										 |  |  |                expect((<Map<any, any>>eventEntry[2]).get('$event').type).toEqual('change'); | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 12:33:40 +02:00
										 |  |  | var someComponent = DirectiveMetadata.create( | 
					
						
							| 
									
										
										
										
											2015-05-26 09:25:39 -07:00
										 |  |  |     {id: 'someComponent', type: DirectiveMetadata.COMPONENT_TYPE, selector: 'some-comp'}); |