import { expect, fixture as _fixture } from '@open-wc/testing'; import { html } from 'lit/static-html.js'; import '@lion/ui/define/lion-radio-group.js'; import '@lion/ui/define/lion-radio.js'; /** * @typedef {import('../src/LionRadioGroup.js').LionRadioGroup} LionRadioGroup * @typedef {import('../src/LionRadio.js').LionRadio} LionRadio * @typedef {import('lit').TemplateResult} TemplateResult */ const fixture = /** @type {(arg: TemplateResult) => Promise} */ (_fixture); describe('', () => { describe('resetGroup', () => { // TODO move to FormGroupMixin test suite and let CheckboxGroup make use of them it('restores to empty modelValue if changes were made', async () => { const el = await fixture(html` `); el.formElements[0].checked = true; expect(el.modelValue).to.deep.equal('male'); el.resetGroup(); expect(el.modelValue).to.deep.equal(''); }); it('restores default values if changes were made', async () => { const el = await fixture(html` `); el.formElements[0].checked = true; expect(el.modelValue).to.deep.equal('male'); el.resetGroup(); expect(el.modelValue).to.deep.equal('female'); el.formElements[2].checked = true; expect(el.modelValue).to.deep.equal('other'); el.resetGroup(); await el.formElements[1].updateComplete; await el.updateComplete; expect(el.modelValue).to.deep.equal('female'); }); it('restores default values if changes were made to a group containing options with formatters', async () => { const formatter = /** @type {(modelValue: { value: string}) => string} */ modelValue => modelValue.value.charAt(0); const el = await fixture(html` `); el.formElements[0].checked = true; expect(el.modelValue).to.deep.equal('male'); el.resetGroup(); expect(el.modelValue).to.deep.equal('female'); el.formElements[2].checked = true; expect(el.modelValue).to.deep.equal('other'); el.resetGroup(); await el.formElements[1].updateComplete; await el.updateComplete; expect(el.modelValue).to.deep.equal('female'); }); }); 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.formElements[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(); }); });