import { expect, fixture, html } from '@open-wc/testing'; import './nile-slide-toggle'; import type { NileSlideToggle } from './nile-slide-toggle'; describe('NileSlideToggle', () => { 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-slide-toggle'); }); it('4. label defaults empty', async () => { const el = await fixture(html``); expect(el.label).to.equal(''); }); it('5. sublabel defaults empty', async () => { const el = await fixture(html``); expect(el.sublabel).to.equal(''); }); it('6. textPosition defaults right', async () => { const el = await fixture(html``); expect(el.textPosition).to.equal('right'); }); it('7. isChecked defaults false', async () => { const el = await fixture(html``); expect(el.isChecked).to.equal(false); }); it('8. fullWidth defaults false', async () => { const el = await fixture(html``); expect(el.fullWidth).to.equal(false); }); it('9. disabled defaults false', async () => { const el = await fixture(html``); expect(el.disabled).to.equal(false); }); it('10. helpText defaults empty', async () => { const el = await fixture(html``); expect(el.helpText).to.equal(''); }); it('11. errorMessage defaults empty', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal(''); }); it('12. set label', async () => { const el = await fixture(html``); expect(el.label).to.equal('Toggle'); }); it('13. set sublabel', async () => { const el = await fixture(html``); expect(el.sublabel).to.equal('sub'); }); it('14. set isChecked', async () => { const el = await fixture(html``); expect(el.isChecked).to.be.true; }); it('15. set disabled', async () => { const el = await fixture(html``); expect(el.disabled).to.be.true; }); it('16. set fullWidth', async () => { const el = await fixture(html``); expect(el.fullWidth).to.be.true; }); it('17. set help-text', async () => { const el = await fixture(html``); expect(el.helpText).to.equal('Help'); }); it('18. set error-message', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal('Err'); }); it('19. nile-slide-toggle class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-slide-toggle')).to.exist; }); it('20. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('21. checkbox input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input[type="checkbox"]')).to.exist; }); it('22. slider span', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-slide-toggle__slider')).to.exist; }); it('23. label part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="slide-toggle-label"]')).to.exist; }); it('24. sublabel part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="slide-toggle-sublabel"]')).to.exist; }); it('25. switch part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="slide-toggle-switch"]')).to.exist; }); it('26. slider part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="slide-toggle-slider"]')).to.exist; }); it('27. disabled class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-slide--disabled')).to.exist; }); it('28. label displayed', async () => { const el = await fixture(html``); expect(el.shadowRoot!.textContent).to.contain('Toggle'); }); it('29. sublabel displayed', async () => { const el = await fixture(html``); expect(el.shadowRoot!.textContent).to.contain('Sub'); }); it('30. toggleValue method', async () => { const el = await fixture(html``); expect(el.toggleValue).to.be.a('function'); }); it('31. has styles', async () => { expect((await import('./nile-slide-toggle')).NileSlideToggle.styles).to.exist; }); it('32. is defined', async () => { expect(customElements.get('nile-slide-toggle')).to.exist; }); it('33. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('34. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('35. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('36. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-slide-toggle'); }); it('37. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('38. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-slide-toggle')).to.equal(el); }); it('39. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-slide-toggle'); }); 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. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('43. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('44. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('st')).to.be.true; }); it('45. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('st1'); }); it('46. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('47. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('48. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-slide-toggle'); }); it('49. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('50. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('51. dynamic isChecked', async () => { const el = await fixture(html``); el.isChecked = true; await el.updateComplete; expect(el.isChecked).to.be.true; }); it('52. dynamic disabled', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-slide--disabled')).to.exist; }); it('53. dynamic label', async () => { const el = await fixture(html``); el.label = 'New'; await el.updateComplete; expect(el.shadowRoot!.textContent).to.contain('New'); }); it('54. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-slide-toggle').length).to.equal(2); }); it('55. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-slide-toggle')!.parentElement).to.equal(c); }); it('56. createElement', async () => { const el = document.createElement('nile-slide-toggle') as NileSlideToggle; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('57. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('58. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('59. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('60. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('61. label element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('label')).to.exist; }); it('62. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('63. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('64. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('65. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('66. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('67. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Toggle'); }); it('68. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('69. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('70. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('71. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('72. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('73. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('74. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('75. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('76. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('77. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('78. 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('79. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-slide-toggle')).to.exist; }); it('80. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('81. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('82. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('83. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('84. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('85. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('86. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('87. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('88. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('89. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('90. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('91. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('92. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('93. 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('94. help-text shows nile-form-help-text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-form-help-text')).to.exist; }); it('95. error-message shows nile-form-error-message', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-form-error-message')).to.exist; }); it('96. no help-text without attr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-form-help-text')).to.be.null; }); it('97. no error-message without attr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-form-error-message')).to.be.null; }); it('98. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('ST'); }); it('99. textPosition left reverse class', async () => { const el = await fixture(html``); el.textPosition = 'left'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-slide-toggle--reverse')).to.exist; }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.label).to.equal('WiFi'); expect(el.sublabel).to.equal('Enable wireless'); expect(el.isChecked).to.be.true; expect(el.disabled).to.be.true; expect(el.helpText).to.equal('Help'); expect(el.id).to.equal('st1'); expect(el.shadowRoot!.querySelector('input[type="checkbox"]')).to.exist; }); });