import { expect, fixture, html } from '@open-wc/testing'; import './nile-drawer'; import type { NileDrawer } from './nile-drawer'; describe('NileDrawer', () => { 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-drawer'); }); it('4. open defaults false', async () => { const el = await fixture(html``); expect(el.open).to.equal(false); }); it('5. label defaults empty', async () => { const el = await fixture(html``); expect(el.label).to.equal(''); }); it('6. placement defaults end', async () => { const el = await fixture(html``); expect(el.placement).to.equal('end'); }); it('7. closeOnEscape defaults true', async () => { const el = await fixture(html``); expect(el.closeOnEscape).to.equal(true); }); it('8. set label', async () => { const el = await fixture(html``); expect(el.label).to.equal('Settings'); }); it('9. set placement start', async () => { const el = await fixture(html``); expect(el.placement).to.equal('start'); }); it('10. set placement top', async () => { const el = await fixture(html``); expect(el.placement).to.equal('top'); }); it('11. set placement bottom', async () => { const el = await fixture(html``); expect(el.placement).to.equal('bottom'); }); it('12. drawer class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.drawer')).to.exist; }); it('13. drawer__panel class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.drawer__panel')).to.exist; }); it('14. drawer__overlay class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.drawer__overlay')).to.exist; }); it('15. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('16. panel part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="panel"]')).to.exist; }); it('17. overlay part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="overlay"]')).to.exist; }); it('18. header part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="header"]')).to.exist; }); it('19. body part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="body"]')).to.exist; }); it('20. footer part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="footer"]')).to.exist; }); it('21. title part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="title"]')).to.exist; }); it('22. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot:not([name])')).to.exist; }); it('23. label slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="label"]')).to.exist; }); it('24. footer slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="footer"]')).to.exist; }); it('25. header-actions slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="header-actions"]')).to.exist; }); it('26. has nile-icon close', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; }); it('27. label reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('label')).to.be.true; }); it('28. placement reflects', async () => { const el = await fixture(html``); expect(el.getAttribute('placement')).to.equal('start'); }); it('29. has styles', async () => { expect((await import('./nile-drawer')).NileDrawer.styles).to.exist; }); it('30. is defined', async () => { expect(customElements.get('nile-drawer')).to.exist; }); it('31. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('32. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('33. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('34. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-drawer'); }); it('35. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('36. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-drawer')).to.equal(el); }); it('37. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-drawer'); }); it('38. 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('39. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('40. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('41. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('42. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('dr')).to.be.true; }); it('43. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('dr1'); }); it('44. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('45. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('46. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-drawer'); }); it('47. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('48. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('49. dynamic label', async () => { const el = await fixture(html``); el.label = 'New'; await el.updateComplete; expect(el.label).to.equal('New'); }); it('50. dynamic placement', async () => { const el = await fixture(html``); el.placement = 'start'; await el.updateComplete; expect(el.placement).to.equal('start'); }); it('51. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-drawer').length).to.equal(2); }); it('52. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-drawer')!.parentElement).to.equal(c); }); it('53. createElement', async () => { const el = document.createElement('nile-drawer') as NileDrawer; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('54. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('55. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('56. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('57. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('58. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('59. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('60. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('61. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('62. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('63. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('64. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Drawer'); }); it('65. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('66. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('67. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('68. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('69. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('70. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('71. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('72. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('73. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('74. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('75. 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('76. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-drawer')).to.exist; }); it('77. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('78. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('79. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('80. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('81. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('82. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('83. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('84. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('85. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('86. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('87. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('88. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('89. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('90. 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('91. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('92. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('93. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('94. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('DR'); }); it('95. show method', async () => { const el = await fixture(html``); expect(el.show).to.be.a('function'); }); it('96. hide method', async () => { const el = await fixture(html``); expect(el.hide).to.be.a('function'); }); it('97. close-button part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="close-button"]')).to.exist; }); it('98. header-actions part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="header-actions"]')).to.exist; }); it('99. dynamic closeOnEscape', async () => { const el = await fixture(html``); el.closeOnEscape = false; await el.updateComplete; expect(el.closeOnEscape).to.be.false; }); it('100. full integration', async () => { const el = await fixture(html`Content
Footer
`); expect(el.label).to.equal('Settings'); expect(el.placement).to.equal('start'); expect(el.id).to.equal('dr1'); expect(el.open).to.be.false; expect(el.shadowRoot!.querySelector('.drawer')).to.exist; expect(el.shadowRoot!.querySelector('.drawer__panel')).to.exist; }); });