import { expect, fixture, html } from '@open-wc/testing'; import './nile-progress-bar'; import type { NileProgressBar } from './nile-progress-bar'; describe('NileProgressBar', () => { 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-progress-bar'); }); it('4. value defaults 0', async () => { const el = await fixture(html``); expect(el.value).to.equal(0); }); it('5. container part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="container"]')).to.exist; }); it('6. progress-bar part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="progress-bar"]')).to.exist; }); it('7. remaining part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="remaining"]')).to.exist; }); it('8. progress part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="progress"]')).to.exist; }); it('9. container class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-progress-bar__container')).to.exist; }); it('10. progress-bar class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-progress-bar__progress-bar')).to.exist; }); it('11. value reflected', async () => { const el = await fixture(html``); expect(el.getAttribute('value')).to.equal('50'); }); it('12. value settable', async () => { const el = await fixture(html``); expect(el.value).to.equal(30); }); it('13. progress width', async () => { const el = await fixture(html``); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('50%'); }); it('14. progress width 0', async () => { const el = await fixture(html``); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('0%'); }); it('15. progress width 100', async () => { const el = await fixture(html``); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('100%'); }); it('16. dynamic value', async () => { const el = await fixture(html``); el.value = 75; await el.updateComplete; const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('75%'); }); it('17. nile-complete at 100', async () => { const el = await fixture(html``); let fired = false; el.addEventListener('nile-complete', () => (fired = true)); el.value = 100; await el.updateComplete; expect(fired).to.be.true; }); it('18. no nile-complete below 100', async () => { const el = await fixture(html``); let fired = false; el.addEventListener('nile-complete', () => (fired = true)); el.value = 50; await el.updateComplete; expect(fired).to.be.false; }); it('19. invalid value reset', async () => { const el = await fixture(html``); el.value = 150; await el.updateComplete; expect(el.value).to.equal(0); }); it('20. negative value reset', async () => { const el = await fixture(html``); el.value = -10; await el.updateComplete; expect(el.value).to.equal(0); }); it('21. has styles', async () => { expect((await import('./nile-progress-bar')).NileProgressBar.styles).to.exist; }); it('22. is defined', async () => { expect(customElements.get('nile-progress-bar')).to.exist; }); it('23. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('24. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('25. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('26. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-progress-bar'); }); it('27. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-progress-bar.x')).to.be.true; }); it('28. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-progress-bar')).to.equal(el); }); it('29. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-progress-bar'); }); it('30. 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('31. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('32. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('33. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('34. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('35. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('p')).to.be.true; }); it('36. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('p1'); }); it('37. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('38. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('39. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('40. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('41. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('42. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-progress-bar').length).to.equal(2); }); it('43. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-progress-bar')!.parentElement).to.equal(c); }); it('44. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-progress-bar'); }); it('45. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('46. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('47. value type number', async () => { const el = await fixture(html``); expect(typeof el.value).to.equal('number'); }); it('48. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('49. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('50. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('51. ul element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.exist; }); it('52. li element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('li')).to.exist; }); it('53. span element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.exist; }); it('54. no slots', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(0); }); it('55. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('56. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('57. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Progress'); }); it('58. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('progressbar'); }); it('59. createElement', async () => { const el = document.createElement('nile-progress-bar') as NileProgressBar; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('60. setAttribute value', async () => { const el = await fixture(html``); el.setAttribute('value', '60'); await el.updateComplete; expect(el.value).to.equal(60); }); it('61. removeAttribute value', async () => { const el = await fixture(html``); el.removeAttribute('value'); await el.updateComplete; expect(el.getAttribute('value')).to.be.null; }); it('62. rapid value changes', async () => { const el = await fixture(html``); for (let i = 0; i <= 100; i += 25) { el.value = i; await el.updateComplete; } expect(el.value).to.equal(100); }); it('63. value 1', async () => { const el = await fixture(html``); expect(el.value).to.equal(1); }); it('64. value 99', async () => { const el = await fixture(html``); expect(el.value).to.equal(99); }); it('65. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('66. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('P'); }); it('67. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('68. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('69. childElementCount', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('70. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('71. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('72. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('73. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('74. value 25', async () => { const el = await fixture(html``); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('25%'); }); it('75. value 75', async () => { const el = await fixture(html``); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('75%'); }); it('76. 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('77. aria-valuenow', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-valuenow')).to.equal('50'); }); it('78. aria-valuemin', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-valuemin')).to.equal('0'); }); it('79. aria-valuemax', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-valuemax')).to.equal('100'); }); it('80. nile-complete detail', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('nile-complete', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); el.value = 100; await el.updateComplete; expect(detail).to.exist; }); it('81. dynamic value 0 to 100', async () => { const el = await fixture(html``); el.value = 100; await el.updateComplete; const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('100%'); }); it('82. value resets after invalid', async () => { const el = await fixture(html``); el.value = 200; await el.updateComplete; await el.updateComplete; expect(el.value).to.equal(0); }); it('83. textContent empty', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('84. innerHTML empty', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); }); it('85. hasAttribute value', async () => { const el = await fixture(html``); expect(el.hasAttribute('value')).to.be.true; }); it('86. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('87. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('88. shadow dom elements', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('div').length).to.be.greaterThanOrEqual(1); }); it('89. nested in div', async () => { const c = await fixture(html`
`); const el = c.querySelector('nile-progress-bar') as NileProgressBar; expect(el.value).to.equal(50); }); it('90. multiple with different values', async () => { const c = await fixture(html`
`); const els = c.querySelectorAll('nile-progress-bar'); expect((els[0] as NileProgressBar).value).to.equal(25); expect((els[1] as NileProgressBar).value).to.equal(75); }); it('91. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; el.hidden = false; expect(el.hidden).to.be.false; }); it('92. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('active'); expect(el.classList.contains('active')).to.be.true; }); it('93. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('94. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('95. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('96. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('97. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('98. value boundary 100', async () => { const el = await fixture(html``); expect(el.value).to.equal(100); }); it('99. value boundary 0', async () => { const el = await fixture(html``); expect(el.value).to.equal(0); }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.value).to.equal(50); expect(el.id).to.equal('p1'); expect(el.getAttribute('role')).to.equal('progressbar'); const p = el.shadowRoot!.querySelector('[part="progress"]') as HTMLElement; expect(p.style.width).to.equal('50%'); }); });