fix(field): added Date support to InteractionStateMixin

This commit is contained in:
Thijs Louisse 2019-08-05 17:53:43 +02:00
parent 22bb75a868
commit cfd78bdccc
2 changed files with 6 additions and 2 deletions

View file

@ -60,7 +60,7 @@ export const InteractionStateMixin = dedupeMixin(
value = modelValue.viewValue; value = modelValue.viewValue;
} }
// Checks for empty platform types: Objects, Arrays, Dates // 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; return !!Object.keys(value).length;
} }
// eslint-disable-next-line no-mixed-operators // eslint-disable-next-line no-mixed-operators

View file

@ -14,7 +14,7 @@ import { InteractionStateMixin } from '../src/InteractionStateMixin.js';
export function runInteractionStateMixinSuite(customConfig) { export function runInteractionStateMixinSuite(customConfig) {
const cfg = { const cfg = {
tagString: null, tagString: null,
allowedModelValueTypes: [Array, Object, Number, Boolean, String], allowedModelValueTypes: [Array, Object, Number, Boolean, String, Date],
suffix: '', suffix: '',
...customConfig, ...customConfig,
}; };
@ -154,6 +154,10 @@ export function runInteractionStateMixinSuite(customConfig) {
changeModelValueAndLeave(''); changeModelValueAndLeave('');
expect(el.prefilled, 'empty string should not be "prefilled"').to.be.false; 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 // Not prefilled
changeModelValueAndLeave(null); changeModelValueAndLeave(null);