import { expect, fixture, html } from '@open-wc/testing'; import './nile-breadcrumb'; import '../nile-breadcrumb-item/nile-breadcrumb-item'; import type { NileBreadcrumb } from './nile-breadcrumb'; describe('NileBreadcrumb', () => { it('1. renders', async () => { const el = await fixture(html`A`); expect(el).to.exist; }); it('2. shadow root', async () => { const el = await fixture(html`A`); expect(el.shadowRoot).to.not.be.null; }); it('3. tag name', async () => { const el = await fixture(html`A`); expect(el.tagName.toLowerCase()).to.equal('nile-breadcrumb'); }); it('4. slot', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('5. breadcrumb class', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('.breadcrumb')).to.exist; }); it('6. slotted items', async () => { const el = await fixture(html`AB`); expect(el.querySelectorAll('nile-breadcrumb-item').length).to.equal(2); }); it('7. has styles', async () => { expect((await import('./nile-breadcrumb')).NileBreadcrumb.styles).to.exist; }); it('8. is defined', async () => { expect(customElements.get('nile-breadcrumb')).to.exist; }); it('9. shadow mode', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.mode).to.equal('open'); }); it('10. isConnected', async () => { const el = await fixture(html`A`); expect(el.isConnected).to.be.true; }); it('11. removal', async () => { const el = await fixture(html`A`); el.remove(); expect(el.isConnected).to.be.false; }); it('12. outerHTML', async () => { const el = await fixture(html`A`); expect(el.outerHTML).to.contain('nile-breadcrumb'); }); it('13. matches', async () => { const el = await fixture(html`A`); expect(el.matches('nile-breadcrumb.x')).to.be.true; }); it('14. closest', async () => { const el = await fixture(html`A`); expect(el.closest('nile-breadcrumb')).to.equal(el); }); it('15. cloneNode', async () => { const el = await fixture(html`A`); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-breadcrumb'); }); it('16. dispatchEvent', async () => { const el = await fixture(html`A`); let f = false; el.addEventListener('c', () => (f = true)); el.dispatchEvent(new Event('c')); expect(f).to.be.true; }); it('17. updateComplete', async () => { const el = await fixture(html`A`); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('18. render method', async () => { const el = await fixture(html`A`); expect(el.render).to.be.a('function'); }); it('19. shadowRoot host', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.host).to.equal(el); }); it('20. class attr', async () => { const el = await fixture(html`A`); expect(el.classList.contains('b')).to.be.true; }); it('21. id attr', async () => { const el = await fixture(html`A`); expect(el.id).to.equal('b1'); }); it('22. style attr', async () => { const el = await fixture(html`A`); expect(el.style.color).to.equal('red'); }); it('23. data attr', async () => { const el = await fixture(html`A`); expect(el.getAttribute('data-x')).to.equal('1'); }); it('24. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('25. dir', async () => { const el = await fixture(html`A`); expect(el.dir).to.equal('rtl'); }); it('26. nodeType', async () => { const el = await fixture(html`A`); expect(el.nodeType).to.equal(1); }); it('27. localName', async () => { const el = await fixture(html`A`); expect(el.localName).to.equal('nile-breadcrumb'); }); it('28. namespaceURI', async () => { const el = await fixture(html`A`); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('29. ownerDocument', async () => { const el = await fixture(html`A`); expect(el.ownerDocument).to.equal(document); }); it('30. classList add', async () => { const el = await fixture(html`A`); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('31. dataset', async () => { const el = await fixture(html`A`); expect(el.dataset.idx).to.equal('0'); }); it('32. getBoundingClientRect', async () => { const el = await fixture(html`A`); expect(el.getBoundingClientRect()).to.exist; }); it('33. no inputs', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('34. no buttons', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('35. single slot', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('36. aria-label', async () => { const el = await fixture(html`A`); expect(el.getAttribute('aria-label')).to.equal('Breadcrumb'); }); it('37. role', async () => { const el = await fixture(html`A`); expect(el.getAttribute('role')).to.equal('navigation'); }); it('38. multiple items', async () => { const el = await fixture(html`ABC`); expect(el.querySelectorAll('nile-breadcrumb-item').length).to.equal(3); }); it('39. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('40. textContent', async () => { const el = await fixture(html`Home`); expect(el.textContent).to.contain('Home'); }); it('41. createElement', async () => { const el = document.createElement('nile-breadcrumb') as NileBreadcrumb; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('42. no form', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('43. no anchor', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('44. no img', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('45. title attr', async () => { const el = await fixture(html`A`); expect(el.title).to.equal('B'); }); it('46. lang attr', async () => { const el = await fixture(html`A`); expect(el.lang).to.equal('en'); }); it('47. tabindex', async () => { const el = await fixture(html`A`); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('48. shadow childNodes', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('49. scrollIntoView', async () => { const el = await fixture(html`A`); expect(el.scrollIntoView).to.be.a('function'); }); it('50. focus method', async () => { const el = await fixture(html`A`); expect(el.focus).to.be.a('function'); }); it('51. blur method', async () => { const el = await fixture(html`A`); expect(el.blur).to.be.a('function'); }); it('52. dispatchCustomEvent', async () => { const el = await fixture(html`A`); 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('53. no svg', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('54. parent-child', async () => { const c = await fixture(html`
A
`); expect(c.querySelector('nile-breadcrumb')!.parentElement).to.equal(c); }); it('55. multiple instances', async () => { const c = await fixture(html`
AB
`); expect(c.querySelectorAll('nile-breadcrumb').length).to.equal(2); }); it('56. class toggle', async () => { const el = await fixture(html`A`); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('57. toggle hidden', async () => { const el = await fixture(html`A`); el.hidden = true; expect(el.hidden).to.be.true; }); it('58. contains', async () => { const el = await fixture(html`A`); expect(el.contains(el.querySelector('#b1'))).to.be.true; }); it('59. no video', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('60. no audio', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('61. no canvas', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('62. no table', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('63. no ul', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('64. no nav', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('65. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('nile-breadcrumb-item'); }); it('66. requestUpdate', async () => { const el = await fixture(html`A`); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('67. innerHTML', async () => { const el = await fixture(html`A`); expect(el.innerHTML).to.contain('nile-breadcrumb-item'); }); it('68. re-renders', async () => { const el = await fixture(html`A`); el.requestUpdate(); await el.updateComplete; el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('69. hasAttribute class', async () => { const el = await fixture(html`A`); expect(el.hasAttribute('class')).to.be.true; }); it('70. setAttribute class', async () => { const el = await fixture(html`A`); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('71. removeAttribute class', async () => { const el = await fixture(html`A`); el.removeAttribute('class'); expect(el.classList.contains('x')).to.be.false; }); it('72. no h1', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('73. no aside', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('74. no pre', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('75. no code', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('76. no select', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('77. no textarea', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('78. aria-describedby', async () => { const el = await fixture(html`A`); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('79. no div', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('div')).to.be.null; }); it('80. no span', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('span')).to.be.null; }); it('81. children array', async () => { const el = await fixture(html`AB`); expect(el.children.length).to.equal(2); }); it('82. lastElementChild', async () => { const el = await fixture(html`AB`); expect(el.lastElementChild!.textContent).to.contain('B'); }); it('83. no nile-icon in shadow', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('nile-icon')).to.be.null; }); it('84. no nile-button in shadow', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('nile-button')).to.be.null; }); it('85. text of items', async () => { const el = await fixture(html`HomeSettings`); expect(el.textContent).to.contain('Home'); expect(el.textContent).to.contain('Settings'); }); it('86. item index 0', async () => { const el = await fixture(html`AB`); expect(el.querySelectorAll('nile-breadcrumb-item')[0].textContent).to.contain('A'); }); it('87. item index 1', async () => { const el = await fixture(html`AB`); expect(el.querySelectorAll('nile-breadcrumb-item')[1].textContent).to.contain('B'); }); it('88. nested in div', async () => { const c = await fixture(html`
A
`); expect(c.querySelector('nile-breadcrumb')).to.exist; }); it('89. no list', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('li')).to.be.null; }); it('90. no ol', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('ol')).to.be.null; }); it('91. no p', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('92. no hr', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); it('93. no br', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('br')).to.be.null; }); it('94. only slot in shadow', async () => { const el = await fixture(html`A`); const elements = el.shadowRoot!.querySelectorAll('*'); expect(Array.from(elements).some(e => e.tagName.toLowerCase() === 'slot')).to.be.true; }); it('95. three items', async () => { const el = await fixture(html`ABC`); expect(el.childElementCount).to.equal(3); }); it('96. four items', async () => { const el = await fixture(html`ABCD`); expect(el.childElementCount).to.equal(4); }); it('97. single item', async () => { const el = await fixture(html`Only`); expect(el.childElementCount).to.equal(1); }); it('98. slot is default (no name)', async () => { const el = await fixture(html`A`); const slot = el.shadowRoot!.querySelector('slot'); expect(slot!.hasAttribute('name')).to.be.false; }); it('99. no nile-divider', async () => { const el = await fixture(html`A`); expect(el.shadowRoot!.querySelector('nile-divider')).to.be.null; }); it('100. full integration', async () => { const el = await fixture(html`HomeSettingsProfile`); expect(el.id).to.equal('b1'); expect(el.getAttribute('role')).to.equal('navigation'); expect(el.querySelectorAll('nile-breadcrumb-item').length).to.equal(3); expect(el.textContent).to.contain('Home'); expect(el.textContent).to.contain('Profile'); }); });