import { expect, fixture, html } from '@open-wc/testing'; import './nile-list'; import type { NileList } from './nile-list'; describe('NileList', () => { 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-list'); }); it('4. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('5. slotted content', async () => { const el = await fixture(html`
Item
`); expect(el.textContent).to.contain('Item'); }); it('6. handleListItemClick method', async () => { const el = await fixture(html``); expect(el.handleListItemClick).to.be.a('function'); }); it('7. emits nile-list-click', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-list-click', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); el.dispatchEvent(new CustomEvent('nile-list-click', { detail: { value: 'Test' } })); expect(detail.value).to.equal('Test'); }); it('8. has styles', async () => { expect((await import('./nile-list')).NileList.styles).to.exist; }); it('9. is defined', async () => { expect(customElements.get('nile-list')).to.exist; }); it('10. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('11. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('12. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('13. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-list'); }); it('14. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('15. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-list')).to.equal(el); }); it('16. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-list'); }); it('17. 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('18. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('19. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('20. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('21. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('l')).to.be.true; }); it('22. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('l1'); }); it('23. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('24. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('25. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-list'); }); it('26. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('27. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('28. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-list').length).to.equal(2); }); it('29. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-list')!.parentElement).to.equal(c); }); it('30. createElement', async () => { const el = document.createElement('nile-list') as NileList; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('31. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('32. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('33. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('34. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('35. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('36. no button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('button')).to.be.null; }); it('37. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('38. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('39. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('40. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('41. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('42. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('List'); }); it('43. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('list'); }); it('44. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('45. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('L'); }); it('46. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('47. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('48. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('49. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('50. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('51. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('52. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('53. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('54. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('55. 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('56. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-list')).to.exist; }); it('57. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('58. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('59. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('60. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('61. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('62. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('63. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('64. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('65. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('66. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('67. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('68. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('69. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('70. 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('71. contains', async () => { const el = await fixture(html`T`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('72. childElementCount', async () => { const el = await fixture(html`
A
B
`); expect(el.childElementCount).to.equal(2); }); it('73. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('74. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('75. no p', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('76. no hr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); it('77. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('78. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('79. no nile-icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.be.null; }); it('80. no nile-badge', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-badge')).to.be.null; }); it('81. innerHTML empty default', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); }); it('82. textContent empty default', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('83. innerHTML with content', async () => { const el = await fixture(html`X`); expect(el.innerHTML).to.contain('span'); }); it('84. removeChild', async () => { const el = await fixture(html`X`); const s = el.querySelector('#s1')!; el.removeChild(s); expect(el.querySelector('#s1')).to.be.null; }); it('85. appendChild', async () => { const el = await fixture(html``); const s = document.createElement('span'); s.textContent = 'New'; el.appendChild(s); expect(el.querySelector('span')).to.exist; }); it('86. replaceChildren', async () => { const el = await fixture(html`Old`); const p = document.createElement('p'); p.textContent = 'New'; el.replaceChildren(p); expect(el.querySelector('p')).to.exist; expect(el.querySelector('span')).to.be.null; }); it('87. slot count 1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('88. no div', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.be.null; }); it('89. no span', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.be.null; }); it('90. setAttribute id', async () => { const el = await fixture(html``); el.setAttribute('id', 'l2'); expect(el.id).to.equal('l2'); }); it('91. removeAttribute id', async () => { const el = await fixture(html``); el.removeAttribute('id'); expect(el.id).to.equal(''); }); it('92. hasAttribute id', async () => { const el = await fixture(html``); expect(el.hasAttribute('id')).to.be.true; }); it('93. getAttribute id', async () => { const el = await fixture(html``); expect(el.getAttribute('id')).to.equal('l1'); }); it('94. removeAttribute class', async () => { const el = await fixture(html``); el.removeAttribute('class'); expect(el.classList.contains('x')).to.be.false; }); it('95. children survived update', async () => { const el = await fixture(html`T`); el.requestUpdate(); await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('96. no nile-divider', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-divider')).to.be.null; }); it('97. no nile-button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-button')).to.be.null; }); it('98. no header slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="header"]')).to.be.null; }); it('99. no footer slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="footer"]')).to.be.null; }); it('100. full integration', async () => { const el = await fixture(html`
Item 1
Item 2
`); expect(el.id).to.equal('l1'); expect(el.getAttribute('role')).to.equal('list'); expect(el.childElementCount).to.equal(2); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); });