|
| 1 | +import { fixture, oneEvent, expect } from '@open-wc/testing'; |
| 2 | + |
| 3 | +/** |
| 4 | + * <hx-switch-control> component tests |
| 5 | + * |
| 6 | + * @type HXSwitchControlElement |
| 7 | + * |
| 8 | + */ |
| 9 | +describe('<hx-switch-control> component tests', () => { |
| 10 | + const template = '<hx-switch-control>'; |
| 11 | + const mockup = `<hx-switch-control> |
| 12 | + <input type="checkbox" id="switchOnOffTest" /> |
| 13 | + <label for="switchOnOffTest"> |
| 14 | + <hx-switch |
| 15 | + onlabel="on" |
| 16 | + offlabel="off" |
| 17 | + aria-labelledby="switchOnOffTest"> |
| 18 | + </hx-switch> |
| 19 | + </label> |
| 20 | + </hx-switch-control>`; |
| 21 | + |
| 22 | + describe('test instantiate element', () => { |
| 23 | + it('should be instantiated with hx-defined attribute', async () => { |
| 24 | + const fragment = /** @type {HXSwitchControlElement} */ await fixture(mockup); |
| 25 | + const attr = fragment.hasAttribute('hx-defined'); |
| 26 | + |
| 27 | + expect(attr).to.be.true; |
| 28 | + }); |
| 29 | + |
| 30 | + it('should not be hidden', async () => { |
| 31 | + const fragment = /** @type {HXSwitchControlElement} */ await fixture(mockup); |
| 32 | + const prop = fragment.hidden; |
| 33 | + |
| 34 | + expect(prop).to.be.false; |
| 35 | + }); |
| 36 | + |
| 37 | + it(`the rendered Light DOM should NOT equal simple template ${template}`, async () => { |
| 38 | + const fragment = /** @type {HXSwitchControlElement} */ await fixture(mockup); |
| 39 | + |
| 40 | + expect(fragment).lightDom.to.not.equal(mockup); |
| 41 | + }); |
| 42 | + |
| 43 | + it(`should NOT have a Shadow DOM`, async () => { |
| 44 | + const fragment = /** @type {HXSwitchControlElement} */ await fixture(mockup); |
| 45 | + const shadow = fragment.shadowRoot; |
| 46 | + |
| 47 | + expect(shadow).to.be.null; |
| 48 | + }); |
| 49 | + |
| 50 | + }); |
| 51 | + describe('test for click event listener', () => { |
| 52 | + it('should fire a click event', async () => { |
| 53 | + const fragment = /** @type { HXSwitchControlElement } */ await fixture(mockup); |
| 54 | + const detail = { evt: 'clicked!'}; |
| 55 | + const customEvent = new CustomEvent('click', { detail }); |
| 56 | + |
| 57 | + setTimeout(() => fragment.dispatchEvent(customEvent)); |
| 58 | + const evt = await oneEvent(fragment, 'click'); |
| 59 | + |
| 60 | + expect(evt).to.equal(customEvent); |
| 61 | + expect(evt.detail).to.equal(detail); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + describe('test <hx-switch-control> getters', () => { |
| 66 | + it('should get the control element"]', async () => { |
| 67 | + const fragment = /** @type { HXSwitchControlElement } */ await fixture(mockup); |
| 68 | + const id = 'switchOnOffTest'; |
| 69 | + const ctrlElement = fragment.controlElement; |
| 70 | + const ctrlElementID = ctrlElement.id; |
| 71 | + |
| 72 | + expect(ctrlElementID).to.equal(id); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should get the <hx-switch> element', async () => { |
| 76 | + const template = '<hx-switch>'; |
| 77 | + const fragment = /** @type { HXSwitchControlElement } */ await fixture(mockup); |
| 78 | + const switchFra = /** @type { HXSwitchElement } */ await fixture(template); |
| 79 | + const switchEl = fragment.switchElement; |
| 80 | + |
| 81 | + expect(switchEl.tagName).to.equal(switchFra.tagName); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should get the <hx-switch> toggled state', async () => { |
| 85 | + const fragment = /** @type { HXSwitchControlElement } */ await fixture(mockup); |
| 86 | + const switchElementState = fragment.switchElement.toggled; |
| 87 | + |
| 88 | + expect(switchElementState).to.be.false; |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments