import { expect, fixture, html } from '@open-wc/testing'; import './index'; import type { NileIcon } from './index'; describe('NileIcon', () => { it('1. renders', async () => { const el = await fixture(html``); expect(el).to.exist; }); it('2. shadow root', async () => { const el = await fixture(html``); expect(el.shadowRoot).to.not.be.null; }); it('3. tag name', async () => { const el = await fixture(html``); expect(el.tagName.toLowerCase()).to.equal('nile-icon'); }); it('4. set defaults local', async () => { const el = await fixture(html``); expect(el.set).to.equal('local'); }); it('5. name property', async () => { const el = await fixture(html``); expect(el.name).to.equal('info'); }); it('6. description defaults empty', async () => { const el = await fixture(html``); expect(el.description).to.equal(''); }); it('7. method defaults fill', async () => { const el = await fixture(html``); expect(el.method).to.equal('fill'); }); it('8. size defaults 16', async () => { const el = await fixture(html``); expect(el.size).to.equal(16); }); it('9. push defaults false', async () => { const el = await fixture(html``); expect(el.push).to.be.false; }); it('10. noFill defaults false', async () => { const el = await fixture(html``); expect(el.noFill).to.be.false; }); it('11. nds-icon class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nds-icon')).to.exist; }); it('12. span element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.exist; }); it('13. set name property', async () => { const el = await fixture(html``); expect(el.getAttribute('name')).to.equal('info'); }); it('14. set description', async () => { const el = await fixture(html``); expect(el.description).to.equal('Test icon'); }); it('15. set method stroke', async () => { const el = await fixture(html``); expect(el.method).to.equal('stroke'); }); it('16. set size', async () => { const el = await fixture(html``); await el.updateComplete; expect(Number(el.size)).to.equal(24); }); it('17. set color', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.color).to.equal('red'); }); it('18. color applied to style', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.style.getPropertyValue('--nile-svg-fill')).to.equal('blue'); }); it('19. push property', async () => { const el = await fixture(html``); expect(el.push).to.be.true; }); it('20. noFill property', async () => { const el = await fixture(html``); expect(el.noFill).to.be.true; }); it('21. frame property', async () => { const el = await fixture(html``); expect(el.frame).to.exist; }); it('22. name reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('name')).to.be.true; }); it('23. size reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('size')).to.be.true; }); it('24. description reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('description')).to.be.true; }); it('25. method reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('method')).to.be.true; }); it('26. has styles', async () => { expect((await import('./index')).NileIcon.styles).to.exist; }); it('27. is defined', async () => { expect(customElements.get('nile-icon')).to.exist; }); it('28. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('29. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('30. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('31. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-icon'); }); it('32. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('33. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-icon')).to.equal(el); }); it('34. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-icon'); }); it('35. dispatchEvent', async () => { const el = await fixture(html``); let f = false; el.addEventListener('c', () => (f = true)); el.dispatchEvent(new Event('c')); expect(f).to.be.true; }); it('36. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); // it('37. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('38. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('39. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('ic')).to.be.true; }); it('40. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('ic1'); }); it('41. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('42. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('43. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-icon'); }); it('44. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('45. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('46. buttonClassMap', async () => { const el = await fixture(html``); expect(el.buttonClassMap).to.exist; }); it('47. buttonClassMap stroke false', async () => { const el = await fixture(html``); expect(el.buttonClassMap['stroke']).to.be.false; }); it('48. buttonClassMap stroke true', async () => { const el = await fixture(html``); expect(el.buttonClassMap['stroke']).to.be.true; }); it('49. buttonClassMap push', async () => { const el = await fixture(html``); expect(el.buttonClassMap['nds-icon--push']).to.be.true; }); it('50. buttonClassMap noFill', async () => { const el = await fixture(html``); expect(el.buttonClassMap['no-fill']).to.be.true; }); it('51. dynamic name change', async () => { const el = await fixture(html``); el.name = 'check'; await el.updateComplete; expect(el.name).to.equal('check'); }); it('52. dynamic size change', async () => { const el = await fixture(html``); el.size = 32; await el.updateComplete; expect(el.style.getPropertyValue('--nile-svg-height')).to.equal('32px'); }); it('53. dynamic color change', async () => { const el = await fixture(html``); el.color = 'green'; await el.updateComplete; expect(el.style.getPropertyValue('--nile-svg-fill')).to.equal('green'); }); it('54. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-icon').length).to.equal(2); }); it('55. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-icon')!.parentElement).to.equal(c); }); it('56. createElement', async () => { const el = document.createElement('nile-icon') as NileIcon; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('57. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('58. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('59. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('60. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('61. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('62. no button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('button')).to.be.null; }); it('63. no slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.be.null; }); it('64. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('65. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('66. style attr', async () => { const el = await fixture(html``); expect(el.style.margin).to.equal('5px'); }); it('67. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('68. aria-label attr', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Icon'); }); it('69. role attr', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('img'); }); it('70. dir attr', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('71. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('72. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('73. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('74. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('75. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('76. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('77. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('78. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('79. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('80. dispatchCustomEvent', async () => { const el = await fixture(html``); let d: any; el.addEventListener('t', ((e: CustomEvent) => { d = e.detail; }) as EventListener); el.dispatchEvent(new CustomEvent('t', { detail: 'x' })); expect(d).to.equal('x'); }); it('81. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-icon')).to.exist; }); it('82. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('83. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('84. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('85. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('86. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('87. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('88. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('89. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('90. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('91. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('92. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('93. resolveCssVarExpression null for empty', async () => { const el = await fixture(html``); expect(el.resolveCssVarExpression('')).to.be.null; }); it('94. resolveCssVarExpression returns literal', async () => { const el = await fixture(html``); expect(el.resolveCssVarExpression('hello')).to.equal('hello'); }); it('95. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('96. multiple re-renders', async () => { const el = await fixture(html``); for (let i = 0; i < 3; i++) { el.requestUpdate(); await el.updateComplete; } expect(el.shadowRoot).to.not.be.null; }); it('97. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('98. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('99. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.name).to.equal('info'); expect(Number(el.size)).to.equal(24); expect(el.color).to.equal('red'); expect(el.description).to.equal('Info icon'); expect(el.push).to.be.true; expect(el.id).to.equal('ic1'); expect(el.shadowRoot!.querySelector('.nds-icon')).to.exist; }); });