import { expect, fixture, html } from '@open-wc/testing'; import './nile-tab'; import type { NileTab } from './nile-tab'; describe('NileTab', () => { 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-tab'); }); it('4. panel defaults empty', async () => { const el = await fixture(html``); expect(el.panel).to.equal(''); }); it('5. active defaults false', async () => { const el = await fixture(html``); expect(el.active).to.be.false; }); it('6. closable defaults false', async () => { const el = await fixture(html``); expect(el.closable).to.be.false; }); it('7. disabled defaults false', async () => { const el = await fixture(html``); expect(el.disabled).to.be.false; }); it('8. centered defaults false', async () => { const el = await fixture(html``); expect(el.centered).to.be.false; }); it('9. set panel', async () => { const el = await fixture(html``); expect(el.panel).to.equal('p1'); }); it('10. set active', async () => { const el = await fixture(html``); expect(el.active).to.be.true; }); it('11. set closable', async () => { const el = await fixture(html``); expect(el.closable).to.be.true; }); it('12. set disabled', async () => { const el = await fixture(html``); expect(el.disabled).to.be.true; }); it('13. set centered', async () => { const el = await fixture(html``); expect(el.centered).to.be.true; }); it('14. tab class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab')).to.exist; }); it('15. tab--active class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab--active')).to.exist; }); it('16. tab--closable class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab--closable')).to.exist; }); it('17. tab--disabled class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab--disabled')).to.exist; }); it('18. tab--centered class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab--centered')).to.exist; }); it('19. role tab', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('tab'); }); it('20. part base', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('21. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot:not([name])')).to.exist; }); it('22. prefix slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="prefix"]')).to.exist; }); it('23. close button when closable', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon-button')).to.exist; }); it('24. no close button when not closable', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon-button')).to.be.null; }); it('25. emits nile-close', async () => { const el = await fixture(html``); let fired = false; el.addEventListener('nile-close', () => { fired = true; }); const btn = el.shadowRoot!.querySelector('nile-icon-button') as HTMLElement; btn.click(); expect(fired).to.be.true; }); it('26. slotted content', async () => { const el = await fixture(html`Tab 1`); expect(el.textContent).to.contain('Tab 1'); }); it('27. panel reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('panel')).to.be.true; }); it('28. active reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('active')).to.be.true; }); it('29. disabled reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('30. has styles', async () => { expect((await import('./nile-tab')).NileTab.styles).to.exist; }); it('31. is defined', async () => { expect(customElements.get('nile-tab')).to.exist; }); it('32. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('33. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('34. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('35. tabindex 0', async () => { const el = await fixture(html``); const div = el.shadowRoot!.querySelector('.tab') as HTMLElement; expect(div.getAttribute('tabindex')).to.equal('0'); }); it('36. tabindex -1 disabled', async () => { const el = await fixture(html``); const div = el.shadowRoot!.querySelector('.tab') as HTMLElement; expect(div.getAttribute('tabindex')).to.equal('-1'); }); it('37. auto-generated id', async () => { const el = await fixture(html``); expect(el.id).to.contain('nile-tab-'); }); it('38. custom id preserved', async () => { const el = await fixture(html``); expect(el.id).to.equal('my-tab'); }); it('39. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-tab'); }); it('40. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('41. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-tab')).to.equal(el); }); it('42. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-tab'); }); it('43. 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('44. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('45. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('46. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('47. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('t')).to.be.true; }); it('48. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('49. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('50. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-tab'); }); it('51. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('52. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('53. dynamic active', async () => { const el = await fixture(html``); el.active = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.tab--active')).to.exist; }); it('54. dynamic disabled', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.tab--disabled')).to.exist; }); it('55. dynamic closable', async () => { const el = await fixture(html``); el.closable = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('nile-icon-button')).to.exist; }); it('56. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-tab').length).to.equal(2); }); it('57. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-tab')!.parentElement).to.equal(c); }); it('58. createElement', async () => { const el = document.createElement('nile-tab') as NileTab; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('59. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('60. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('61. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('62. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('63. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).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. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('67. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('68. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('69. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('70. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('71. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('72. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('73. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('74. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('75. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('76. 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('77. nested in div', async () => { const c = await fixture(html`
T
`); expect(c.querySelector('nile-tab')).to.exist; }); it('78. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('79. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('80. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('81. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('82. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('83. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('84. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('85. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('86. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('87. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('88. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('89. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('90. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('91. 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('92. close button part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="close-button"]')).to.exist; }); it('93. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('94. no p', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('95. no hr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); it('96. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('97. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('98. active then inactive', async () => { const el = await fixture(html``); el.active = false; await el.updateComplete; expect(el.shadowRoot!.querySelector('.tab--active')).to.be.null; }); it('99. contains', async () => { const el = await fixture(html`T`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('100. full integration', async () => { const el = await fixture(html`Tab 1`); expect(el.panel).to.equal('p1'); expect(el.active).to.be.true; expect(el.closable).to.be.true; expect(el.id).to.equal('t1'); expect(el.textContent).to.contain('Tab 1'); expect(el.shadowRoot!.querySelector('.tab--active')).to.exist; expect(el.shadowRoot!.querySelector('nile-icon-button')).to.exist; }); });