mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
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:
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user