import { expect, fixture, html } from '@open-wc/testing'; import './index'; import type { NileHeading } from './index'; describe('NileHeading', () => { 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-heading'); }); it('4. name defaults empty', async () => { const el = await fixture(html``); expect(el.name).to.equal(''); }); it('5. size defaults header-1', async () => { const el = await fixture(html``); expect(el.size).to.equal('header-1'); }); it('6. slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('7. slotted content', async () => { const el = await fixture(html`Hello World`); expect(el.textContent).to.contain('Hello World'); }); it('8. size reflected', async () => { const el = await fixture(html``); expect(el.getAttribute('size')).to.equal('header-2'); }); it('9. dynamic name', async () => { const el = await fixture(html``); el.name = 'Test'; await el.updateComplete; expect(el.name).to.equal('Test'); }); it('10. dynamic size', async () => { const el = await fixture(html``); el.size = 'header-2'; await el.updateComplete; expect(el.getAttribute('size')).to.equal('header-2'); }); it('11. has styles', async () => { expect((await import('./index')).NileHeading.styles).to.exist; }); it('12. is defined', async () => { expect(customElements.get('nile-heading')).to.exist; }); it('13. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('14. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('15. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('16. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-heading'); }); it('17. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-heading.x')).to.be.true; }); it('18. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-heading')).to.equal(el); }); it('19. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-heading'); }); it('20. 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('21. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('22. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('23. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('24. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('25. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('h')).to.be.true; }); it('26. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('h1'); }); it('27. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('28. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('29. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('30. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('31. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('32. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-heading').length).to.equal(2); }); it('33. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-heading')!.parentElement).to.equal(c); }); it('34. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-heading'); }); it('35. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('36. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('37. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('38. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('39. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('40. name type', async () => { const el = await fixture(html``); expect(typeof el.name).to.equal('string'); }); it('41. size type', async () => { const el = await fixture(html``); expect(typeof el.size).to.equal('string'); }); it('42. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('43. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('44. slot count', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('45. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Title'); }); it('46. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('heading'); }); it('47. createElement', async () => { const el = document.createElement('nile-heading') as NileHeading; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('48. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('49. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('50. children survived update', async () => { const el = await fixture(html`Title`); el.name = 'N'; await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('51. nested elements', async () => { const el = await fixture(html`Bold`); expect(el.querySelector('strong')).to.exist; }); it('52. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('53. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('54. text content', async () => { const el = await fixture(html`Test`); expect(el.textContent).to.contain('Test'); }); it('55. no children default', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('56. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('57. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('58. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('59. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('60. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('61. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('62. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('63. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('64. 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('65. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('active'); expect(el.classList.contains('active')).to.be.true; }); it('66. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('67. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = '

New

'; expect(el.querySelector('p')!.textContent).to.equal('New'); }); it('68. setAttribute size', async () => { const el = await fixture(html``); el.setAttribute('size', 'header-3'); await el.updateComplete; expect(el.size).to.equal('header-3'); }); it('69. removeAttribute size', async () => { const el = await fixture(html``); el.removeAttribute('size'); await el.updateComplete; expect(el.getAttribute('size')).to.be.null; }); it('70. hasAttribute size', async () => { const el = await fixture(html``); expect(el.hasAttribute('size')).to.be.true; }); it('71. rapid size changes', async () => { const el = await fixture(html``); el.size = 'header-2'; await el.updateComplete; el.size = 'header-3'; await el.updateComplete; expect(el.size).to.equal('header-3'); }); it('72. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('73. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('74. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('75. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('76. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('77. re-renders', async () => { const el = await fixture(html``); el.name = 'A'; await el.updateComplete; el.name = 'B'; await el.updateComplete; expect(el.name).to.equal('B'); }); it('78. nested in div', async () => { const c = await fixture(html`
Title
`); expect(c.querySelector('nile-heading')).to.exist; }); it('79. contains check', async () => { const el = await fixture(html`T`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('80. children array', async () => { const el = await fixture(html`AB`); expect(el.children.length).to.equal(2); }); it('81. lastElementChild', async () => { const el = await fixture(html`A
B
`); expect(el.lastElementChild!.tagName.toLowerCase()).to.equal('div'); }); it('82. append child', async () => { const el = await fixture(html``); const s = document.createElement('span'); el.appendChild(s); expect(el.querySelector('span')).to.exist; }); it('83. remove child', async () => { const el = await fixture(html`T`); el.removeChild(el.querySelector('#s1')!); expect(el.querySelector('#s1')).to.be.null; }); it('84. replaceChildren', async () => { const el = await fixture(html`Old`); const p = document.createElement('p'); el.replaceChildren(p); expect(el.querySelector('p')).to.exist; expect(el.querySelector('span')).to.be.null; }); it('85. textContent empty default', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('86. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('87. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('88. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('89. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('90. aria-level', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-level')).to.equal('1'); }); it('91. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('92. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('T'); }); it('93. insertBefore', async () => { const el = await fixture(html`B`); const p = document.createElement('p'); el.insertBefore(p, el.querySelector('#s1')!); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('p'); }); it('94. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('95. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('96. no h1 in shadow', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('97. no div in shadow', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.be.null; }); it('98. only slot in shadow', async () => { const el = await fixture(html``); const all = el.shadowRoot!.querySelectorAll('*'); const tagNames = Array.from(all).map(e => e.tagName.toLowerCase()); expect(tagNames).to.include('slot'); }); it('99. multiple re-renders', async () => { const el = await fixture(html``); for (let i = 0; i < 5; i++) { el.requestUpdate(); await el.updateComplete; } expect(el.shadowRoot).to.not.be.null; }); it('100. full integration', async () => { const el = await fixture(html`Main Title`); expect(el.name).to.equal('Title'); expect(el.size).to.equal('header-1'); expect(el.id).to.equal('h1'); expect(el.textContent).to.contain('Main Title'); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); });