From 15fc5dd7eefc7c290d762b6dac0c313a94d45a0e Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Tue, 18 Oct 2016 07:51:13 +0200 Subject: [PATCH] test(forms): added missing selfOnly tests (#12317) --- .../@angular/forms/test/form_array_spec.ts | 21 ++++++++++++++++++ .../@angular/forms/test/form_control_spec.ts | 6 +++++ .../@angular/forms/test/form_group_spec.ts | 22 ++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/@angular/forms/test/form_array_spec.ts b/modules/@angular/forms/test/form_array_spec.ts index 76ba0644db..bc78e9edc5 100644 --- a/modules/@angular/forms/test/form_array_spec.ts +++ b/modules/@angular/forms/test/form_array_spec.ts @@ -123,6 +123,13 @@ export function main() { expect(form.value).toEqual({'parent': ['one', 'two']}); }); + it('should not update the parent explicitly specified', () => { + const form = new FormGroup({'parent': a}); + a.setValue(['one', 'two'], {onlySelf: true}); + + expect(form.value).toEqual({parent: ['', '']}); + }); + it('should throw if fields are missing from supplied value (subset)', () => { expect(() => a.setValue([, 'two'])) .toThrowError(new RegExp(`Must supply a value for form control at index: 0`)); @@ -219,6 +226,13 @@ export function main() { expect(form.value).toEqual({'parent': ['one', 'two']}); }); + it('should not update the parent explicitly specified', () => { + const form = new FormGroup({'parent': a}); + a.patchValue(['one', 'two'], {onlySelf: true}); + + expect(form.value).toEqual({parent: ['', '']}); + }); + it('should ignore fields that are missing from supplied value (subset)', () => { a.patchValue([, 'two']); expect(a.value).toEqual(['', 'two']); @@ -291,6 +305,13 @@ export function main() { expect(a.value).toEqual(['initial value', '']); }); + it('should not update the parent when explicitly specified', () => { + const form = new FormGroup({'a': a}); + a.reset(['one', 'two'], {onlySelf: true}); + + expect(form.value).toEqual({a: ['initial value', '']}); + }); + it('should set its own value if boxed value passed', () => { a.setValue(['new value', 'new value']); diff --git a/modules/@angular/forms/test/form_control_spec.ts b/modules/@angular/forms/test/form_control_spec.ts index 4087d914e5..d97530dd20 100644 --- a/modules/@angular/forms/test/form_control_spec.ts +++ b/modules/@angular/forms/test/form_control_spec.ts @@ -429,6 +429,12 @@ export function main() { expect(c.value).toBe('initial value'); }); + it('should not set the parent when explicitly specified', () => { + const g = new FormGroup({'one': c}); + c.patchValue('newValue', {onlySelf: true}); + expect(g.value).toEqual({'one': 'initial value'}); + }); + it('should reset to a specific value if passed with boxed value', () => { c.setValue('new value'); expect(c.value).toBe('new value'); diff --git a/modules/@angular/forms/test/form_group_spec.ts b/modules/@angular/forms/test/form_group_spec.ts index 0c1d131d26..f0c7cf7c91 100644 --- a/modules/@angular/forms/test/form_group_spec.ts +++ b/modules/@angular/forms/test/form_group_spec.ts @@ -185,6 +185,13 @@ export function main() { expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}}); }); + it('should not update the parent when explicitly specified', () => { + const form = new FormGroup({'parent': g}); + g.setValue({'one': 'one', 'two': 'two'}, {onlySelf: true}); + + expect(form.value).toEqual({parent: {'one': '', 'two': ''}}); + }); + it('should throw if fields are missing from supplied value (subset)', () => { expect(() => g.setValue({ 'one': 'one' @@ -283,6 +290,13 @@ export function main() { expect(form.value).toEqual({'parent': {'one': 'one', 'two': 'two'}}); }); + it('should not update the parent when explicitly specified', () => { + const form = new FormGroup({'parent': g}); + g.patchValue({'one': 'one', 'two': 'two'}, {onlySelf: true}); + + expect(form.value).toEqual({parent: {'one': '', 'two': ''}}); + }); + it('should ignore fields that are missing from supplied value (subset)', () => { g.patchValue({'one': 'one'}); expect(g.value).toEqual({'one': 'one', 'two': ''}); @@ -401,6 +415,13 @@ export function main() { expect(form.value).toEqual({'g': {'one': null, 'two': null}}); }); + it('should not update the parent when explicitly specified', () => { + const form = new FormGroup({'g': g}); + g.reset({'one': 'new value', 'two': 'new value'}, {onlySelf: true}); + + expect(form.value).toEqual({g: {'one': 'initial value', 'two': ''}}); + }); + it('should mark itself as pristine', () => { g.markAsDirty(); expect(g.pristine).toBe(false); @@ -541,7 +562,6 @@ export function main() { g.reset({'one': {value: '', disabled: true}}); expect(logger).toEqual(['control1', 'control2', 'group', 'form']); }); - }); });