import { expect, fixture, html } from '@open-wc/testing'; import './nile-loader'; import type { NileLoader } from './nile-loader'; describe('NileLoader', () => { 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-loader'); }); it('4. label defaults empty', async () => { const el = await fixture(html``); expect(el.label).to.equal(''); }); it('5. size defaults lg', async () => { const el = await fixture(html``); expect(el.size).to.equal('lg'); }); it('6. margin defaults empty', async () => { const el = await fixture(html``); expect(el.margin).to.equal(''); }); it('7. variant defaults v1', async () => { const el = await fixture(html``); expect(el.variant).to.equal('v1'); }); it('8. propHeight defaults empty', async () => { const el = await fixture(html``); expect(el.propHeight).to.equal(''); }); it('9. propWidth defaults empty', async () => { const el = await fixture(html``); expect(el.propWidth).to.equal(''); }); it('10. loader container part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="loader-container"]')).to.exist; }); it('11. svg container part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="svg-container"]')).to.exist; }); it('12. v1 renders div', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-loader__v1')).to.exist; }); it('13. v2 renders svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-loader__v2')).to.exist; }); it('14. v3 renders svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-loader__v3')).to.exist; }); it('15. no label rendered', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="loader-label"]')).to.be.null; }); it('16. label rendered', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="loader-label"]')).to.exist; }); it('17. label text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.textContent).to.contain('Loading...'); }); it('18. sm size class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__container--sm')).to.exist; }); it('19. md size class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__container--md')).to.exist; }); it('20. lg size class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__container--lg')).to.exist; }); it('21. xl size class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__container--xl')).to.exist; }); it('22. loader__container class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__container')).to.exist; }); it('23. svg__container class v2', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.svg__container')).to.exist; }); it('24. dynamic label', async () => { const el = await fixture(html``); el.label = 'Wait'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="loader-label"]')).to.exist; }); it('25. dynamic size', async () => { const el = await fixture(html``); el.size = 'sm'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.loader__container--sm')).to.exist; }); it('26. dynamic variant', async () => { const el = await fixture(html``); el.variant = 'v2'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-loader__v2')).to.exist; }); it('27. has styles', async () => { expect((await import('./nile-loader')).NileLoader.styles).to.exist; }); it('28. is defined', async () => { expect(customElements.get('nile-loader')).to.exist; }); it('29. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('30. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('31. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('32. color default v1', async () => { const el = await fixture(html``); expect(el.color).to.contain('nile-colors-blue-500'); }); it('33. color settable', async () => { const el = await fixture(html``); expect(el.color).to.equal('red'); }); it('34. custom height width', async () => { const el = await fixture(html``); expect(el.propHeight).to.equal('100'); expect(el.propWidth).to.equal('100'); }); it('35. setSvgDimensions method', async () => { const el = await fixture(html``); expect(el.setSvgDimensions).to.be.a('function'); }); it('36. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-loader'); }); it('37. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-loader.x')).to.be.true; }); it('38. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-loader')).to.equal(el); }); it('39. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-loader'); }); it('40. 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('41. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('42. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('43. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('44. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('45. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('l')).to.be.true; }); it('46. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('l1'); }); it('47. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('48. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('49. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('50. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('51. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('52. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-loader').length).to.equal(2); }); it('53. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-loader')!.parentElement).to.equal(c); }); it('54. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-loader'); }); it('55. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('56. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('57. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('58. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('59. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('60. label type string', async () => { const el = await fixture(html``); expect(typeof el.label).to.equal('string'); }); it('61. size type string', async () => { const el = await fixture(html``); expect(typeof el.size).to.equal('string'); }); it('62. variant type string', async () => { const el = await fixture(html``); expect(typeof el.variant).to.equal('string'); }); it('63. color type string', async () => { const el = await fixture(html``); expect(typeof el.color).to.equal('string'); }); it('64. svg v2 viewBox', async () => { const el = await fixture(html``); const svg = el.shadowRoot!.querySelector('svg'); expect(svg!.getAttribute('viewBox')).to.equal('0 0 32 32'); }); it('65. svg v3 viewBox', async () => { const el = await fixture(html``); const svg = el.shadowRoot!.querySelector('svg'); expect(svg!.getAttribute('viewBox')).to.equal('0 0 32 32'); }); it('66. v2 has paths', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('path').length).to.equal(2); }); it('67. v3 has paths', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('path').length).to.equal(2); }); it('68. loader__label class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.loader__label')).to.exist; }); it('69. no slots', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(0); }); it('70. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('71. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('72. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Loading'); }); it('73. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('progressbar'); }); it('74. createElement', async () => { const el = document.createElement('nile-loader') as NileLoader; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('75. rapid size changes', async () => { const el = await fixture(html``); const sizes: Array<'sm'|'md'|'lg'|'xl'> = ['sm','md','lg','xl']; for (const s of sizes) { el.size = s; await el.updateComplete; } expect(el.size).to.equal('xl'); }); it('76. rapid variant changes', async () => { const el = await fixture(html``); for (const v of ['v1','v2','v3']) { el.variant = v; await el.updateComplete; } expect(el.variant).to.equal('v3'); }); it('77. remove label', async () => { const el = await fixture(html``); el.label = ''; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="loader-label"]')).to.be.null; }); it('78. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('Loader'); }); it('79. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('80. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('81. v1 style inline', async () => { const el = await fixture(html``); const d = el.shadowRoot!.querySelector('.nile-loader__v1') as HTMLElement; expect(d.style.width).to.not.equal(''); }); it('82. height attr', async () => { const el = await fixture(html``); expect(el.propHeight).to.equal('80'); }); it('83. width attr', async () => { const el = await fixture(html``); expect(el.propWidth).to.equal('80'); }); it('84. innerHTML empty default', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); }); it('85. childElementCount', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(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. dynamic color', async () => { const el = await fixture(html``); el.color = 'green'; await el.updateComplete; expect(el.color).to.equal('green'); }); it('91. dynamic margin', async () => { const el = await fixture(html``); el.margin = '10px'; await el.updateComplete; expect(el.margin).to.equal('10px'); }); it('92. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('93. aria-busy', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-busy')).to.equal('true'); }); it('94. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('95. hasAttribute height', async () => { const el = await fixture(html``); expect(el.hasAttribute('height')).to.be.true; }); it('96. hasAttribute width', async () => { const el = await fixture(html``); expect(el.hasAttribute('width')).to.be.true; }); it('97. svg namespace v2', async () => { const el = await fixture(html``); const svg = el.shadowRoot!.querySelector('svg'); expect(svg!.getAttribute('xmlns')).to.equal('http://www.w3.org/2000/svg'); }); it('98. svg fill v2', async () => { const el = await fixture(html``); const svg = el.shadowRoot!.querySelector('svg'); expect(svg!.getAttribute('fill')).to.equal('none'); }); it('99. re-renders', async () => { const el = await fixture(html``); el.variant = 'v2'; await el.updateComplete; el.variant = 'v3'; await el.updateComplete; el.variant = 'v1'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-loader__v1')).to.exist; }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.label).to.equal('Loading'); expect(el.size).to.equal('md'); expect(el.variant).to.equal('v2'); expect(el.id).to.equal('l1'); expect(el.shadowRoot!.querySelector('.nile-loader__v2')).to.exist; expect(el.shadowRoot!.querySelector('[part="loader-label"]')).to.exist; }); });