import { expect, fixture, html } from '@open-wc/testing'; import './nile-form-help-text'; import type { NileFormHelpText } from './nile-form-help-text'; describe('NileFormHelpText', () => { 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-help-text'); }); it('4. isExpanded defaults false', async () => { const el = await fixture(html``); expect(el.isExpanded).to.be.false; }); it('5. container part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="container"]')).to.exist; }); it('6. nile-form-help-text class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-form-help-text')).to.exist; }); it('7. help__text__full class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.help__text__full')).to.exist; }); 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`Help text here`); expect(el.textContent).to.contain('Help text here'); }); it('10. expanded class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-form-help-text--expanded')).to.exist; }); it('11. expanded text class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.help__text__full--expanded')).to.exist; }); it('12. toggleExpanded method', async () => { const el = await fixture(html``); expect(el.toggleExpanded).to.be.a('function'); }); it('13. toggle works', async () => { const el = await fixture(html``); el.toggleExpanded(); await el.updateComplete; expect(el.isExpanded).to.be.true; }); it('14. toggle twice', async () => { const el = await fixture(html``); el.toggleExpanded(); el.toggleExpanded(); await el.updateComplete; expect(el.isExpanded).to.be.false; }); it('15. isExpanded reflected', async () => { const el = await fixture(html``); el.isExpanded = true; await el.updateComplete; expect(el.hasAttribute('isexpanded')).to.be.true; }); it('16. dynamic isExpanded', async () => { const el = await fixture(html``); el.isExpanded = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-form-help-text--expanded')).to.exist; }); it('17. has styles', async () => { expect((await import('./nile-form-help-text')).NileFormHelpText.styles).to.exist; }); it('18. is defined', async () => { expect(customElements.get('nile-form-help-text')).to.exist; }); it('19. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('20. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('21. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('22. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-form-help-text'); }); it('23. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-form-help-text.x')).to.be.true; }); it('24. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-form-help-text')).to.equal(el); }); it('25. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-form-help-text'); }); it('26. 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('27. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('28. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('29. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('30. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('31. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('f')).to.be.true; }); it('32. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('f1'); }); it('33. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('34. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('35. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('36. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('37. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('38. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-form-help-text').length).to.equal(2); }); it('39. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-form-help-text')!.parentElement).to.equal(c); }); it('40. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-form-help-text'); }); it('41. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('42. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('43. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('44. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('45. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('46. isExpanded type boolean', async () => { const el = await fixture(html``); expect(typeof el.isExpanded).to.equal('boolean'); }); it('47. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('48. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('49. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Help'); }); it('50. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('note'); }); it('51. createElement', async () => { const el = document.createElement('nile-form-help-text') as NileFormHelpText; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('52. decideToToggleShowButton method', async () => { const el = await fixture(html``); expect(el.decideToToggleShowButton).to.be.a('function'); }); it('53. observeWidthChange method', async () => { const el = await fixture(html``); expect(el.observeWidthChange).to.be.a('function'); }); it('54. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('H'); }); it('55. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('56. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('57. 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('58. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('59. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('60. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('61. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('62. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('63. 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('64. slot count', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('slot').length).to.equal(1); }); it('65. no anchor', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.be.null; }); it('66. no img', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('img')).to.be.null; }); it('67. children survived update', async () => { const el = await fixture(html`Help`); el.isExpanded = true; await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('68. nested elements', async () => { const el = await fixture(html`Bold help`); expect(el.querySelector('strong')).to.exist; }); it('69. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('70. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('71. text content', async () => { const el = await fixture(html`Test content`); expect(el.textContent).to.contain('Test content'); }); it('72. no children default', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('73. class toggle', async () => { const el = await fixture(html``); el.classList.toggle('active'); expect(el.classList.contains('active')).to.be.true; }); it('74. setAttribute class', async () => { const el = await fixture(html``); el.setAttribute('class', 'test'); expect(el.classList.contains('test')).to.be.true; }); it('75. 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('76. no video', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('video')).to.be.null; }); it('77. no audio', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('audio')).to.be.null; }); it('78. no canvas', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('canvas')).to.be.null; }); it('79. span element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('span')).to.exist; }); it('80. div element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.exist; }); it('81. no ul', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('ul')).to.be.null; }); it('82. no table', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('table')).to.be.null; }); it('83. no svg', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('svg')).to.be.null; }); it('84. aria-describedby', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('desc'); }); it('85. re-renders', async () => { const el = await fixture(html``); el.isExpanded = true; await el.updateComplete; el.isExpanded = false; await el.updateComplete; expect(el.shadowRoot!.querySelector('.nile-form-help-text--expanded')).to.be.null; }); it('86. nested in div', async () => { const c = await fixture(html`
Help
`); expect(c.querySelector('nile-form-help-text')).to.exist; }); it('87. multiple with content', async () => { const c = await fixture(html`
AB
`); const els = c.querySelectorAll('nile-form-help-text'); expect(els.length).to.equal(2); }); it('88. hasAttribute isexpanded', async () => { const el = await fixture(html``); await el.updateComplete; expect(el.hasAttribute('isexpanded')).to.be.true; }); it('89. removeAttribute isexpanded', async () => { const el = await fixture(html``); await el.updateComplete; el.removeAttribute('isexpanded'); await el.updateComplete; expect(el.isExpanded).to.be.false; }); it('90. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = '

New

'; expect(el.querySelector('p')!.textContent).to.equal('New'); }); it('91. children array', async () => { const el = await fixture(html`AB`); expect(el.children.length).to.equal(2); }); it('92. no select', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('select')).to.be.null; }); it('93. no textarea', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('textarea')).to.be.null; }); it('94. no h1', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('h1')).to.be.null; }); it('95. textContainer ref', async () => { const el = await fixture(html``); expect(el.textContainer).to.exist; }); it('96. dynamic content update', async () => { const el = await fixture(html`Old`); el.innerHTML = 'New'; await el.updateComplete; expect(el.textContent).to.contain('New'); }); it('97. no nav', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('nav')).to.be.null; }); it('98. no aside', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('aside')).to.be.null; }); it('99. shadow dom structure', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.nile-form-help-text')).to.exist; expect(el.shadowRoot!.querySelector('.help__text__full')).to.exist; }); it('100. full integration', async () => { const el = await fixture(html`This is help text`); expect(el.id).to.equal('fh1'); expect(el.textContent).to.contain('This is help text'); expect(el.shadowRoot!.querySelector('.nile-form-help-text')).to.exist; expect(el.shadowRoot!.querySelector('slot')).to.exist; }); });