From 5354e1a0db749c3dba6b0a867185866103231aa5 Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Tue, 6 Apr 2021 15:41:36 +0200 Subject: [PATCH] chore(form-core): test initial dirty state prefilled FormGroup --- .../form-group/FormGroupMixin.suite.js | 18 +++++ .../test/form-integrations.test.js | 80 +++++++++++++------ .../test/helpers/umbrella-form.js | 60 ++++++++++---- 3 files changed, 116 insertions(+), 42 deletions(-) diff --git a/packages/form-core/test-suites/form-group/FormGroupMixin.suite.js b/packages/form-core/test-suites/form-group/FormGroupMixin.suite.js index c3cac196b..eaff0141e 100644 --- a/packages/form-core/test-suites/form-group/FormGroupMixin.suite.js +++ b/packages/form-core/test-suites/form-group/FormGroupMixin.suite.js @@ -670,6 +670,24 @@ export function runFormGroupMixinSuite(cfg = {}) { expect(el.validationStates.error.Input1IsTen).to.be.true; expect(el.hasFeedbackFor).to.deep.equal(['error']); }); + + it('does not become dirty when elements are prefilled', async () => { + const el = /** @type {FormGroup} */ (await fixture(html` + <${tag} .serializedValue="${{ input1: 'x', input2: 'y' }}"> + <${childTag} name="input1" > + <${childTag} name="input2"> + + `)); + expect(el.dirty).to.be.false; + + const el2 = /** @type {FormGroup} */ (await fixture(html` + <${tag} .modelValue="${{ input1: 'x', input2: 'y' }}"> + <${childTag} name="input1" > + <${childTag} name="input2"> + + `)); + expect(el2.dirty).to.be.false; + }); }); // TODO: this should be tested in FormGroupMixin diff --git a/packages/form-integrations/test/form-integrations.test.js b/packages/form-integrations/test/form-integrations.test.js index a9b024778..6e29980b9 100644 --- a/packages/form-integrations/test/form-integrations.test.js +++ b/packages/form-integrations/test/form-integrations.test.js @@ -11,24 +11,24 @@ describe('Form Integrations', () => { const el = /** @type {UmbrellaForm} */ (await fixture(html``)); await el.updateComplete; const formEl = el._lionFormNode; + expect(formEl.serializedValue).to.eql({ - bio: '', - 'checkers[]': [['foo', 'bar']], - comments: '', + full_name: { first_name: '', last_name: '' }, date: '2000-12-12', datepicker: '2020-12-12', - dinosaurs: 'brontosaurus', - email: '', - favoriteColor: 'hotpink', - full_name: { - first_name: '', - last_name: '', - }, - iban: '', - lyrics: '1', + bio: '', money: '', + iban: '', + email: '', + checkers: ['foo', 'bar'], + dinosaurs: '', + favoriteFruit: 'Banana', + favoriteMovie: 'Rocky', + favoriteColor: 'hotpink', + lyrics: '1', range: 2.3, - 'terms[]': [[]], + terms: [], + comments: '', }); }); @@ -37,23 +37,51 @@ describe('Form Integrations', () => { await el.updateComplete; const formEl = el._lionFormNode; expect(formEl.formattedValue).to.eql({ - bio: '', - 'checkers[]': [['foo', 'bar']], - comments: '', + full_name: { first_name: '', last_name: '' }, date: '12/12/2000', datepicker: '12/12/2020', - dinosaurs: 'brontosaurus', - email: '', - favoriteColor: 'hotpink', - full_name: { - first_name: '', - last_name: '', - }, - iban: '', - lyrics: '1', + bio: '', money: '', + iban: '', + email: '', + checkers: ['foo', 'bar'], + dinosaurs: '', + favoriteFruit: 'Banana', + favoriteMovie: 'Rocky', + favoriteColor: 'hotpink', + lyrics: '1', range: 2.3, - 'terms[]': [[]], + terms: [], + comments: '', + }); + }); + + describe('Form Integrations', () => { + it('does not become dirty when elements are prefilled', async () => { + const el = /** @type {UmbrellaForm} */ (await fixture( + html``, + )); + + expect(el._lionFormNode.dirty).to.be.false; }); }); }); diff --git a/packages/form-integrations/test/helpers/umbrella-form.js b/packages/form-integrations/test/helpers/umbrella-form.js index fb60807ff..ccfdfee4b 100644 --- a/packages/form-integrations/test/helpers/umbrella-form.js +++ b/packages/form-integrations/test/helpers/umbrella-form.js @@ -12,6 +12,8 @@ import '@lion/checkbox-group/define'; import '@lion/radio-group/define'; import '@lion/select/define'; import '@lion/select-rich/define'; +import '@lion/listbox/define'; +import '@lion/combobox/define'; import '@lion/input-range/define'; import '@lion/textarea/define'; import '@lion/button/define'; @@ -23,9 +25,13 @@ export class UmbrellaForm extends LitElement { )); } + set serializedValue(v) { + this.__serializedValue = v; + } + render() { return html` - +
@@ -75,15 +81,31 @@ export class UmbrellaForm extends LitElement { .validators="${[new Required()]}" > - + + + Apple + Banana + Mango + + + Rocky + Rocky II + Rocky III + Rocky IV + Rocky V + Rocky Balboa + - - Red - Hotpink - Teal - + Red + Hotpink + Teal