import { expect, fixture as _fixture, html } from '@open-wc/testing'; import '../lion-radio-group.js'; import '../lion-radio.js'; /** * @typedef {import('../src/LionRadioGroup').LionRadioGroup} LionRadioGroup * @typedef {import('../src/LionRadio').LionRadio} LionRadio * @typedef {import('@lion/core').TemplateResult} TemplateResult */ const fixture = /** @type {(arg: TemplateResult) => Promise} */ (_fixture); describe('', () => { it('should have role = radiogroup', async () => { const el = await fixture(html` `); expect(el.getAttribute('role')).to.equal('radiogroup'); }); it(`becomes "touched" once a single element of the group changes`, async () => { const el = await fixture(html` `); el.children[1].focus(); expect(el.touched).to.equal(false, 'initially, touched state is false'); /** @type {LionRadio} */ (el.children[1]).checked = true; expect(el.touched, `focused via a mouse click, group should be touched`).to.be.true; }); it('allows selection of only one radio in a named group', async () => { const el = await fixture(html` `); const male = el.formElements[0]; const maleInput = male.querySelector('input'); const female = el.formElements[1]; const femaleInput = female.querySelector('input'); expect(male.checked).to.equal(false); expect(female.checked).to.equal(false); maleInput.focus(); maleInput.click(); expect(male.checked).to.equal(true); expect(female.checked).to.equal(false); femaleInput.focus(); femaleInput.click(); expect(male.checked).to.equal(false); expect(female.checked).to.equal(true); }); it('is accessible', async () => { const el = await fixture(html` `); await expect(el).to.be.accessible(); }); it('is accessible when the group is disabled', async () => { const el = await fixture(html` `); await expect(el).to.be.accessible(); }); it('is accessible when an option is disabled', async () => { const el = await fixture(html` `); await expect(el).to.be.accessible(); }); });