import { expect, fixture, html } from '@open-wc/testing'; import './nile-filter-chip'; import type { NileFilterChip } from './nile-filter-chip'; describe('NileFilterChip', () => { 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-filter-chip'); }); it('4. label defaults empty', async () => { const el = await fixture(html``); expect(el.label).to.equal(''); }); it('5. value defaults empty', async () => { const el = await fixture(html``); expect(el.value).to.equal(''); }); it('6. viewMoreCount defaults 0', async () => { const el = await fixture(html``); expect(el.viewMoreCount).to.equal(0); }); it('7. editable defaults false', async () => { const el = await fixture(html``); expect(el.editable).to.be.false; }); it('8. closable defaults false', async () => { const el = await fixture(html``); expect(el.closable).to.be.false; }); it('9. icon defaults empty', async () => { const el = await fixture(html``); expect(el.icon).to.equal(''); }); it('10. removeIcon defaults empty', async () => { const el = await fixture(html``); expect(el.removeIcon).to.equal(''); }); it('11. active defaults false', async () => { const el = await fixture(html``); expect(el.active).to.be.false; }); it('12. chip class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.chip')).to.exist; }); it('13. label part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="label"]')).to.exist; }); it('14. value part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="value"]')).to.exist; }); it('15. label text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="label"]')!.textContent).to.contain('Status'); }); it('16. value text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="value"]')!.textContent).to.contain('Active'); }); it('17. label slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="label"]')).to.exist; }); it('18. value slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="value"]')).to.exist; }); it('19. icon slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="icon"]')).to.exist; }); it('20. suffix slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="suffix"]')).to.exist; }); it('21. content slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="content"]')).to.exist; }); it('22. close icon shown', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.close-icon')).to.exist; }); it('23. no close icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.close-icon')).to.be.null; }); it('24. badge with viewMoreCount', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-badge')).to.exist; }); it('25. no badge without viewMoreCount', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-badge')).to.be.null; }); it('26. icon span shown', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.icon')).to.exist; }); it('27. no icon span default', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.icon')).to.be.null; }); it('28. active reflected', async () => { const el = await fixture(html``); expect(el.hasAttribute('active')).to.be.true; }); it('29. nile-click event', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-click', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); el.shadowRoot!.querySelector('.chip')!.dispatchEvent(new Event('click', { bubbles: true })); expect(detail).to.exist; }); it('30. nile-click detail value', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-click', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); (el.shadowRoot!.querySelector('.chip') as HTMLElement).click(); expect(detail.value).to.equal('V'); }); it('31. dynamic label', async () => { const el = await fixture(html``); el.label = 'New'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="label"]')!.textContent).to.contain('New'); }); it('32. dynamic value', async () => { const el = await fixture(html``); el.value = 'Val'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="value"]')!.textContent).to.contain('Val'); }); it('33. dynamic closable', async () => { const el = await fixture(html``); el.closable = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.close-icon')).to.exist; }); it('34. dynamic active', async () => { const el = await fixture(html``); el.active = true; await el.updateComplete; expect(el.hasAttribute('active')).to.be.true; }); it('35. label-wrapper class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.label-wrapper')).to.exist; }); it('36. value-wrapper class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.value-wrapper')).to.exist; }); it('37. has styles', async () => { expect((await import('./nile-filter-chip')).NileFilterChip.styles).to.exist; }); it('38. is defined', async () => { expect(customElements.get('nile-filter-chip')).to.exist; }); it('39. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('40. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('41. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('42. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-filter-chip'); }); it('43. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-filter-chip.x')).to.be.true; }); it('44. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-filter-chip')).to.equal(el); }); it('45. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-filter-chip'); }); it('46. 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('47. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('48. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('49. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('50. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('51. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('f')).to.be.true; }); it('52. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('f1'); }); it('53. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('54. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('55. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('56. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('57. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('58. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-filter-chip').length).to.equal(2); }); it('59. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-filter-chip')!.parentElement).to.equal(c); }); it('60. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-filter-chip'); }); it('61. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('62. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('63. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('64. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('65. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('66. label type', async () => { const el = await fixture(html``); expect(typeof el.label).to.equal('string'); }); it('67. value type', async () => { const el = await fixture(html``); expect(typeof el.value).to.equal('string'); }); it('68. closable type', async () => { const el = await fixture(html``); expect(typeof el.closable).to.equal('boolean'); }); it('69. editable type', async () => { const el = await fixture(html``); expect(typeof el.editable).to.equal('boolean'); }); it('70. active type', async () => { const el = await fixture(html``); expect(typeof el.active).to.equal('boolean'); }); it('71. viewMoreCount type', async () => { const el = await fixture(html``); expect(typeof el.viewMoreCount).to.equal('number'); }); it('72. close icon nile-icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.close-icon nile-icon')).to.exist; }); it('73. badge-wrapper class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.badge-wrapper')).to.exist; }); it('74. badge part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="badge"]')).to.exist; }); it('75. badge text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.textContent).to.contain('+5'); }); it('76. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Filter'); }); it('77. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('button'); }); it('78. createElement', async () => { const el = document.createElement('nile-filter-chip') as NileFilterChip; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('79. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('F'); }); it('80. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('81. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('82. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('83. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('84. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('85. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('86. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('87. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('88. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('89. 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('90. label colon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="label"]')!.textContent).to.contain(':'); }); it('91. dynamic viewMoreCount', async () => { const el = await fixture(html``); el.viewMoreCount = 5; await el.updateComplete; expect(el.shadowRoot!.querySelector('nile-badge')).to.exist; }); it('92. removeIcon applies', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('.close-icon nile-icon'); expect(icon!.getAttribute('name')).to.equal('trash'); }); it('93. close icon size', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('.close-icon nile-icon'); expect(icon!.getAttribute('size')).to.equal('12'); }); it('94. dynamic icon', async () => { const el = await fixture(html``); el.icon = 'star'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.icon')).to.exist; }); it('95. slotted label', async () => { const el = await fixture(html`Custom`); expect(el.querySelector('[slot="label"]')).to.exist; }); it('96. slotted value', async () => { const el = await fixture(html`Custom`); expect(el.querySelector('[slot="value"]')).to.exist; }); it('97. slotted icon', async () => { const el = await fixture(html``); expect(el.querySelector('[slot="icon"]')).to.exist; }); it('98. rapid prop changes', async () => { const el = await fixture(html``); el.label = 'A'; el.value = 'B'; el.closable = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.close-icon')).to.exist; }); it('99. re-renders', async () => { const el = await fixture(html``); el.label = 'A'; await el.updateComplete; el.label = 'B'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="label"]')!.textContent).to.contain('B'); }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.label).to.equal('Status'); expect(el.value).to.equal('Active'); expect(el.closable).to.be.true; expect(el.viewMoreCount).to.equal(3); expect(el.active).to.be.true; expect(el.id).to.equal('f1'); expect(el.shadowRoot!.querySelector('.close-icon')).to.exist; expect(el.shadowRoot!.querySelector('nile-badge')).to.exist; }); });