import { expect, fixture, html } from '@open-wc/testing'; import './nile-inline-sidebar'; import '../nile-inline-sidebar-item/nile-inline-sidebar-item'; import '../nile-inline-sidebar-group/nile-inline-sidebar-group'; import type { NileInlineSidebar } from './nile-inline-sidebar'; describe('NileInlineSidebar', () => { 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-inline-sidebar'); }); it('4. collapsed defaults false', async () => { const el = await fixture(html``); expect(el.collapsed).to.be.false; }); it('5. fixed defaults false', async () => { const el = await fixture(html``); expect(el.fixed).to.be.false; }); it('6. showTooltip defaults false', async () => { const el = await fixture(html``); expect(el.showTooltip).to.be.false; }); it('7. placement defaults left', async () => { const el = await fixture(html``); expect(el.placement).to.equal('left'); }); it('8. set collapsed', async () => { const el = await fixture(html``); expect(el.collapsed).to.be.true; }); it('9. set fixed', async () => { const el = await fixture(html``); expect(el.fixed).to.be.true; }); it('10. set showTooltip', async () => { const el = await fixture(html``); expect(el.showTooltip).to.be.true; }); it('11. set placement right', async () => { const el = await fixture(html``); expect(el.placement).to.equal('right'); }); it('12. set placement left', async () => { const el = await fixture(html``); expect(el.placement).to.equal('left'); }); it('13. collapsed reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('collapsed')).to.be.true; }); it('14. fixed reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('fixed')).to.be.true; }); it('15. placement reflects', async () => { const el = await fixture(html``); expect(el.getAttribute('placement')).to.equal('right'); }); it('16. sidebar class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.sidebar')).to.exist; }); it('17. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('18. header part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="header"]')).to.exist; }); it('19. nav-items part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="nav-items"]')).to.exist; }); it('20. sidebar-header class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.sidebar-header')).to.exist; }); it('21. sidebar-nav class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.sidebar-nav')).to.exist; }); it('22. nav element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.exist; }); it('23. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('24. toggle-btn when expanded', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.toggle-btn')).to.exist; }); it('25. no toggle-btn when fixed', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.toggle-btn')).to.be.null; }); it('26. collapsed nav hidden', async () => { const el = await fixture(html``); const nav = el.shadowRoot!.querySelector('.sidebar-nav') as HTMLElement; expect(nav.style.display).to.equal('none'); }); it('27. expanded nav visible', async () => { const el = await fixture(html``); const nav = el.shadowRoot!.querySelector('.sidebar-nav') as HTMLElement; expect(nav.style.display).to.not.equal('none'); }); it('28. collapsed shows side-bar-action', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-side-bar-action')).to.exist; }); it('29. expanded hides side-bar-action', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-side-bar-action')).to.be.null; }); it('30. collapsed shows action-menu', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-side-bar-action-menu')).to.exist; }); it('31. left expanded icon menu_open', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon?.getAttribute('name')).to.equal('menu_open'); }); it('32. right expanded icon menu_close', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon?.getAttribute('name')).to.equal('menu_close'); }); it('33. left collapsed icon menu_close', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon?.getAttribute('name')).to.equal('menu_close'); }); it('34. right collapsed icon menu_open', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon?.getAttribute('name')).to.equal('menu_open'); }); it('35. left action placement bottom-start', async () => { const el = await fixture(html``); const action = el.shadowRoot!.querySelector('nile-side-bar-action'); expect(action?.getAttribute('placement')).to.equal('bottom-start'); }); it('36. right action placement bottom-end', async () => { const el = await fixture(html``); const action = el.shadowRoot!.querySelector('nile-side-bar-action'); expect(action?.getAttribute('placement')).to.equal('bottom-end'); }); it('37. fixed forces collapsed false', async () => { const el = await fixture(html``); expect(el.collapsed).to.be.false; }); it('38. dynamic collapsed on', async () => { const el = await fixture(html``); el.collapsed = true; await el.updateComplete; expect(el.hasAttribute('collapsed')).to.be.true; }); it('39. dynamic collapsed off', async () => { const el = await fixture(html``); el.collapsed = false; await el.updateComplete; expect(el.hasAttribute('collapsed')).to.be.false; }); it('40. dynamic placement to right', async () => { const el = await fixture(html``); el.placement = 'right'; await el.updateComplete; expect(el.getAttribute('placement')).to.equal('right'); }); it('41. dynamic placement to left', async () => { const el = await fixture(html``); el.placement = 'left'; await el.updateComplete; expect(el.getAttribute('placement')).to.equal('left'); }); it('42. dynamic fixed', async () => { const el = await fixture(html``); el.fixed = true; await el.updateComplete; expect(el.hasAttribute('fixed')).to.be.true; }); it('43. slotted item', async () => { const el = await fixture(html`A`); expect(el.querySelector('nile-inline-sidebar-item')).to.exist; }); it('44. slotted group', async () => { const el = await fixture(html`A`); expect(el.querySelector('nile-inline-sidebar-group')).to.exist; }); it('45. multiple items', async () => { const el = await fixture(html`ABC`); expect(el.querySelectorAll('nile-inline-sidebar-item').length).to.equal(3); }); it('46. emits nile-toggle on collapse', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-toggle', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); const btn = el.shadowRoot!.querySelector('.toggle-btn') as HTMLElement; btn.click(); expect(detail).to.exist; expect(detail.collapsed).to.be.true; }); it('47. emits nile-toggle on expand', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-toggle', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); const btn = el.shadowRoot!.querySelector('.toggle-btn') as HTMLElement; btn.click(); expect(detail).to.exist; expect(detail.collapsed).to.be.false; }); it('48. has styles', async () => { expect((await import('./nile-inline-sidebar')).NileInlineSidebar.styles).to.exist; }); it('49. is defined', async () => { expect(customElements.get('nile-inline-sidebar')).to.exist; }); it('50. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('51. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('52. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('53. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-inline-sidebar'); }); it('54. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('55. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-inline-sidebar')).to.equal(el); }); it('56. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-inline-sidebar'); }); it('57. 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('58. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('59. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('60. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('61. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('s')).to.be.true; }); it('62. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('s1'); }); it('63. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('64. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('65. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-inline-sidebar'); }); it('66. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('67. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('68. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-inline-sidebar').length).to.equal(2); }); it('69. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-inline-sidebar')!.parentElement).to.equal(c); }); it('70. createElement', async () => { const el = document.createElement('nile-inline-sidebar') as NileInlineSidebar; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('71. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('72. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('73. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('74. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('75. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('76. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('77. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('78. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('79. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('80. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('81. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Sidebar'); }); it('82. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('navigation'); }); it('83. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('84. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('S'); }); it('85. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('86. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('87. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('88. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('89. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('90. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('91. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('92. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('93. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('94. 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('95. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-inline-sidebar')).to.exist; }); it('96. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('97. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('98. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('99. 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('100. full integration', async () => { const el = await fixture(html`DashboardAnalyticsAdmin`); expect(el.placement).to.equal('right'); expect(el.id).to.equal('s1'); expect(el.getAttribute('aria-label')).to.equal('Nav'); expect(el.querySelectorAll('nile-inline-sidebar-item').length).to.equal(3); expect(el.shadowRoot!.querySelector('.sidebar')).to.exist; expect(el.shadowRoot!.querySelector('nav')).to.exist; }); });