From 795c7ab31d373a31a9e3e685de70f6ffdd0de188 Mon Sep 17 00:00:00 2001 From: "volkov.vladislav" Date: Tue, 11 Apr 2017 12:19:03 +0300 Subject: [PATCH 1/3] Fix watcher for changes in dxDateBox --- src/core/watcher-helper.ts | 3 ++- tests/src/ui/form.spec.ts | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/core/watcher-helper.ts b/src/core/watcher-helper.ts index 4c543754d..237189275 100644 --- a/src/core/watcher-helper.ts +++ b/src/core/watcher-helper.ts @@ -39,7 +39,8 @@ export class WatcherHelper { } private _isDifferentValues(oldValue: any, newValue: any, deepCheck: boolean) { - if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object)) { + if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object) && + !(oldValue instanceof Date && newValue instanceof Date)) { return this._checkObjectsFields(newValue, oldValue); } return oldValue !== newValue; diff --git a/tests/src/ui/form.spec.ts b/tests/src/ui/form.spec.ts index cf6040389..f82ada3fe 100644 --- a/tests/src/ui/form.spec.ts +++ b/tests/src/ui/form.spec.ts @@ -25,7 +25,8 @@ import { }) class TestContainerComponent { formData = { - name: 'Unknown' + name: 'Unknown', + date: new Date() }; @ViewChildren(DxFormComponent) innerWidgets: QueryList; } @@ -114,4 +115,24 @@ describe('DxForm', () => { expect(formInstance.option('formData.name')).toEqual([2]); })); + + it('should change the value of dxDateBox', async(() => { + TestBed.overrideComponent(TestContainerComponent, { + set: { + template: ` + + + + ` + } + }); + let fixture = TestBed.createComponent(TestContainerComponent); + fixture.detectChanges(); + + this.formData.date = new Date(2017, 0, 1); + let formInstance = getWidget(fixture); + let dateBoxInstance = formInstance.getEditor('date'); + + expect(dateBoxInstance.option('value')).toEqual(new Date(2017, 0, 1)); + })); }); From 319ba550a8340b2b18893417979a925d81256f46 Mon Sep 17 00:00:00 2001 From: "volkov.vladislav" Date: Tue, 11 Apr 2017 13:57:13 +0300 Subject: [PATCH 2/3] Fix tests --- tests/src/ui/form.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/src/ui/form.spec.ts b/tests/src/ui/form.spec.ts index f82ada3fe..21558fe91 100644 --- a/tests/src/ui/form.spec.ts +++ b/tests/src/ui/form.spec.ts @@ -121,15 +121,16 @@ describe('DxForm', () => { set: { template: ` - ` } }); let fixture = TestBed.createComponent(TestContainerComponent); fixture.detectChanges(); - - this.formData.date = new Date(2017, 0, 1); + + fixture.componentInstance.formData.date = new Date(2017, 0, 1); + fixture.detectChanges(); + let formInstance = getWidget(fixture); let dateBoxInstance = formInstance.getEditor('date'); From fb73fd6779ad36f221b67847ec3ad8e1c4e88890 Mon Sep 17 00:00:00 2001 From: "volkov.vladislav" Date: Tue, 11 Apr 2017 15:25:58 +0300 Subject: [PATCH 3/3] Refactoring --- src/core/watcher-helper.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/watcher-helper.ts b/src/core/watcher-helper.ts index 237189275..2e1a441f3 100644 --- a/src/core/watcher-helper.ts +++ b/src/core/watcher-helper.ts @@ -39,8 +39,10 @@ export class WatcherHelper { } private _isDifferentValues(oldValue: any, newValue: any, deepCheck: boolean) { - if (deepCheck && newValue instanceof (Object) && oldValue instanceof (Object) && - !(oldValue instanceof Date && newValue instanceof Date)) { + let isObjectValues = newValue instanceof Object && oldValue instanceof Object, + isDateValues = oldValue instanceof Date && newValue instanceof Date; + + if (deepCheck && isObjectValues && !isDateValues) { return this._checkObjectsFields(newValue, oldValue); } return oldValue !== newValue;