import { expect, fixture, html } from '@open-wc/testing'; import './nile-breadcrumb-item'; import type { NileBreadcrumbItem } from './nile-breadcrumb-item'; describe('NileBreadcrumbItem', () => { 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-breadcrumb-item'); }); it('4. separator default', async () => { const el = await fixture(html``); expect(el.separator).to.contain('nile-icon-arrow-right'); }); it('5. slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('6. nile-icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; }); it('7. arrow class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-breadcrumb-item__arrow')).to.exist; }); it('8. icon size 14', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('size')).to.equal('14'); }); it('9. slotted content', async () => { const el = await fixture(html`Home`); expect(el.textContent).to.contain('Home'); }); it('10. slot-text class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-breadcrumb-item__slot-text')).to.exist; }); it('11. custom separator', async () => { const el = await fixture(html``); expect(el.separator).to.equal('/'); }); it('12. has styles', async () => { expect((await import('./nile-breadcrumb-item')).NileBreadcrumbItem.styles).to.exist; }); it('13. is defined', async () => { expect(customElements.get('nile-breadcrumb-item')).to.exist; }); it('14. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('15. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('16. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('17. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-breadcrumb-item'); }); it('18. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-breadcrumb-item.x')).to.be.true; }); it('19. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-breadcrumb-item')).to.equal(el); }); it('20. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-breadcrumb-item'); }); it('21. 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('22. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('23. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('24. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('25. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('bi')).to.be.true; }); it('26. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('bi1'); }); it('27. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('28. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('29. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('30. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('31. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('32. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-breadcrumb-item'); }); it('33. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('34. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('35. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('36. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('37. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('38. separator type', async () => { const el = await fixture(html``); expect(typeof el.separator).to.equal('string'); }); it('39. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('40. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('41. single slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('42. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Item'); }); it('43. createElement', async () => { const el = document.createElement('nile-breadcrumb-item') as NileBreadcrumbItem; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('44. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('I'); }); it('45. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('46. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('47. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('48. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('49. focus', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('50. blur', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('51. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-breadcrumb-item').length).to.equal(2); }); it('52. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-breadcrumb-item')!.parentElement).to.equal(c); }); it('53. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('54. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('55. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('56. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('57. icon name matches separator', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('name')).to.equal('star'); }); it('58. icon aria-label', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.hasAttribute('aria-label')).to.be.true; }); it('59. dynamic separator', async () => { const el = await fixture(html``); el.separator = '/'; await el.updateComplete; const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('name')).to.equal('/'); }); it('60. children survived update', async () => { const el = await fixture(html`A`); el.separator = '/'; await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('61. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('62. text content', async () => { const el = await fixture(html`Test`); expect(el.textContent).to.contain('Test'); }); it('63. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('64. re-renders', async () => { const el = await fixture(html``); el.separator = '/'; await el.updateComplete; el.separator = '>'; await el.updateComplete; expect(el.separator).to.equal('>'); }); it('65. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('66. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('67. 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('68. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('69. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('70. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('71. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('72. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('73. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('74. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('75. no div', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.be.null; }); it('76. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = 'X'; expect(el.querySelector('span')!.textContent).to.equal('X'); }); it('77. setAttribute separator', async () => { const el = await fixture(html``); el.setAttribute('separator', '>'); await el.updateComplete; expect(el.separator).to.equal('>'); }); it('78. contains', async () => { const el = await fixture(html`T`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('79. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('80. children array', async () => { const el = await fixture(html`AB`); expect(el.children.length).to.equal(2); }); it('81. no children default', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('82. textContent empty default', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('83. hasAttribute separator', async () => { const el = await fixture(html``); expect(el.hasAttribute('separator')).to.be.true; }); it('84. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('85. no p', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('86. no span in shadow (only slot and nile-icon)', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.be.null; }); it('87. nested in div', async () => { const c = await fixture(html`
A
`); expect(c.querySelector('nile-breadcrumb-item')).to.exist; }); it('88. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('89. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('90. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('91. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('92. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('93. append child', async () => { const el = await fixture(html``); const s = document.createElement('span'); s.textContent = 'N'; el.appendChild(s); expect(el.querySelector('span')).to.exist; }); it('94. remove child', async () => { const el = await fixture(html`A`); el.removeChild(el.querySelector('#s1')!); expect(el.querySelector('#s1')).to.be.null; }); it('95. replaceChildren', async () => { const el = await fixture(html`Old`); const p = document.createElement('p'); el.replaceChildren(p); expect(el.querySelector('p')).to.exist; expect(el.querySelector('span')).to.be.null; }); it('96. nested in breadcrumb', async () => { const c = await fixture(html`A`); expect(c.querySelector('nile-breadcrumb-item')).to.exist; }); it('97. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('link'); }); it('98. no hr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); 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`Home`); expect(el.separator).to.equal('/'); expect(el.id).to.equal('bi1'); expect(el.textContent).to.contain('Home'); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; expect(el.shadowRoot!.querySelector('slot')).to.exist; }); });