From cfd78bdccce80ec4c1a875891604efa45f539e7c Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Mon, 5 Aug 2019 17:53:43 +0200 Subject: [PATCH] fix(field): added Date support to InteractionStateMixin --- packages/field/src/InteractionStateMixin.js | 2 +- packages/field/test-suites/InteractionStateMixin.suite.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/field/src/InteractionStateMixin.js b/packages/field/src/InteractionStateMixin.js index 91a2e02a1..9e7deb32d 100644 --- a/packages/field/src/InteractionStateMixin.js +++ b/packages/field/src/InteractionStateMixin.js @@ -60,7 +60,7 @@ export const InteractionStateMixin = dedupeMixin( value = modelValue.viewValue; } // Checks for empty platform types: Objects, Arrays, Dates - if (typeof value === 'object' && value !== null) { + if (typeof value === 'object' && value !== null && !(value instanceof Date)) { return !!Object.keys(value).length; } // eslint-disable-next-line no-mixed-operators diff --git a/packages/field/test-suites/InteractionStateMixin.suite.js b/packages/field/test-suites/InteractionStateMixin.suite.js index 8d6cff351..2c7b3b7b4 100644 --- a/packages/field/test-suites/InteractionStateMixin.suite.js +++ b/packages/field/test-suites/InteractionStateMixin.suite.js @@ -14,7 +14,7 @@ import { InteractionStateMixin } from '../src/InteractionStateMixin.js'; export function runInteractionStateMixinSuite(customConfig) { const cfg = { tagString: null, - allowedModelValueTypes: [Array, Object, Number, Boolean, String], + allowedModelValueTypes: [Array, Object, Number, Boolean, String, Date], suffix: '', ...customConfig, }; @@ -154,6 +154,10 @@ export function runInteractionStateMixinSuite(customConfig) { changeModelValueAndLeave(''); expect(el.prefilled, 'empty string should not be "prefilled"').to.be.false; } + if (cfg.allowedModelValueTypes.includes(Date)) { + changeModelValueAndLeave(new Date()); + expect(el.prefilled, 'Dates should be "prefilled"').to.be.true; + } // Not prefilled changeModelValueAndLeave(null);