feat(form): add reset functionality (#799)

* feat(form): add reset functionality

* feat(interal): add defaultValue decorator

* feat: add defaultValue and defaultChecked

* chore: implement unit tests

* chore: remove leftover
This commit is contained in:
Alessandro
2022-06-28 23:59:52 +02:00
committed by GitHub
parent 0d19c46d18
commit b2cf3a5505
22 changed files with 468 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { expect, fixture, html, waitUntil } from '@open-wc/testing';
import { expect, fixture, html, oneEvent, waitUntil } from '@open-wc/testing';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { serialize } from '../../utilities/form';
@@ -124,6 +124,36 @@ describe('<sl-input>', () => {
});
});
describe('when resetting a form', () => {
it('should reset the element to its initial value', async () => {
const form = await fixture<HTMLFormElement>(html`
<form>
<sl-input name="a" value="test"></sl-input>
<sl-button type="reset">Reset</sl-button>
</form>
`);
const button = form.querySelector('sl-button')!;
const input = form.querySelector('sl-input')!;
input.value = '1234';
await input.updateComplete;
setTimeout(() => button.click());
await oneEvent(form, 'reset');
await input.updateComplete;
expect(input.value).to.equal('test');
input.defaultValue = '';
setTimeout(() => button.click());
await oneEvent(form, 'reset');
await input.updateComplete;
expect(input.value).to.equal('');
});
});
describe('when calling HTMLFormElement.reportValidity()', () => {
it('should be invalid when the input is empty and form.reportValidity() is called', async () => {
const form = await fixture<HTMLFormElement>(html`