`;
-
- let fixture = tcb.overrideTemplate(MyComp8, t).createFakeAsync(MyComp8);
- tick();
-
- fixture.debugElement.componentInstance.form = new FormGroup({});
- fixture.debugElement.componentInstance.name = 'old';
-
- tick();
-
- var form = fixture.debugElement.query(By.css('form'));
- dispatchEvent(form.nativeElement, 'submit');
-
- tick();
- expect(fixture.debugElement.componentInstance.name).toEqual('updated');
- })));
-
- it('should mark formGroup as submitted on submit event',
- fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
- const t = `
-
- {{data}}
-
`;
-
- var fixture: ComponentFixture;
-
- tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((root) => { fixture = root; });
- tick();
-
- fixture.debugElement.componentInstance.form = new FormGroup({});
- fixture.debugElement.componentInstance.data = false;
-
- tick();
-
- var form = fixture.debugElement.query(By.css('form'));
- dispatchEvent(form.nativeElement, 'submit');
-
- tick();
- expect(fixture.debugElement.componentInstance.data).toEqual(true);
- })));
-
- it('should work with single controls',
- inject(
- [TestComponentBuilder, AsyncTestCompleter],
- (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
- var control = new FormControl('loginValue');
-
- const t = ``;
-
- tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
- fixture.debugElement.componentInstance.form = control;
- fixture.detectChanges();
-
- var input = fixture.debugElement.query(By.css('input'));
- expect(input.nativeElement.value).toEqual('loginValue');
-
- input.nativeElement.value = 'updatedValue';
- dispatchEvent(input.nativeElement, 'input');
-
- expect(control.value).toEqual('updatedValue');
- async.done();
- });
- }));
-
- it('should update DOM elements when rebinding the form group',
- inject(
- [TestComponentBuilder, AsyncTestCompleter],
- (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
- const t = `
-
-
`;
-
- tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
- fixture.debugElement.componentInstance.form =
- new FormGroup({'login': new FormControl('oldValue')});
- fixture.detectChanges();
-
- fixture.debugElement.componentInstance.form =
- new FormGroup({'login': new FormControl('newValue')});
- fixture.detectChanges();
-
- var input = fixture.debugElement.query(By.css('input'));
- expect(input.nativeElement.value).toEqual('newValue');
- async.done();
- });
- }));
-
- it('should update DOM elements when updating the value of a control',
- inject(
- [TestComponentBuilder, AsyncTestCompleter],
- (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
- var login = new FormControl('oldValue');
- var form = new FormGroup({'login': login});
-
- const t = `
-
-
`;
-
- tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
- fixture.debugElement.componentInstance.form = form;
- fixture.detectChanges();
-
- login.setValue('newValue');
-
- fixture.detectChanges();
-
- var input = fixture.debugElement.query(By.css('input'));
- expect(input.nativeElement.value).toEqual('newValue');
- async.done();
- });
- }));
-
- it('should mark controls as touched after interacting with the DOM control',
- inject(
- [TestComponentBuilder, AsyncTestCompleter],
- (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
- var login = new FormControl('oldValue');
- var form = new FormGroup({'login': login});
-
- const t = `
-
-
`;
-
- tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => {
- fixture.debugElement.componentInstance.form = form;
- fixture.detectChanges();
-
- var loginEl = fixture.debugElement.query(By.css('input'));
- expect(login.touched).toBe(false);
-
- dispatchEvent(loginEl.nativeElement, 'blur');
-
- expect(login.touched).toBe(true);
-
- async.done();
- });
- }));
-
- it('should mark controls as dirty before emitting a value change event',
- inject(
- [TestComponentBuilder, AsyncTestCompleter],
- (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
- const login = new FormControl('oldValue');
- const form = new FormGroup({'login': login});
-
- const t = `