import { expect, fixture as _fixture, nextFrame, html } from '@open-wc/testing'; import '@lion/ui/define/lion-input-range.js'; /** * @typedef {import('../src/LionInputRange.js').LionInputRange} LionInputRange * @typedef {import('lit').TemplateResult} TemplateResult */ const fixture = /** @type {(arg: TemplateResult|string) => Promise} */ (_fixture); describe('', () => { it('has a type = range', async () => { const el = await fixture(``); expect(el._inputNode.type).to.equal('range'); }); it('displays the modelValue and unit', async () => { const el = await fixture(html` `); expect( /** @type {HTMLElement} */ ( /** @type {ShadowRoot} */ (el.shadowRoot).querySelector('.input-range__value') ).innerText, ).to.equal('75'); expect( /** @type {HTMLElement} */ ( /** @type {ShadowRoot} */ (el.shadowRoot).querySelector('.input-range__unit') ).innerText, ).to.equal('%'); }); it('displays 2 tick labels (min and max values) by default', async () => { const el = await fixture(``); expect(el.shadowRoot?.querySelectorAll('.input-range__limits span').length).to.equal(2); expect( /** @type {HTMLElement} */ ( /** @type {ShadowRoot} */ (el.shadowRoot).querySelectorAll('.input-range__limits > div')[0] ).textContent?.trim(), ).to.equal(`Minimum ${el.min.toString()}`); expect( /** @type {HTMLElement} */ ( /** @type {ShadowRoot} */ (el.shadowRoot).querySelectorAll('.input-range__limits > div')[1] ).textContent?.trim(), ).to.equal(`Maximum ${el.max.toString()}`); }); it('update min and max attributes when min and max property change', async () => { const el = await fixture(``); el.min = 120; el.max = 220; await nextFrame(); // sync to native element takes some time expect(el._inputNode.min).to.equal(el.min.toString()); expect(el._inputNode.max).to.equal(el.max.toString()); }); it('can hide the tick labels', async () => { const el = await fixture( ``, ); expect(el.shadowRoot?.querySelectorAll('.input-group__input')[0]).dom.to.equal(`
`); }); it('parser method should return a value parsed into a number format', async () => { const el = await fixture(html` `); expect(el.modelValue).to.equal(150); el._inputNode.value = '130'; el._inputNode.dispatchEvent(new Event('input')); expect(el.modelValue).to.equal(130); }); it('is accessible', async () => { const el = await fixture(``); await expect(el).to.be.accessible(); }); it('is accessible when disabled', async () => { const el = await fixture(``); await expect(el).to.be.accessible(); }); });