import { expect, fixture, html } from '@open-wc/testing';
import './nile-error-message';
import type { NileErrorMessage } from './nile-error-message';
describe('NileErrorMessage', () => {
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-message'); });
it('4. errorMessage defaults empty', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal(''); });
it('5. isExpanded defaults false', async () => { const el = await fixture(html``); expect(el.isExpanded).to.be.false; });
it('6. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; });
it('7. icon part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="icon"]')).to.exist; });
it('8. nile-error-message class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message')).to.exist; });
it('9. icon element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nile-icon')).to.exist; });
it('10. error text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__error')!.textContent).to.equal('Error!'); });
it('11. no response default', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__response')).to.be.null; });
it('12. response shown', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__response')).to.exist; });
it('13. response text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__response')!.textContent).to.contain('Details'); });
it('14. collapsed class default', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.collapsed')).to.exist; });
it('15. expanded class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.expanded')).to.exist; });
it('16. toggleExpanded method', async () => { const el = await fixture(html``); expect(el.toggleExpanded).to.be.a('function'); });
it('17. toggle works', async () => { const el = await fixture(html``); el.toggleExpanded(); await el.updateComplete; expect(el.isExpanded).to.be.true; });
it('18. toggle twice', async () => { const el = await fixture(html``); el.toggleExpanded(); el.toggleExpanded(); await el.updateComplete; expect(el.isExpanded).to.be.false; });
it('19. getTruncatedResponse method', async () => { const el = await fixture(html``); expect(el.getTruncatedResponse).to.be.a('function'); });
it('20. truncation short', async () => { const el = await fixture(html``); expect(el.getTruncatedResponse()).to.equal('short'); });
it('21. truncation long', async () => { const el = await fixture(html``); expect(el.getTruncatedResponse()).to.contain('...'); });
it('22. more button with long response', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__more-button')).to.exist; });
it('23. view more text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__more-button')!.textContent).to.contain('View More'); });
it('24. view less text', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__more-button')!.textContent).to.contain('View Less'); });
it('25. response-expanded class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__response-expanded')).to.exist; });
it('26. errorResponseLong displayed', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__response-expanded')!.textContent).to.contain('Extended info'); });
it('27. dynamic errorMessage', async () => { const el = await fixture(html``); el.errorMessage = 'New Error'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-error-message__error')!.textContent).to.equal('New Error'); });
it('28. dynamic errorResponse', async () => { const el = await fixture(html``); el.errorResponse = 'Response'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-error-message__response')).to.exist; });
it('29. maxWidth applies', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-width')).to.equal('500px'); });
it('30. maxHeight applies', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-height')).to.equal('300px'); });
it('31. maxDialogHeight applies', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-dialog-height')).to.equal('400px'); });
it('32. has styles', async () => { expect((await import('./nile-error-message')).NileErrorMessage.styles).to.exist; });
it('33. is defined', async () => { expect(customElements.get('nile-error-message')).to.exist; });
it('34. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); });
it('35. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; });
it('36. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; });
it('37. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-error-message'); });
it('38. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-error-message.x')).to.be.true; });
it('39. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-error-message')).to.equal(el); });
it('40. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-error-message'); });
it('41. 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('42. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; });
it('43. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; });
it('44. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); });
it('45. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); });
it('46. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('e')).to.be.true; });
it('47. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('e1'); });
it('48. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); });
it('49. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); });
it('50. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; });
it('51. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); });
it('52. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); });
it('53. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-error-message').length).to.equal(2); });
it('54. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-error-message')!.parentElement).to.equal(c); });
it('55. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-error-message'); });
it('56. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); });
it('57. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); });
it('58. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; });
it('59. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); });
it('60. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; });
it('61. errorMessage type string', async () => { const el = await fixture(html``); expect(typeof el.errorMessage).to.equal('string'); });
it('62. isExpanded type boolean', async () => { const el = await fixture(html``); expect(typeof el.isExpanded).to.equal('boolean'); });
it('63. no slots', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(0); });
it('64. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); });
it('65. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); });
it('66. error span class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__error')).to.exist; });
it('67. icon class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__icon')).to.exist; });
it('68. nile-icon size', async () => { const el = await fixture(html``); const icon = el.shadowRoot!.querySelector('nile-icon'); expect(icon!.getAttribute('size')).to.equal('14'); });
it('69. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Error'); });
it('70. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('alert'); });
it('71. createElement', async () => { const el = document.createElement('nile-error-message') as NileErrorMessage; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); });
it('72. dynamic isExpanded', async () => { const el = await fixture(html``); el.isExpanded = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.expanded')).to.exist; });
it('73. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('E'); });
it('74. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); });
it('75. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); });
it('76. rapid toggle', async () => { const el = await fixture(html``); for (let i = 0; i < 5; i++) { el.toggleExpanded(); await el.updateComplete; } expect(el.isExpanded).to.be.true; });
it('77. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; });
it('78. childElementCount', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); });
it('79. innerHTML empty', async () => { const el = await fixture(html``); expect(el.innerHTML.trim()).to.equal(''); });
it('80. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); });
it('81. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); });
it('82. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); });
it('83. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); });
it('84. 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('85. more button icon', async () => { const el = await fixture(html``); const btn = el.shadowRoot!.querySelector('.nile-error-message__more-button'); expect(btn!.querySelector('nile-icon')).to.exist; });
it('86. no more button without long response', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-error-message__more-button')).to.be.null; });
it('87. errorMessage settable', async () => { const el = await fixture(html``); el.errorMessage = 'Err'; expect(el.errorMessage).to.equal('Err'); });
it('88. errorResponse settable', async () => { const el = await fixture(html``); el.errorResponse = 'Resp'; expect(el.errorResponse).to.equal('Resp'); });
it('89. errorResponseLong settable', async () => { const el = await fixture(html``); el.errorResponseLong = 'Long'; expect(el.errorResponseLong).to.equal('Long'); });
it('90. maxWidth settable', async () => { const el = await fixture(html``); el.maxWidth = '300px'; await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-width')).to.equal('300px'); });
it('91. maxHeight settable', async () => { const el = await fixture(html``); el.maxHeight = '200px'; await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-height')).to.equal('200px'); });
it('92. maxDialogHeight settable', async () => { const el = await fixture(html``); el.maxDialogHeight = '500px'; await el.updateComplete; expect(el.style.getPropertyValue('--nile-error-max-dialog-height')).to.equal('500px'); });
it('93. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; });
it('94. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; });
it('95. toggle after setting response', async () => { const el = await fixture(html``); el.toggleExpanded(); await el.updateComplete; expect(el.shadowRoot!.querySelector('.expanded')).to.exist; });
it('96. toggle updates icon name', async () => { const el = await fixture(html``); el.toggleExpanded(); await el.updateComplete; const icon = el.shadowRoot!.querySelector('.nile-error-message__more-button nile-icon'); expect(icon!.getAttribute('name')).to.contain('arrow-up'); });
it('97. no aria-expanded attr by default', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-expanded')).to.be.null; });
it('98. 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('.nile-error-message__error')!.textContent).to.equal('Error 4'); });
it('99. re-renders', async () => { const el = await fixture(html``); el.errorMessage = 'A'; await el.updateComplete; el.errorMessage = 'B'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-error-message__error')!.textContent).to.equal('B'); });
it('100. full integration', async () => { const el = await fixture(html``); expect(el.errorMessage).to.equal('Fail'); expect(el.errorResponse).to.equal('Details'); expect(el.errorResponseLong).to.equal('Extended'); expect(el.id).to.equal('e1'); expect(el.shadowRoot!.querySelector('.nile-error-message__response')).to.exist; expect(el.shadowRoot!.querySelector('.nile-error-message__more-button')).to.exist; });
});