|
| 1 | +import { fixture, expect } from '@open-wc/testing'; |
| 2 | + |
| 3 | +/** |
| 4 | + * <hx-menu> component tests |
| 5 | + * |
| 6 | + * @type HXMenuElement |
| 7 | + * |
| 8 | + */ |
| 9 | +describe('<hx-menu> component tests', () => { |
| 10 | + const template = '<hx-menu>'; |
| 11 | + |
| 12 | + describe('instantiate element', () => { |
| 13 | + it('should be instantiated with hx-defined attribute', async () => { |
| 14 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 15 | + const attr = component.hasAttribute('hx-defined'); |
| 16 | + |
| 17 | + expect(attr).to.be.true; |
| 18 | + }); |
| 19 | + |
| 20 | + it('should not be hidden', async () => { |
| 21 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 22 | + const prop = component.hidden; |
| 23 | + |
| 24 | + expect(prop).to.be.false; |
| 25 | + }); |
| 26 | + |
| 27 | + it(`the rendered light DOM should NOT equal simple template ${template}`, async () => { |
| 28 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 29 | + |
| 30 | + expect(component).lightDom.to.not.equal(template); |
| 31 | + }); |
| 32 | + |
| 33 | + it(`should NOT have a Shadow DOM`, async () => { |
| 34 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 35 | + const shadow = component.shadowRoot; |
| 36 | + |
| 37 | + expect(shadow).to.be.null; |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('verify onCreate method', () => { |
| 42 | + it('test for default position', async () => { |
| 43 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 44 | + const defaultPosition = 'bottom-start'; |
| 45 | + const attr = component.hasAttribute('position'); |
| 46 | + const bottomStart = component.getAttribute('position'); |
| 47 | + |
| 48 | + expect(attr).to.be.true; |
| 49 | + expect(bottomStart).to.equal(defaultPosition); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('test $onConnect method', () => { |
| 54 | + it('should have aria-expanded attribute', async () => { |
| 55 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 56 | + const attr = component.hasAttribute('aria-expanded'); |
| 57 | + |
| 58 | + expect(attr).to.be.true; |
| 59 | + }); |
| 60 | + |
| 61 | + it('should have aria-expanded attribute default to false', async () => { |
| 62 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 63 | + const attr = component.getAttribute('aria-expanded'); |
| 64 | + |
| 65 | + expect(attr).to.be.equal(String(false)); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should have role attribute default to menu', async () => { |
| 69 | + const roleAttr = 'menu'; |
| 70 | + const component = /** @type {HXMenuElement} */ await fixture(template); |
| 71 | + const attr = component.hasAttribute('role'); |
| 72 | + const role = component.getAttribute('role'); |
| 73 | + |
| 74 | + expect(attr).to.be.true; |
| 75 | + expect(role).to.equal(roleAttr); |
| 76 | + }); |
| 77 | + }); |
| 78 | +}); |
0 commit comments