import { expect, fixture, html } from '@open-wc/testing'; import './nile-radio'; import type { NileRadio } from './nile-radio'; describe('NileRadio', () => { 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-radio'); }); it('4. checked defaults false', async () => { const el = await fixture(html``); expect(el.checked).to.equal(false); }); it('5. value defaults empty', async () => { const el = await fixture(html``); expect(el.value).to.equal(''); }); it('6. size defaults medium', async () => { const el = await fixture(html``); expect(el.size).to.equal('medium'); }); it('7. disabled defaults false', async () => { const el = await fixture(html``); expect(el.disabled).to.equal(false); }); it('8. islabelborder defaults false', async () => { const el = await fixture(html``); expect(el.islabelborder).to.equal(false); }); it('9. allowUncheck defaults false', async () => { const el = await fixture(html``); expect(el.allowUncheck).to.equal(false); }); it('10. set checked', async () => { const el = await fixture(html``); expect(el.checked).to.be.true; }); it('11. set value', async () => { const el = await fixture(html``); expect(el.value).to.equal('opt1'); }); it('12. set size small', async () => { const el = await fixture(html``); expect(el.size).to.equal('small'); }); it('13. set disabled', async () => { const el = await fixture(html``); expect(el.disabled).to.be.true; }); it('14. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('15. control part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part~="control"]')).to.exist; }); it('16. label part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="label"]')).to.exist; }); it('17. default slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot:not([name])')).to.exist; }); it('18. slotted text', async () => { const el = await fixture(html`Option 1`); expect(el.textContent).to.contain('Option 1'); }); it('19. has styles', async () => { expect((await import('./nile-radio')).NileRadio.styles).to.exist; }); it('20. is defined', async () => { expect(customElements.get('nile-radio')).to.exist; }); it('21. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('22. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('23. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('24. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-radio'); }); it('25. matches', async () => { const el = await fixture(html``); expect(el.matches('.x')).to.be.true; }); it('26. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-radio')).to.equal(el); }); it('27. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-radio'); }); it('28. 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('29. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('30. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('31. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('32. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('rd')).to.be.true; }); it('33. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('r1'); }); it('34. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('35. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('36. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-radio'); }); it('37. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('38. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('39. dynamic checked', async () => { const el = await fixture(html``); el.checked = true; await el.updateComplete; expect(el.checked).to.be.true; }); it('40. dynamic value', async () => { const el = await fixture(html``); el.value = 'opt2'; await el.updateComplete; expect(el.value).to.equal('opt2'); }); it('41. dynamic disabled', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; expect(el.disabled).to.be.true; }); it('42. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-radio').length).to.equal(2); }); it('43. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-radio')!.parentElement).to.equal(c); }); it('44. createElement', async () => { const el = document.createElement('nile-radio') as NileRadio; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('45. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('46. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('47. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('48. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('49. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('50. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('51. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('52. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Radio'); }); it('53. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('54. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('55. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('-1'); }); it('56. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('57. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('58. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('59. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('a'); expect(el.classList.contains('a')).to.be.true; }); it('60. toggle hidden', async () => { const el = await fixture(html``); el.hidden = true; expect(el.hidden).to.be.true; }); it('61. 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('62. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-radio')).to.exist; }); it('63. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('64. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('65. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('66. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('67. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('68. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('69. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('70. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('71. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('72. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-test', '1'); expect(el.dataset.test).to.equal('1'); }); it('73. removeAttribute hidden', async () => { const el = await fixture(html``); el.removeAttribute('hidden'); expect(el.hidden).to.be.false; }); it('74. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('75. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('76. 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('77. size reflects', async () => { const el = await fixture(html``); expect(el.getAttribute('size')).to.equal('large'); }); it('78. disabled reflects', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('79. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('80. no button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('button')).to.be.null; }); it('81. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('82. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('RD'); }); it('83. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('84. no p', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('p')).to.be.null; }); it('85. no hr', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('hr')).to.be.null; }); it('86. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('87. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('88. radio class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.radio')).to.exist; }); it('89. radio__control class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.radio__control')).to.exist; }); it('90. radio__label class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.radio__label')).to.exist; }); it('91. contains', async () => { const el = await fixture(html`C`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('92. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('93. set islabelborder', async () => { const el = await fixture(html``); expect(el.islabelborder).to.be.true; }); it('94. set allowUncheck', async () => { const el = await fixture(html``); expect(el.allowUncheck).to.be.true; }); it('95. dynamic size', async () => { const el = await fixture(html``); el.size = 'large'; await el.updateComplete; expect(el.size).to.equal('large'); }); it('96. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('97. role attr', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('radio'); }); it('98. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('99. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('100. full integration', async () => { const el = await fixture(html`Option 1`); expect(el.value).to.equal('opt1'); expect(el.size).to.equal('large'); expect(el.checked).to.be.true; expect(el.disabled).to.be.true; expect(el.id).to.equal('r1'); expect(el.textContent).to.contain('Option 1'); }); });