-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: emit sl-change from radio and switch on user interaction only
- Loading branch information
1 parent
9b99a92
commit 9216e72
Showing
5 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect, fixture, html, oneEvent } from '@open-wc/testing'; | ||
import { sendKeys } from '@web/test-runner-commands' | ||
|
||
import '../../../dist/shoelace.js'; | ||
import type SlRadio from './radio'; | ||
|
||
describe('<sl-radio>', () => { | ||
it('should be disabled with the disabled attribute', async () => { | ||
const el = await fixture(html` <sl-radio disabled></sl-radio> `); | ||
const radio = el.shadowRoot?.querySelector('input'); | ||
|
||
expect(radio.disabled).to.be.true; | ||
}); | ||
|
||
it('should be valid by default', async () => { | ||
const el = (await fixture<SlRadio>(html` <sl-radio></sl-radio> `)) | ||
|
||
expect(el.invalid).to.be.false; | ||
}); | ||
|
||
it('should fire sl-change when clicked', async () => { | ||
const el = (await fixture<SlRadio>(html` <sl-radio></sl-radio> `)) | ||
setTimeout(() => el.shadowRoot?.querySelector('input').click()); | ||
const event = await oneEvent(el, 'sl-change') | ||
expect(event.target).to.equal(el); | ||
expect(el.checked).to.be.true; | ||
}); | ||
|
||
it('should fire sl-change when toggled via keyboard', async () => { | ||
const el = (await fixture<SlRadio>(html` <sl-radio></sl-radio> `)) | ||
const input = el.shadowRoot?.querySelector('input'); | ||
input.focus(); | ||
setTimeout(() => sendKeys({ press: ' ' })); | ||
const event = await oneEvent(el, 'sl-change') | ||
expect(event.target).to.equal(el); | ||
expect(el.checked).to.be.true; | ||
}); | ||
|
||
it('should not fire sl-change when checked is set by javascript', async () => { | ||
const el = (await fixture<SlRadio>(html` <sl-radio></sl-radio> `)) | ||
el.addEventListener('sl-change', () => expect.fail('event fired')) | ||
el.checked = true; | ||
await el.updateComplete; | ||
el.checked = false; | ||
await el.updateComplete; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect, fixture, html, oneEvent } from '@open-wc/testing'; | ||
import { sendKeys } from '@web/test-runner-commands' | ||
|
||
import '../../../dist/shoelace.js'; | ||
import type SlSwitch from './switch'; | ||
|
||
describe('<sl-switch>', () => { | ||
it('should be disabled with the disabled attribute', async () => { | ||
const el = await fixture(html` <sl-switch disabled></sl-switch> `); | ||
const input = el.shadowRoot?.querySelector('input'); | ||
|
||
expect(input.disabled).to.be.true; | ||
}); | ||
|
||
it('should be valid by default', async () => { | ||
const el = (await fixture<SlSwitch>(html` <sl-switch></sl-switch> `)) | ||
|
||
expect(el.invalid).to.be.false; | ||
}); | ||
|
||
it('should fire sl-change when clicked', async () => { | ||
const el = (await fixture<SlSwitch>(html` <sl-switch></sl-switch> `)) | ||
setTimeout(() => el.shadowRoot?.querySelector('input').click()); | ||
const event = await oneEvent(el, 'sl-change') | ||
expect(event.target).to.equal(el); | ||
expect(el.checked).to.be.true; | ||
}); | ||
|
||
it('should fire sl-change when toggled via keyboard', async () => { | ||
const el = (await fixture<SlSwitch>(html` <sl-switch></sl-switch> `)) | ||
const input = el.shadowRoot?.querySelector('input'); | ||
input.focus(); | ||
setTimeout(() => sendKeys({ press: ' ' })); | ||
const event = await oneEvent(el, 'sl-change') | ||
expect(event.target).to.equal(el); | ||
expect(el.checked).to.be.true; | ||
}); | ||
|
||
it('should not fire sl-change when checked is set by javascript', async () => { | ||
const el = (await fixture<SlSwitch>(html` <sl-switch></sl-switch> `)) | ||
el.addEventListener('sl-change', () => expect.fail('event fired')) | ||
el.checked = true; | ||
await el.updateComplete; | ||
el.checked = false; | ||
await el.updateComplete; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters