import { expect, fixture, html } from '@open-wc/testing'; import './nile-tab-group'; import '../nile-tab/nile-tab'; import '../nile-tab-panel/nile-tab-panel'; import type { NileTabGroup } from './nile-tab-group'; describe('NileTabGroup', () => { 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-group'); }); it('4. has styles', async () => { expect((await import('./nile-tab-group')).NileTabGroup.styles).to.exist; }); it('5. is defined', async () => { expect(customElements.get('nile-tab-group')).to.exist; }); it('6. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('7. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('8. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('9. nav slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="nav"]')).to.exist; }); it('10. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot:not([name])')).to.exist; }); it('11. part base', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('12. part nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="nav"]')).to.exist; }); it('13. part body', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="body"]')).to.exist; }); it('14. tab-group class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab-group')).to.exist; }); it('15. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-tab-group'); }); it('16. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('17. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-tab-group')).to.equal(el); }); it('18. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-tab-group'); }); it('19. 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('20. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('21. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('22. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('23. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('tg')).to.be.true; }); it('24. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('tg1'); }); it('25. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('26. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('27. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-tab-group'); }); it('28. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('29. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('30. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-tab-group').length).to.equal(2); }); it('31. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-tab-group')!.parentElement).to.equal(c); }); it('32. createElement', async () => { const el = document.createElement('nile-tab-group') as NileTabGroup; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('33. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('34. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('35. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('36. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('37. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('38. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('39. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('40. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('41. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('42. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('43. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Tabs'); }); it('44. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('tablist'); }); it('45. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('46. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('TG'); }); it('47. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('48. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('49. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('50. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('51. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('52. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('53. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('54. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('55. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('56. 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('57. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-tab-group')).to.exist; }); it('58. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('59. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('60. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('61. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('62. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).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`T1`); expect(el.contains(el.querySelector('nile-tab'))).to.be.true; }); it('72. childElementCount', async () => { const el = await fixture(html`T1C1`); expect(el.childElementCount).to.equal(2); }); it('73. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('74. no p', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('75. no hr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); it('76. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('77. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('78. no nile-badge', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-badge')).to.be.null; }); it('79. no nile-divider', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-divider')).to.be.null; }); it('80. part tabs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="tabs"]')).to.exist; }); it('81. removeAttribute class', async () => { const el = await fixture(html``); el.removeAttribute('class'); expect(el.classList.contains('x')).to.be.false; }); it('82. hasAttribute id', async () => { const el = await fixture(html``); expect(el.hasAttribute('id')).to.be.true; }); it('83. getAttribute id', async () => { const el = await fixture(html``); expect(el.getAttribute('id')).to.equal('tg1'); }); it('84. setAttribute id', async () => { const el = await fixture(html``); el.setAttribute('id', 'tg2'); expect(el.id).to.equal('tg2'); }); it('85. removeAttribute id', async () => { const el = await fixture(html``); el.removeAttribute('id'); expect(el.id).to.equal(''); }); it('86. no nav element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('87. firstElementChild', async () => { const el = await fixture(html`T`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('nile-tab'); }); it('88. children survived update', async () => { const el = await fixture(html`T`); el.requestUpdate(); await el.updateComplete; expect(el.querySelector('nile-tab')).to.exist; }); it('89. no nile-tooltip', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-tooltip')).to.be.null; }); it('90. no nile-spinner', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-spinner')).to.be.null; }); it('91. no button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('button')).to.be.null; }); it('92. part active-tab-indicator', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="active-tab-indicator"]')).to.exist; }); it('93. tab-group__tabs class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab-group__tabs')).to.exist; }); it('94. tab-group__body class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab-group__body')).to.exist; }); it('95. tab-group__nav class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab-group__nav-container')).to.exist; }); it('96. tab-group__indicator class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.tab-group__indicator')).to.exist; }); it('97. no nile-input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-input')).to.be.null; }); it('98. no nile-checkbox', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-checkbox')).to.be.null; }); it('99. no nile-tag', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-tag')).to.be.null; }); it('100. full integration', async () => { const el = await fixture(html`Tab 1Tab 2Panel 1Panel 2`); expect(el.id).to.equal('tg1'); expect(el.childElementCount).to.equal(4); expect(el.shadowRoot!.querySelector('.tab-group')).to.exist; expect(el.shadowRoot!.querySelector('slot[name="nav"]')).to.exist; }); });