import { expect, fixture, html } from '@open-wc/testing'; import './nile-form-error-message'; import type { NileFormErrorMessage } from './nile-form-error-message'; describe('NileFormErrorMessage', () => { 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-form-error-message'); }); it('4. nile-form-error-message class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-form-error-message')).to.exist; }); it('5. nile-icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; }); it('6. icon class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-form-error-message__icon')).to.exist; }); it('7. icon size 14', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('size')).to.equal('14'); }); it('8. slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot')).to.exist; }); it('9. slotted content', async () => { const el = await fixture(html`Error text`); expect(el.textContent).to.contain('Error text'); }); it('10. has styles', async () => { expect((await import('./nile-form-error-message')).NileFormErrorMessage.styles).to.exist; }); it('11. is defined', async () => { expect(customElements.get('nile-form-error-message')).to.exist; }); it('12. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('13. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('14. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('15. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-form-error-message'); }); it('16. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-form-error-message.x')).to.be.true; }); it('17. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-form-error-message')).to.equal(el); }); it('18. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-form-error-message'); }); it('19. 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('20. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('21. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('22. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('23. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('24. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('e')).to.be.true; }); it('25. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('e1'); }); it('26. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('27. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('28. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('29. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('30. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('31. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-form-error-message').length).to.equal(2); }); it('32. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-form-error-message')!.parentElement).to.equal(c); }); it('33. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-form-error-message'); }); it('34. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('35. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('36. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('37. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('38. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('39. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('40. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('41. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Error'); }); it('42. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('alert'); }); it('43. createElement', async () => { const el = document.createElement('nile-form-error-message') as NileFormErrorMessage; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('44. slot count', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('45. div element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.exist; }); it('46. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('E'); }); it('47. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('48. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('49. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('50. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('51. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('52. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('53. children survived update', async () => { const el = await fixture(html`Err`); el.requestUpdate(); await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('54. nested elements', async () => { const el = await fixture(html`Bold error`); expect(el.querySelector('strong')).to.exist; }); it('55. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('56. text content', async () => { const el = await fixture(html`Test error`); expect(el.textContent).to.contain('Test error'); }); it('57. no children default', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('58. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('active'); expect(el.classList.contains('active')).to.be.true; }); it('59. 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('60. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('61. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('62. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('63. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('64. 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('65. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = '

New

'; expect(el.querySelector('p')!.textContent).to.equal('New'); }); it('66. 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('67. nested in div', async () => { const c = await fixture(html`
Err
`); expect(c.querySelector('nile-form-error-message')).to.exist; }); it('68. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('69. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('70. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('71. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('72. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('73. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('74. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('75. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('76. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('77. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('78. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('79. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('80. no code', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('code')).to.be.null; }); it('81. children array', async () => { const el = await fixture(html`AB`); expect(el.children.length).to.equal(2); }); it('82. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('83. lastElementChild', async () => { const el = await fixture(html`A
B
`); expect(el.lastElementChild!.tagName.toLowerCase()).to.equal('div'); }); it('84. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('85. removeAttribute class', async () => { const el = await fixture(html``); el.removeAttribute('class'); expect(el.classList.contains('x')).to.be.false; }); it('86. hasAttribute id', async () => { const el = await fixture(html``); expect(el.hasAttribute('id')).to.be.true; }); it('87. getAttribute id', async () => { const el = await fixture(html``); expect(el.getAttribute('id')).to.equal('e1'); }); it('88. setAttribute id', async () => { const el = await fixture(html``); el.setAttribute('id', 'e2'); expect(el.id).to.equal('e2'); }); it('89. removeAttribute id', async () => { const el = await fixture(html``); el.removeAttribute('id'); expect(el.id).to.equal(''); }); it('90. innerHTML empty default', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); }); it('91. textContent empty default', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('92. setAttribute data', async () => { const el = await fixture(html``); el.setAttribute('data-err', 'true'); expect(el.dataset.err).to.equal('true'); }); it('93. append child', async () => { const el = await fixture(html``); const s = document.createElement('span'); s.textContent = 'New'; el.appendChild(s); expect(el.querySelector('span')).to.exist; }); it('94. remove child', async () => { const el = await fixture(html`E`); const s = el.querySelector('#s1')!; el.removeChild(s); expect(el.querySelector('#s1')).to.be.null; }); it('95. replaceChildren', async () => { const el = await fixture(html`Old`); const p = document.createElement('p'); p.textContent = 'New'; el.replaceChildren(p); expect(el.querySelector('p')).to.exist; expect(el.querySelector('span')).to.be.null; }); it('96. insertBefore', async () => { const el = await fixture(html`B`); const p = document.createElement('p'); p.textContent = 'A'; el.insertBefore(p, el.querySelector('#s1')!); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('p'); }); it('97. multiple with content', async () => { const c = await fixture(html`
AB
`); const els = c.querySelectorAll('nile-form-error-message'); expect(els.length).to.equal(2); }); it('98. contains', async () => { const el = await fixture(html`E`); expect(el.contains(el.querySelector('#s1'))).to.be.true; }); it('99. re-renders', async () => { const el = await fixture(html``); el.innerHTML = 'A'; await el.updateComplete; el.innerHTML = 'B'; await el.updateComplete; expect(el.textContent).to.contain('B'); }); it('100. full integration', async () => { const el = await fixture(html`This field is required`); expect(el.id).to.equal('e1'); expect(el.getAttribute('role')).to.equal('alert'); expect(el.textContent).to.contain('This field is required'); expect(el.shadowRoot!.querySelector('.nile-form-error-message')).to.exist; expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; expect(el.shadowRoot!.querySelector('slot')).to.exist; }); });