2015-11-23 10:18:04 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {Component, Directive, View, Output, EventEmitter} from 'angular2/core';
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ComponentFixture,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  afterEach,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  AsyncTestCompleter,
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  TestComponentBuilder,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  beforeEach,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ddescribe,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  dispatchEvent,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  fakeAsync,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  tick,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  expect,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  it,
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  inject,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  iit,
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-19 16:47:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  xit,
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-24 15:41:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  browserDetection
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} from 'angular2/testing_internal';
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-19 15:09:34 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {DOM} from 'angular2/src/platform/dom/dom_adapter';
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  Control,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ControlGroup,
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 22:01:36 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  ControlValueAccessor,
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-10 21:42:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  FORM_DIRECTIVES,
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-27 14:36:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  NG_VALIDATORS,
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  NG_ASYNC_VALIDATORS,
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-10 13:51:44 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  NgControl,
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 22:01:36 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  NgIf,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  NgFor,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  NgForm,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  Validators,
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 16:54:27 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  Validator
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-18 15:55:43 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} from 'angular2/common';
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-24 09:57:24 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {Provider, forwardRef, Input} from 'angular2/core';
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {By} from 'angular2/platform/browser';
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-06 17:34:07 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {ListWrapper} from 'angular2/src/facade/collection';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {ObservableWrapper} from 'angular2/src/facade/async';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {CONST_EXPR} from 'angular2/src/facade/lang';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {PromiseWrapper} from "angular2/src/facade/promise";
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export function main() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe("integration tests", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 17:52:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("should initialize DOM elements with the given form object",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               new ControlGroup({"login": new Control("loginValue")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(input.nativeElement.value).toEqual("loginValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("should update the control group values on DOM change",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         var form = new ControlGroup({"login": new Control("oldValue")});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           input.nativeElement.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(form.value).toEqual({"login": "updatedValue"});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should ignore the change event for <input type=text>",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         var form = new ControlGroup({"login": new Control("oldValue")});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           input.nativeElement.value = "updatedValue";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           ObservableWrapper.subscribe(form.valueChanges,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                       (value) => { throw 'Should not happen'; });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           dispatchEvent(input.nativeElement, "change");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should emit ngSubmit event on submit",
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var t = `<div>
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      <form [ngFormModel]="form" (ngSubmit)="name='updated'"></form>
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      <span>{{name}}</span>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    </div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-12 16:26:21 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                fixture.debugElement.componentInstance.form = new ControlGroup({});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                fixture.debugElement.componentInstance.name = 'old';
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var form = fixture.debugElement.query(By.css("form"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                dispatchEvent(form.nativeElement, "submit");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                expect(fixture.debugElement.componentInstance.name).toEqual('updated');
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-28 08:59:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should work with single controls",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         var control = new Control("loginValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div><input type="text" [ngFormControl]="form"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form = control;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(input.nativeElement.value).toEqual("loginValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           input.nativeElement.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(control.value).toEqual("updatedValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("should update DOM elements when rebinding the control group",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               new ControlGroup({"login": new Control("oldValue")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               new ControlGroup({"login": new Control("newValue")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(input.nativeElement.value).toEqual("newValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("should update DOM elements when updating the value of a control",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var login = new Control("oldValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         var form = new ControlGroup({"login": login});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           login.updateValue("newValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 10:41:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(input.nativeElement.value).toEqual("newValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should mark controls as touched after interacting with the DOM control",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var login = new Control("oldValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         var form = new ControlGroup({"login": login});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var loginEl = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(login.touched).toBe(false);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           dispatchEvent(loginEl.nativeElement, "blur");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           expect(login.touched).toBe(true);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe("different control types", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <input type=text>",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="text" ngControl="text">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"text": new Control("old")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.value).toEqual("old");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "new";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": "new"});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should support <input> without type",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input ngControl="text">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"text": new Control("old")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.value).toEqual("old");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "new";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": "new"});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <textarea>",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <textarea ngControl="text"></textarea>
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"text": new Control('old')});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var textarea = fixture.debugElement.query(By.css("textarea"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(textarea.nativeElement.value).toEqual("old");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             textarea.nativeElement.value = "new";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(textarea.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"text": 'new'});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-11 18:50:41 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <type=checkbox>",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="checkbox" ngControl="checkbox">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"checkbox": new Control(true)});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.checked).toBe(true);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.checked = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "change");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"checkbox": false});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <type=number>",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="number" ngControl="num">
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"num": new Control(10)});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.value).toEqual("10");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "20";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"num": 20});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 11:38:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <select>",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <select ngControl="city">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <option value="SF"></option>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <option value="NYC"></option>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    </select>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"city": new Control("SF")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var select = fixture.debugElement.query(By.css("select"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var sfOption = fixture.debugElement.query(By.css("option"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(select.nativeElement.value).toEqual('SF');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(sfOption.nativeElement.selected).toBe(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             select.nativeElement.value = 'NYC';
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-16 15:30:29 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(select.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"city": 'NYC'});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sfOption.nativeElement.selected).toBe(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-13 12:15:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support <select> with a dynamic list of options",
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 08:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <select ngControl="city">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        <option *ngFor="#c of data" [value]="c"></option>
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-13 12:15:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      </select>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      (compFixture) => fixture = compFixture);
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 08:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-13 12:15:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 08:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      new ControlGroup({"city": new Control("NYC")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.data = ['SF', 'NYC'];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 08:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var select = fixture.debugElement.query(By.css('select'));
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-30 08:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(select.nativeElement.value).toEqual('NYC');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-13 12:15:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should support custom value accessors",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="text" ngControl="name" wrapped-value>
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"name": new Control("aa")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.value).toEqual("!aa!");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "!bb!";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should support custom value accessors on non builtin input elements that fire a change event without a 'target' property",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <my-input ngControl="name"></my-input>
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form =
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 new ControlGroup({"name": new Control("aa")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("my-input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.componentInstance.value).toEqual("!aa!");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             input.componentInstance.value = "!bb!";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             ObservableWrapper.subscribe(input.componentInstance.onInput, (value) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               expect(fixture.debugElement.componentInstance.form.value).toEqual({"name": "bb"});
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             input.componentInstance.dispatchChangeEvent();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe("validations", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should use sync validators defined in html",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 14:38:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var form = new ControlGroup(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               {"login": new Control(""), "min": new Control(""), "max": new Control("")});
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form" login-is-empty-validator>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <input type="text" ngControl="login" required>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <input type="text" ngControl="min" minlength="3">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <input type="text" ngControl="max" maxlength="3">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var required = fixture.debugElement.query(By.css("[required]"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var minLength = fixture.debugElement.query(By.css("[minlength]"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var maxLength = fixture.debugElement.query(By.css("[maxlength]"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 14:38:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             required.nativeElement.value = "";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             minLength.nativeElement.value = "1";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             maxLength.nativeElement.value = "1234";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(required.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(minLength.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(maxLength.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 14:38:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(form.hasError("required", ["login"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(form.hasError("minlength", ["min"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(form.hasError("maxlength", ["max"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-27 14:36:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(form.hasError("loginIsEmpty")).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 14:38:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             required.nativeElement.value = "1";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             minLength.nativeElement.value = "123";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             maxLength.nativeElement.value = "123";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(required.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(minLength.nativeElement, "input");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(maxLength.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-13 14:38:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             expect(form.valid).toEqual(true);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should use async validators defined in the html",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var form = new ControlGroup({"login": new Control("")});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <input type="text" ngControl="login" uniq-login-validator="expected">
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var rootTC;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => rootTC = root);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  rootTC.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  rootTC.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.pending).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick(100);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.hasError("uniqLogin", ["login"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var input = rootTC.debugElement.query(By.css("input"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  input.nativeElement.value = "expected";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick(100);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.valid).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should use sync validators defined in the model",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var form = new ControlGroup({"login": new Control("aa", Validators.required)});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(form.valid).toEqual(true);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(form.valid).toEqual(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should use async validators defined in the model",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var control =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      new Control("", Validators.required, uniqLoginAsyncValidator("expected"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var form = new ControlGroup({"login": control});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => fixture =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                                               root);
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.hasError("required", ["login"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  input.nativeElement.value = "wrong value";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.pending).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.hasError("uniqLogin", ["login"])).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  input.nativeElement.value = "expected";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.valid).toEqual(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe("nested forms", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should init DOM with the given form object",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var form =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               new ControlGroup({"nested": new ControlGroup({"login": new Control("value")})});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <div ngControlGroup="nested">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  </div>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.nativeElement.value).toEqual("value");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should update the control group values on DOM change",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var form =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               new ControlGroup({"nested": new ControlGroup({"login": new Control("value")})});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div [ngFormModel]="form">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    <div ngControlGroup="nested">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    </div>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                </div>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.nativeElement.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input.nativeElement, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(form.value).toEqual({"nested": {"login": "updatedValue"}});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should support ngModel for complex forms",
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject(
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           [TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var form = new ControlGroup({"name": new Control("")});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             var t =
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                 `<div [ngFormModel]="form"><input type="text" ngControl="name" [(ngModel)]="name"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var fixture: ComponentFixture;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.name = 'oldValue';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(input.value).toEqual("oldValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           })));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("should support ngModel for single fields",
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var form = new Control("");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var t = `<div><input type="text" [ngFormControl]="form" [(ngModel)]="name"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var fixture: ComponentFixture;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    (root) => { fixture = root; });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                tick();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                fixture.debugElement.componentInstance.name = "oldValue";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                expect(input.value).toEqual("oldValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    describe("template-driven forms", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should add new controls and control groups",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<form>
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                     <div ngControlGroup="user">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                     </div>
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = null;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['user']).not.toBeDefined();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['user']).toBeDefined();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['user'].controls['login']).toBeDefined();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should emit ngSubmit event on submit",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<div><form (ngSubmit)="name='updated'"></form></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = 'old';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var form = fixture.debugElement.query(By.css("form"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(form.nativeElement, "submit");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(fixture.debugElement.componentInstance.name).toEqual("updated");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-05 14:29:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should not create a template-driven form when ngNoForm is used",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<form ngNoForm>
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </form>`;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.name = null;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(fixture.debugElement.componentViewChildren.length).toEqual(0);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should remove controls",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var t = `<form>
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    <div *ngIf="name == 'show'">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    </div>
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  </form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = 'show';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['login']).toBeDefined();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = 'hide';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['login']).not.toBeDefined();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should remove control groups",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<form>
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                     <div *ngIf="name=='show'" ngControlGroup="user">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      <input type="text" ngControl="login">
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                     </div>
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-01 13:11:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = 'show';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var form = fixture.debugElement.componentViewChildren[0].inject(NgForm);
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['user']).toBeDefined();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = 'hide';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(form.controls['user']).not.toBeDefined();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support ngModel for complex forms",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 14:53:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<form>
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      <input type="text" ngControl="name" [(ngModel)]="name">
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 14:53:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								               </form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = "oldValue";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(input.value).toEqual("oldValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should support ngModel for single fields",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<div><input type="text" [(ngModel)]="name"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = "oldValue";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(input.value).toEqual("oldValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(fixture.debugElement.componentInstance.name).toEqual("updatedValue");
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-31 12:24:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe("setting status classes", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should work with single fields",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var form = new Control("", Validators.required);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div><input type="text" [ngFormControl]="form"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(['ng-invalid', 'ng-pristine', 'ng-untouched']);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "blur");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should work with complex model-driven forms",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           var form = new ControlGroup({"name": new Control("", Validators.required)});
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<form [ngFormModel]="form"><input type="text" ngControl="name"></form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-untouched"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "blur");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should work with ngModel",
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           var t = `<div><input [(ngModel)]="name" required></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								           tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((fixture) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.debugElement.componentInstance.name = "";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-untouched"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "blur");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-invalid", "ng-pristine", "ng-touched"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             input.value = "updatedValue";
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             expect(sortedClassList(input)).toEqual(["ng-dirty", "ng-touched", "ng-valid"]);
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-24 21:51:37 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								             async.done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         }));
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-03 11:56:01 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    describe("ngModel corner cases", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should not update the view when the value initially came from the view",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var form = new Control("");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  var t =
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      `<div><input type="text" [ngFormControl]="form" [(ngModel)]="name"></div>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.form = form;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-19 16:47:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  // In Firefox, effective text selection in the real DOM requires an actual focus
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // of the field. This is not an issue in a new HTML document.
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-24 15:41:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  if (browserDetection.isFirefox) {
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-19 16:47:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    var fakeDoc = DOM.createHtmlDocument();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    DOM.appendChild(fakeDoc.body, fixture.debugElement.nativeElement);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-19 16:47:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  input.value = "aa";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  input.selectionStart = 1;
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // selection start has not changed because we did not reset the value
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(input.selectionStart).toEqual(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it("should update the view when the model is set back to what used to be in the view",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<input type="text" [(ngModel)]="name">`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = "";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // Type "aa" into the input.
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var input = fixture.debugElement.query(By.css("input")).nativeElement;
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  input.value = "aa";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  input.selectionStart = 1;
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  dispatchEvent(input, "input");
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  expect(fixture.debugElement.componentInstance.name).toEqual("aa");
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // Programatically update the input value to be "bb".
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = "bb";
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(input.value).toEqual("bb");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // Programatically set it back to "aa".
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.debugElement.componentInstance.name = "aa";
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-18 21:42:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  expect(input.value).toEqual("aa");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-23 12:37:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it("should not crash when validity is checked from a binding",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								         inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // {{x.valid}} used to crash because valid() tried to read a property
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // from form.control before it was set. This test verifies this bug is
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  // fixed.
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-23 16:02:19 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var t = `<form><div ngControlGroup="x" #x="ngForm">
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                  <input type="text" ngControl="test"></div>{{x.valid}}</form>`;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  var fixture: ComponentFixture;
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-23 12:37:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      (root) => { fixture = root; });
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-23 12:37:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  tick();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                  fixture.detectChanges();
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-23 12:37:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                })));
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-15 18:16:50 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@Directive({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  selector: '[wrapped-value]',
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  host: {'(input)': 'handleOnInput($event.target.value)', '[value]': 'value'}
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								})
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class WrappedValue implements ControlValueAccessor {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  value;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  onChange: Function;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-10 13:51:44 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  constructor(cd: NgControl) { cd.valueAccessor = this; }
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  writeValue(value) { this.value = `!${value}!`; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  registerOnChange(fn) { this.onChange = fn; }
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-02 08:41:33 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  registerOnTouched(fn) {}
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-30 11:56:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  handleOnInput(value) { this.onChange(value.substring(1, value.length - 1)); }
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@Component({selector: "my-input", template: ''})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class MyInput implements ControlValueAccessor {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  @Output('input') onInput: EventEmitter<any> = new EventEmitter();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  value: string;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  constructor(cd: NgControl) { cd.valueAccessor = this; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  writeValue(value) { this.value = `!${value}!`; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  registerOnChange(fn) { ObservableWrapper.subscribe(this.onInput, fn); }
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  registerOnTouched(fn) {}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  dispatchChangeEvent() {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-20 17:19:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ObservableWrapper.callEmit(this.onInput, this.value.substring(1, this.value.length - 1));
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-23 14:06:46 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function uniqLoginAsyncValidator(expectedValue: string) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return (c) => {
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    var completer = PromiseWrapper.completer();
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    var res = (c.value == expectedValue) ? null : {"uniqLogin": true};
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    completer.resolve(res);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return completer.promise;
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-29 17:45:15 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-27 14:36:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function loginIsEmptyGroupValidator(c: ControlGroup) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return c.controls["login"].value == "" ? {"loginIsEmpty": true} : null;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								@Directive({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  selector: '[login-is-empty-validator]',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  providers: [new Provider(NG_VALIDATORS, {useValue: loginIsEmptyGroupValidator, multi: true})]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class LoginIsEmptyValidator {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@Directive({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  selector: '[uniq-login-validator]',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  providers: [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    new Provider(NG_ASYNC_VALIDATORS,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                 {useExisting: forwardRef(() => UniqLoginValidator), multi: true})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class UniqLoginValidator implements Validator {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  @Input('uniq-login-validator') expected;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  validate(c) { return uniqLoginAsyncValidator(this.expected)(c); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-27 14:36:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								@Component({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  selector: "my-comp",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  template: '',
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-02 10:00:42 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  directives: [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    FORM_DIRECTIVES,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    WrappedValue,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MyInput,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NgIf,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NgFor,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    LoginIsEmptyValidator,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    UniqLoginValidator
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ]
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-27 14:36:13 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								})
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class MyComp {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  form: any;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  name: string;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-13 12:15:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  data: any;
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-04 09:58:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-01 10:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function sortedClassList(el) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  var l = DOM.classList(el);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  ListWrapper.sort(l);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return l;
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-08 11:17:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 |