chore(form-core): test initial dirty state prefilled FormGroup
This commit is contained in:
parent
97b8592cd9
commit
5354e1a0db
3 changed files with 116 additions and 42 deletions
|
|
@ -670,6 +670,24 @@ export function runFormGroupMixinSuite(cfg = {}) {
|
||||||
expect(el.validationStates.error.Input1IsTen).to.be.true;
|
expect(el.validationStates.error.Input1IsTen).to.be.true;
|
||||||
expect(el.hasFeedbackFor).to.deep.equal(['error']);
|
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}>
|
||||||
|
<${childTag} name="input2"></${childTag}>
|
||||||
|
</${tag}>
|
||||||
|
`));
|
||||||
|
expect(el.dirty).to.be.false;
|
||||||
|
|
||||||
|
const el2 = /** @type {FormGroup} */ (await fixture(html`
|
||||||
|
<${tag} .modelValue="${{ input1: 'x', input2: 'y' }}">
|
||||||
|
<${childTag} name="input1" ></${childTag}>
|
||||||
|
<${childTag} name="input2"></${childTag}>
|
||||||
|
</${tag}>
|
||||||
|
`));
|
||||||
|
expect(el2.dirty).to.be.false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: this should be tested in FormGroupMixin
|
// TODO: this should be tested in FormGroupMixin
|
||||||
|
|
|
||||||
|
|
@ -11,24 +11,24 @@ describe('Form Integrations', () => {
|
||||||
const el = /** @type {UmbrellaForm} */ (await fixture(html`<umbrella-form></umbrella-form>`));
|
const el = /** @type {UmbrellaForm} */ (await fixture(html`<umbrella-form></umbrella-form>`));
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
const formEl = el._lionFormNode;
|
const formEl = el._lionFormNode;
|
||||||
|
|
||||||
expect(formEl.serializedValue).to.eql({
|
expect(formEl.serializedValue).to.eql({
|
||||||
bio: '',
|
full_name: { first_name: '', last_name: '' },
|
||||||
'checkers[]': [['foo', 'bar']],
|
|
||||||
comments: '',
|
|
||||||
date: '2000-12-12',
|
date: '2000-12-12',
|
||||||
datepicker: '2020-12-12',
|
datepicker: '2020-12-12',
|
||||||
dinosaurs: 'brontosaurus',
|
bio: '',
|
||||||
email: '',
|
|
||||||
favoriteColor: 'hotpink',
|
|
||||||
full_name: {
|
|
||||||
first_name: '',
|
|
||||||
last_name: '',
|
|
||||||
},
|
|
||||||
iban: '',
|
|
||||||
lyrics: '1',
|
|
||||||
money: '',
|
money: '',
|
||||||
|
iban: '',
|
||||||
|
email: '',
|
||||||
|
checkers: ['foo', 'bar'],
|
||||||
|
dinosaurs: '',
|
||||||
|
favoriteFruit: 'Banana',
|
||||||
|
favoriteMovie: 'Rocky',
|
||||||
|
favoriteColor: 'hotpink',
|
||||||
|
lyrics: '1',
|
||||||
range: 2.3,
|
range: 2.3,
|
||||||
'terms[]': [[]],
|
terms: [],
|
||||||
|
comments: '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -37,23 +37,51 @@ describe('Form Integrations', () => {
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
const formEl = el._lionFormNode;
|
const formEl = el._lionFormNode;
|
||||||
expect(formEl.formattedValue).to.eql({
|
expect(formEl.formattedValue).to.eql({
|
||||||
bio: '',
|
full_name: { first_name: '', last_name: '' },
|
||||||
'checkers[]': [['foo', 'bar']],
|
|
||||||
comments: '',
|
|
||||||
date: '12/12/2000',
|
date: '12/12/2000',
|
||||||
datepicker: '12/12/2020',
|
datepicker: '12/12/2020',
|
||||||
dinosaurs: 'brontosaurus',
|
bio: '',
|
||||||
email: '',
|
|
||||||
favoriteColor: 'hotpink',
|
|
||||||
full_name: {
|
|
||||||
first_name: '',
|
|
||||||
last_name: '',
|
|
||||||
},
|
|
||||||
iban: '',
|
|
||||||
lyrics: '1',
|
|
||||||
money: '',
|
money: '',
|
||||||
|
iban: '',
|
||||||
|
email: '',
|
||||||
|
checkers: ['foo', 'bar'],
|
||||||
|
dinosaurs: '',
|
||||||
|
favoriteFruit: 'Banana',
|
||||||
|
favoriteMovie: 'Rocky',
|
||||||
|
favoriteColor: 'hotpink',
|
||||||
|
lyrics: '1',
|
||||||
range: 2.3,
|
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`<umbrella-form
|
||||||
|
.serializedValue="${{
|
||||||
|
full_name: { first_name: '', last_name: '' },
|
||||||
|
date: '2000-12-12',
|
||||||
|
datepicker: '2020-12-12',
|
||||||
|
bio: '',
|
||||||
|
money: '',
|
||||||
|
iban: '',
|
||||||
|
email: '',
|
||||||
|
checkers: ['foo', 'bar'],
|
||||||
|
dinosaurs: 'brontosaurus',
|
||||||
|
favoriteFruit: 'Banana',
|
||||||
|
favoriteMovie: 'Rocky',
|
||||||
|
favoriteColor: 'hotpink',
|
||||||
|
lyrics: '1',
|
||||||
|
range: 2.3,
|
||||||
|
terms: [],
|
||||||
|
comments: '',
|
||||||
|
}}"
|
||||||
|
></umbrella-form>`,
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(el._lionFormNode.dirty).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import '@lion/checkbox-group/define';
|
||||||
import '@lion/radio-group/define';
|
import '@lion/radio-group/define';
|
||||||
import '@lion/select/define';
|
import '@lion/select/define';
|
||||||
import '@lion/select-rich/define';
|
import '@lion/select-rich/define';
|
||||||
|
import '@lion/listbox/define';
|
||||||
|
import '@lion/combobox/define';
|
||||||
import '@lion/input-range/define';
|
import '@lion/input-range/define';
|
||||||
import '@lion/textarea/define';
|
import '@lion/textarea/define';
|
||||||
import '@lion/button/define';
|
import '@lion/button/define';
|
||||||
|
|
@ -23,9 +25,13 @@ export class UmbrellaForm extends LitElement {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set serializedValue(v) {
|
||||||
|
this.__serializedValue = v;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<lion-form>
|
<lion-form .serializedValue="${this.__serializedValue}">
|
||||||
<form>
|
<form>
|
||||||
<lion-fieldset name="full_name">
|
<lion-fieldset name="full_name">
|
||||||
<lion-input
|
<lion-input
|
||||||
|
|
@ -42,13 +48,13 @@ export class UmbrellaForm extends LitElement {
|
||||||
<lion-input-date
|
<lion-input-date
|
||||||
name="date"
|
name="date"
|
||||||
label="Date of application"
|
label="Date of application"
|
||||||
.modelValue="${new Date('2000/12/12')}"
|
.modelValue="${new Date('2000-12-12')}"
|
||||||
.validators="${[new Required()]}"
|
.validators="${[new Required()]}"
|
||||||
></lion-input-date>
|
></lion-input-date>
|
||||||
<lion-input-datepicker
|
<lion-input-datepicker
|
||||||
name="datepicker"
|
name="datepicker"
|
||||||
label="Date to be picked"
|
label="Date to be picked"
|
||||||
.modelValue="${new Date('2020/12/12')}"
|
.modelValue="${new Date('2020-12-12')}"
|
||||||
.validators="${[new Required()]}"
|
.validators="${[new Required()]}"
|
||||||
></lion-input-datepicker>
|
></lion-input-datepicker>
|
||||||
<lion-textarea
|
<lion-textarea
|
||||||
|
|
@ -62,7 +68,7 @@ export class UmbrellaForm extends LitElement {
|
||||||
<lion-input-email name="email" label="Email"></lion-input-email>
|
<lion-input-email name="email" label="Email"></lion-input-email>
|
||||||
<lion-checkbox-group
|
<lion-checkbox-group
|
||||||
label="What do you like?"
|
label="What do you like?"
|
||||||
name="checkers[]"
|
name="checkers"
|
||||||
.validators="${[new Required()]}"
|
.validators="${[new Required()]}"
|
||||||
>
|
>
|
||||||
<lion-checkbox .choiceValue=${'foo'} checked label="I like foo"></lion-checkbox>
|
<lion-checkbox .choiceValue=${'foo'} checked label="I like foo"></lion-checkbox>
|
||||||
|
|
@ -75,15 +81,31 @@ export class UmbrellaForm extends LitElement {
|
||||||
.validators="${[new Required()]}"
|
.validators="${[new Required()]}"
|
||||||
>
|
>
|
||||||
<lion-radio .choiceValue=${'allosaurus'} label="allosaurus"></lion-radio>
|
<lion-radio .choiceValue=${'allosaurus'} label="allosaurus"></lion-radio>
|
||||||
<lion-radio .choiceValue=${'brontosaurus'} checked label="brontosaurus"></lion-radio>
|
<lion-radio .choiceValue=${'brontosaurus'} label="brontosaurus"></lion-radio>
|
||||||
<lion-radio .choiceValue=${'diplodocus'} label="diplodocus"></lion-radio>
|
<lion-radio .choiceValue=${'diplodocus'} label="diplodocus"></lion-radio>
|
||||||
</lion-radio-group>
|
</lion-radio-group>
|
||||||
|
<lion-listbox name="favoriteFruit" label="Favorite fruit">
|
||||||
|
<lion-option .choiceValue=${'Apple'}>Apple</lion-option>
|
||||||
|
<lion-option checked .choiceValue=${'Banana'}>Banana</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Mango'}>Mango</lion-option>
|
||||||
|
</lion-listbox>
|
||||||
|
<lion-combobox
|
||||||
|
.validators="${[new Required()]}"
|
||||||
|
name="favoriteMovie"
|
||||||
|
label="Favorite movie"
|
||||||
|
autocomplete="both"
|
||||||
|
>
|
||||||
|
<lion-option checked .choiceValue=${'Rocky'}>Rocky</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Rocky II'}>Rocky II</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Rocky III'}>Rocky III</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Rocky IV'}>Rocky IV</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Rocky V'}>Rocky V</lion-option>
|
||||||
|
<lion-option .choiceValue=${'Rocky Balboa'}>Rocky Balboa</lion-option>
|
||||||
|
</lion-combobox>
|
||||||
<lion-select-rich name="favoriteColor" label="Favorite color">
|
<lion-select-rich name="favoriteColor" label="Favorite color">
|
||||||
<lion-options slot="input">
|
|
||||||
<lion-option .choiceValue=${'red'}>Red</lion-option>
|
<lion-option .choiceValue=${'red'}>Red</lion-option>
|
||||||
<lion-option .choiceValue=${'hotpink'} checked>Hotpink</lion-option>
|
<lion-option .choiceValue=${'hotpink'} checked>Hotpink</lion-option>
|
||||||
<lion-option .choiceValue=${'teal'}>Teal</lion-option>
|
<lion-option .choiceValue=${'teal'}>Teal</lion-option>
|
||||||
</lion-options>
|
|
||||||
</lion-select-rich>
|
</lion-select-rich>
|
||||||
<lion-select label="Lyrics" name="lyrics" .validators="${[new Required()]}">
|
<lion-select label="Lyrics" name="lyrics" .validators="${[new Required()]}">
|
||||||
<select slot="input">
|
<select slot="input">
|
||||||
|
|
@ -100,21 +122,27 @@ export class UmbrellaForm extends LitElement {
|
||||||
unit="%"
|
unit="%"
|
||||||
step="0.1"
|
step="0.1"
|
||||||
label="Input range"
|
label="Input range"
|
||||||
|
></lion-input-range>
|
||||||
|
<lion-checkbox-group
|
||||||
|
.mulipleChoice="${false}"
|
||||||
|
name="terms"
|
||||||
|
.validators="${[new Required()]}"
|
||||||
>
|
>
|
||||||
</lion-input-range>
|
|
||||||
<lion-checkbox-group name="terms[]" .validators="${[new Required()]}">
|
|
||||||
<lion-checkbox label="I blindly accept all terms and conditions"></lion-checkbox>
|
<lion-checkbox label="I blindly accept all terms and conditions"></lion-checkbox>
|
||||||
</lion-checkbox-group>
|
</lion-checkbox-group>
|
||||||
|
<lion-switch name="notifications" label="Notifications"></lion-switch>
|
||||||
|
<lion-input-stepper max="5" min="0" name="rsvp">
|
||||||
|
<label slot="label">RSVP</label>
|
||||||
|
<div slot="help-text">Max. 5 guests</div>
|
||||||
|
</lion-input-stepper>
|
||||||
<lion-textarea name="comments" label="Comments"></lion-textarea>
|
<lion-textarea name="comments" label="Comments"></lion-textarea>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<lion-button raised>Submit</lion-button>
|
<lion-button raised>Submit</lion-button>
|
||||||
<lion-button
|
<lion-button
|
||||||
type="button"
|
type="button"
|
||||||
raised
|
raised
|
||||||
@click=${() => {
|
@click=${ev =>
|
||||||
const lionForm = this._lionFormNode;
|
ev.currentTarget.parentElement.parentElement.parentElement.resetGroup()}
|
||||||
lionForm.resetGroup();
|
|
||||||
}}
|
|
||||||
>Reset</lion-button
|
>Reset</lion-button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue