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