import { expect, fixture, html } from '@open-wc/testing'; import './nile-error-notification'; import type { NileErrorNotification } from './nile-error-notification'; describe('NileErrorNotification', () => { 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-error-notification'); }); it('4. errorMessage defaults empty', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal(''); }); it('5. color defaults empty', async () => { const el = await fixture(html``); expect(el.color).to.equal(''); }); it('6. container part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="container"]')).to.exist; }); it('7. icon part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="icon"]')).to.exist; }); it('8. message part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="message"]')).to.exist; }); it('9. nile-error-notification class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-notification')).to.exist; }); it('10. nile-icon', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; }); it('11. icon class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-notification__icon')).to.exist; }); it('12. icon size 14', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('size')).to.equal('14'); }); it('13. error message text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="message"]')!.textContent).to.contain('Error!'); }); it('14. errorMessage reflected', async () => { const el = await fixture(html``); expect(el.getAttribute('errormessage')).to.equal('E'); }); it('15. color reflected', async () => { const el = await fixture(html``); expect(el.getAttribute('color')).to.equal('red'); }); it('16. color css var set', async () => { const el = await fixture(html``); expect(el.style.getPropertyValue('--indication-color')).to.equal('red'); }); it('17. dynamic errorMessage', async () => { const el = await fixture(html``); el.errorMessage = 'New'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="message"]')!.textContent).to.contain('New'); }); it('18. dynamic color', async () => { const el = await fixture(html``); el.color = 'blue'; await el.updateComplete; expect(el.style.getPropertyValue('--indication-color')).to.equal('blue'); }); it('19. has styles', async () => { expect((await import('./nile-error-notification')).NileErrorNotification.styles).to.exist; }); it('20. is defined', async () => { expect(customElements.get('nile-error-notification')).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-error-notification'); }); it('25. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-error-notification.x')).to.be.true; }); it('26. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-error-notification')).to.equal(el); }); it('27. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-error-notification'); }); 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. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('31. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('32. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('33. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('n')).to.be.true; }); it('34. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('n1'); }); it('35. style attr', async () => { const el = await fixture(html``); expect(el.style.margin).to.equal('0px'); }); it('36. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('37. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('38. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('39. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('40. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-error-notification').length).to.equal(2); }); it('41. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-error-notification')!.parentElement).to.equal(c); }); it('42. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-error-notification'); }); it('43. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('44. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('45. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('46. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('47. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('48. errorMessage type', async () => { const el = await fixture(html``); expect(typeof el.errorMessage).to.equal('string'); }); it('49. color type', async () => { const el = await fixture(html``); expect(typeof el.color).to.equal('string'); }); it('50. no slots', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(0); }); it('51. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('52. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('53. span element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.exist; }); it('54. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('N'); }); it('55. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('alert'); }); it('56. createElement', async () => { const el = document.createElement('nile-error-notification') as NileErrorNotification; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('57. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('N'); }); it('58. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('59. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('60. rapid errorMessage changes', async () => { const el = await fixture(html``); for (let i = 0; i < 5; i++) { el.errorMessage = `Error ${i}`; await el.updateComplete; } expect(el.shadowRoot!.querySelector('[part="message"]')!.textContent).to.contain('Error 4'); }); it('61. rapid color changes', async () => { const el = await fixture(html``); el.color = 'red'; await el.updateComplete; el.color = 'green'; await el.updateComplete; expect(el.style.getPropertyValue('--indication-color')).to.equal('green'); }); it('62. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('63. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('64. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('65. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('66. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('67. 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('68. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('69. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('70. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('71. childElementCount', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('72. innerHTML empty', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); }); it('73. 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('74. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('active'); expect(el.classList.contains('active')).to.be.true; }); it('75. setAttribute errorMessage', async () => { const el = await fixture(html``); el.setAttribute('errormessage', 'Err'); await el.updateComplete; expect(el.errorMessage).to.equal('Err'); }); it('76. removeAttribute errorMessage', async () => { const el = await fixture(html``); el.removeAttribute('errormessage'); await el.updateComplete; expect(el.getAttribute('errormessage')).to.be.null; }); it('77. setAttribute color', async () => { const el = await fixture(html``); el.setAttribute('color', 'red'); await el.updateComplete; expect(el.color).to.equal('red'); }); it('78. hasAttribute errorMessage', async () => { const el = await fixture(html``); expect(el.hasAttribute('errormessage')).to.be.true; }); it('79. hasAttribute color', async () => { const el = await fixture(html``); expect(el.hasAttribute('color')).to.be.true; }); it('80. empty message text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="message"]')!.textContent!.trim()).to.equal(''); }); it('81. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('82. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('83. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('84. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('85. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('86. re-renders', async () => { const el = await fixture(html``); el.errorMessage = 'A'; await el.updateComplete; el.errorMessage = 'B'; await el.updateComplete; expect(el.shadowRoot!.querySelector('[part="message"]')!.textContent).to.contain('B'); }); it('87. nested in div', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-error-notification')).to.exist; }); it('88. multiple diff messages', async () => { const c = await fixture(html`
`); const els = c.querySelectorAll('nile-error-notification'); expect((els[0] as NileErrorNotification).errorMessage).to.equal('A'); expect((els[1] as NileErrorNotification).errorMessage).to.equal('B'); }); it('89. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('d'); }); it('90. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('91. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('92. no pre', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('pre')).to.be.null; }); it('93. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('94. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('95. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('96. contains check', async () => { const c = await fixture(html`
`); expect(c.contains(c.querySelector('nile-error-notification')!)).to.be.true; }); it('97. div element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.exist; }); it('98. textContent empty', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('99. icon name attr', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('name')).to.contain('nile-icon-info'); }); it('100. full integration', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal('Something failed'); expect(el.color).to.equal('red'); expect(el.id).to.equal('n1'); expect(el.shadowRoot!.querySelector('.nile-error-notification')).to.exist; expect(el.style.getPropertyValue('--indication-color')).to.equal('red'); }); });