From 0445b86350f65649c03ed84bfaf9652838c43e55 Mon Sep 17 00:00:00 2001 From: Joren Broekema Date: Thu, 12 Mar 2020 15:37:09 +0100 Subject: [PATCH] fix(choice-input): fix serializedValue setter check --- packages/choice-input/src/ChoiceGroupMixin.js | 4 ++-- .../choice-input/test/ChoiceGroupMixin.test.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/choice-input/src/ChoiceGroupMixin.js b/packages/choice-input/src/ChoiceGroupMixin.js index f7543c626..4d23092bf 100644 --- a/packages/choice-input/src/ChoiceGroupMixin.js +++ b/packages/choice-input/src/ChoiceGroupMixin.js @@ -1,5 +1,5 @@ import { dedupeMixin } from '@lion/core'; -import { InteractionStateMixin, FormRegistrarMixin } from '@lion/field'; +import { FormRegistrarMixin, InteractionStateMixin } from '@lion/field'; export const ChoiceGroupMixin = dedupeMixin( superclass => @@ -49,7 +49,7 @@ export const ChoiceGroupMixin = dedupeMixin( } set serializedValue(value) { - this._setCheckedElements(value, (el, val) => el.serializedValue === val); + this._setCheckedElements(value, (el, val) => el.serializedValue.value === val); } constructor() { diff --git a/packages/choice-input/test/ChoiceGroupMixin.test.js b/packages/choice-input/test/ChoiceGroupMixin.test.js index 5d1f01f32..d3e7d2e97 100644 --- a/packages/choice-input/test/ChoiceGroupMixin.test.js +++ b/packages/choice-input/test/ChoiceGroupMixin.test.js @@ -1,11 +1,11 @@ import { html, LitElement } from '@lion/core'; import { FormGroupMixin } from '@lion/fieldset'; +import '@lion/fieldset/lion-fieldset.js'; import { LionInput } from '@lion/input'; import { Required } from '@lion/validate'; import { expect, fixture, nextFrame } from '@open-wc/testing'; import { ChoiceGroupMixin } from '../src/ChoiceGroupMixin.js'; import { ChoiceInputMixin } from '../src/ChoiceInputMixin.js'; -import '@lion/fieldset/lion-fieldset.js'; describe('ChoiceGroupMixin', () => { before(() => { @@ -116,6 +116,18 @@ describe('ChoiceGroupMixin', () => { expect(el.formElements[2].checked).to.be.true; }); + it('can set initial serializedValue on creation', async () => { + const el = await fixture(html` + + + + + + `); + + expect(el.serializedValue).to.equal('other'); + }); + it('can handle complex data via choiceValue', async () => { const date = new Date(2018, 11, 24, 10, 33, 30, 0);