import { expect, fixture, html } from '@open-wc/testing'; import './nile-link'; import type { NileLink } from './nile-link'; describe('NileLink', () => { 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-link'); }); it('4. disabled defaults false', async () => { const el = await fixture(html``); expect(el.disabled).to.be.false; }); it('5. button defaults false', async () => { const el = await fixture(html``); expect(el.button).to.be.false; }); it('6. anchor element', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('a')).to.exist; }); it('7. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('8. link class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link')).to.exist; }); it('9. disabled class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; }); it('10. button class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link__button')).to.exist; }); it('11. prefix slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="prefix"]')).to.exist; }); it('12. default slot', async () => { const el = await fixture(html``); const s = el.shadowRoot!.querySelector('slot:not([name])'); expect(s).to.exist; }); it('13. suffix slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="suffix"]')).to.exist; }); it('14. prefix part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="prefix"]')).to.exist; }); it('15. label part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="label"]')).to.exist; }); it('16. suffix part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="suffix"]')).to.exist; }); it('17. href attr', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a') as HTMLAnchorElement; expect(a.href).to.contain('example.com'); }); it('18. disabled reflected', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('19. aria-disabled true', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a'); expect(a!.getAttribute('aria-disabled')).to.equal('true'); }); it('20. aria-disabled false', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a'); expect(a!.getAttribute('aria-disabled')).to.equal('false'); }); it('21. tabindex 0 enabled', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a'); expect(a!.getAttribute('tabindex')).to.equal('0'); }); it('22. tabindex -1 disabled', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a'); expect(a!.getAttribute('tabindex')).to.equal('-1'); }); it('23. link__prefix class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link__prefix')).to.exist; }); it('24. link__label class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link__label')).to.exist; }); it('25. link__suffix class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link__suffix')).to.exist; }); it('26. slotted prefix', async () => { const el = await fixture(html`P`); expect(el.querySelector('[slot="prefix"]')).to.exist; }); it('27. slotted suffix', async () => { const el = await fixture(html`S`); expect(el.querySelector('[slot="suffix"]')).to.exist; }); it('28. slotted content', async () => { const el = await fixture(html`Click me`); expect(el.textContent).to.contain('Click me'); }); it('29. dynamic disabled', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; }); it('30. dynamic disabled off', async () => { const el = await fixture(html``); el.disabled = false; await el.updateComplete; expect(el.shadowRoot!.querySelector('.link--disabled')).to.be.null; }); it('31. dynamic button', async () => { const el = await fixture(html``); el.button = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.link__button')).to.exist; }); it('32. dynamic href', async () => { const el = await fixture(html``); el.href = 'https://test.com'; await el.updateComplete; const a = el.shadowRoot!.querySelector('a') as HTMLAnchorElement; expect(a.href).to.contain('test.com'); }); it('33. has styles', async () => { expect((await import('./nile-link')).NileLink.styles).to.exist; }); it('34. is defined', async () => { expect(customElements.get('nile-link')).to.exist; }); it('35. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('36. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('37. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('38. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-link'); }); it('39. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-link.x')).to.be.true; }); it('40. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-link')).to.equal(el); }); it('41. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-link'); }); it('42. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('43. 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('44. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('45. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('46. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('47. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('48. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('l')).to.be.true; }); it('49. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('l1'); }); it('50. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('51. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('52. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('53. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('54. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('55. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-link').length).to.equal(2); }); it('56. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-link')!.parentElement).to.equal(c); }); it('57. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-link'); }); it('58. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('59. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('60. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('61. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('62. hasAttribute disabled', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('63. removeAttribute disabled', async () => { const el = await fixture(html``); el.removeAttribute('disabled'); await el.updateComplete; expect(el.disabled).to.be.false; }); it('64. setAttribute disabled', async () => { const el = await fixture(html``); el.setAttribute('disabled', ''); await el.updateComplete; expect(el.disabled).to.be.true; }); it('65. no disabled class default', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link--disabled')).to.be.null; }); it('66. no button class default', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link__button')).to.be.null; }); it('67. disabled type', async () => { const el = await fixture(html``); expect(typeof el.disabled).to.equal('boolean'); }); it('68. button type', async () => { const el = await fixture(html``); expect(typeof el.button).to.equal('boolean'); }); it('69. handleClick method', async () => { const el = await fixture(html``); expect(el.handleClick).to.be.a('function'); }); it('70. no forms', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('form').length).to.equal(0); }); it('71. no inputs', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('input').length).to.equal(0); }); it('72. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('73. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Link'); }); it('74. slot count', async () => { const el = await fixture(html``); const slots = el.shadowRoot!.querySelectorAll('slot'); expect(slots.length).to.equal(3); }); it('75. createElement', async () => { const el = document.createElement('nile-link') as NileLink; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('76. children survived update', async () => { const el = await fixture(html`Link`); el.disabled = true; await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('77. rapid toggles', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; el.disabled = false; await el.updateComplete; el.disabled = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; }); it('78. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('T'); }); it('79. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('80. anchor no href default', async () => { const el = await fixture(html``); const a = el.shadowRoot!.querySelector('a') as HTMLAnchorElement; expect(a.getAttribute('href')).to.be.null; }); it('81. text children', async () => { const el = await fixture(html`Test`); expect(el.textContent).to.contain('Test'); }); it('82. childElementCount', async () => { const el = await fixture(html`A`); expect(el.childElementCount).to.equal(1); }); it('83. firstElementChild', async () => { const el = await fixture(html`A`); expect(el.firstElementChild!.tagName.toLowerCase()).to.equal('span'); }); it('84. shadow childNodes', async () => { const el = await fixture(html``); expect(el.shadowRoot!.childNodes.length).to.be.greaterThan(0); }); it('85. no children default', async () => { const el = await fixture(html``); expect(el.childElementCount).to.equal(0); }); it('86. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = 'New'; expect(el.querySelector('span')!.textContent).to.equal('New'); }); it('87. combined disabled button', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; expect(el.shadowRoot!.querySelector('.link__button')).to.exist; }); it('88. nested elements', async () => { const el = await fixture(html`Bold text`); expect(el.querySelector('strong')).to.exist; }); it('89. slot prefix content', async () => { const el = await fixture(html`Link`); expect(el.querySelector('[slot="prefix"]')).to.exist; }); it('90. slot suffix content', async () => { const el = await fixture(html`Link`); expect(el.querySelector('[slot="suffix"]')).to.exist; }); it('91. aria attributes', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-describedby')).to.equal('desc'); expect(el.getAttribute('aria-haspopup')).to.equal('true'); }); it('92. dynamic all', async () => { const el = await fixture(html``); el.disabled = true; el.button = true; el.href = '#'; await el.updateComplete; expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; expect(el.shadowRoot!.querySelector('.link__button')).to.exist; }); it('93. re-renders', async () => { const el = await fixture(html``); for (let i = 0; i < 3; i++) { el.disabled = !el.disabled; await el.updateComplete; } expect(el.shadowRoot).to.not.be.null; }); it('94. dispatchCustomEvent', async () => { const el = await fixture(html``); let detail: any; el.addEventListener('test', ((e: CustomEvent) => { detail = e.detail; }) as EventListener); el.dispatchEvent(new CustomEvent('test', { detail: 'x' })); expect(detail).to.equal('x'); }); it('95. scrollIntoView', async () => { const el = await fixture(html``); expect(el.scrollIntoView).to.be.a('function'); }); it('96. focus method', async () => { const el = await fixture(html``); expect(el.focus).to.be.a('function'); }); it('97. blur method', async () => { const el = await fixture(html``); expect(el.blur).to.be.a('function'); }); it('98. tabindex attr', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('99. role attr', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('link'); }); it('100. full integration', async () => { const el = await fixture(html`PClickS`); expect(el.disabled).to.be.true; expect(el.href).to.equal('https://example.com'); expect(el.id).to.equal('l1'); expect(el.querySelector('[slot="prefix"]')).to.exist; expect(el.querySelector('[slot="suffix"]')).to.exist; expect(el.shadowRoot!.querySelector('.link--disabled')).to.exist; }); });