import { expect, fixture, html } from '@open-wc/testing'; import './nile-card'; import type { NileCard } from './nile-card'; describe('NileCard', () => { 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-card'); }); it('4. active defaults false', async () => { const el = await fixture(html``); expect(el.active).to.be.false; }); it('5. disabled defaults false', async () => { const el = await fixture(html``); expect(el.disabled).to.be.false; }); it('6. base part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; }); it('7. card class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card')).to.exist; }); it('8. active class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card--active')).to.exist; }); it('9. disabled class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card--disabled')).to.exist; }); it('10. header slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="header"]')).to.exist; }); it('11. default slot', async () => { const el = await fixture(html``); const slots = el.shadowRoot!.querySelectorAll('slot:not([name])'); expect(slots.length).to.be.greaterThan(0); }); it('12. footer slot', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('slot[name="footer"]')).to.exist; }); it('13. header part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="header"]')).to.exist; }); it('14. body part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="body"]')).to.exist; }); it('15. footer part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="footer"]')).to.exist; }); it('16. body__wrapper part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="body__wrapper"]')).to.exist; }); it('17. card__header class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card__header')).to.exist; }); it('18. card__body class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card__body')).to.exist; }); it('19. card__footer class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card__footer')).to.exist; }); it('20. active reflected', async () => { const el = await fixture(html``); expect(el.hasAttribute('active')).to.be.true; }); it('21. disabled reflected', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('22. no active class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card--active')).to.be.null; }); it('23. no disabled class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card--disabled')).to.be.null; }); it('24. dynamic active', async () => { const el = await fixture(html``); el.active = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--active')).to.exist; }); it('25. dynamic disabled', async () => { const el = await fixture(html``); el.disabled = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--disabled')).to.exist; }); it('26. toggle active off', async () => { const el = await fixture(html``); el.active = false; await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--active')).to.be.null; }); it('27. toggle disabled off', async () => { const el = await fixture(html``); el.disabled = false; await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--disabled')).to.be.null; }); it('28. slotted header', async () => { const el = await fixture(html`
Header
`); expect(el.querySelector('[slot="header"]')).to.exist; }); it('29. slotted body', async () => { const el = await fixture(html`

Body

`); expect(el.querySelector('p')).to.exist; }); it('30. slotted footer', async () => { const el = await fixture(html`
Footer
`); expect(el.querySelector('[slot="footer"]')).to.exist; }); it('31. footer hidden no slot', async () => { const el = await fixture(html``); const f = el.shadowRoot!.querySelector('slot[name="footer"]') as HTMLElement; expect(f.hidden).to.be.true; }); it('32. footer shown with slot', async () => { const el = await fixture(html`
F
`); await el.updateComplete; const f = el.shadowRoot!.querySelector('slot[name="footer"]') as HTMLElement; expect(f.hidden).to.be.false; }); it('33. has-footer class', async () => { const el = await fixture(html`
F
`); await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--has-footer')).to.exist; }); it('34. body_wrapper_nf class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.body__wrapper_nf')).to.exist; }); it('35. has styles', async () => { expect((await import('./nile-card')).NileCard.styles).to.exist; }); it('36. is defined', async () => { expect(customElements.get('nile-card')).to.exist; }); it('37. shadow mode', async () => { const el = await fixture(html``); expect(el.shadowRoot!.mode).to.equal('open'); }); it('38. isConnected', async () => { const el = await fixture(html``); expect(el.isConnected).to.be.true; }); it('39. removal', async () => { const el = await fixture(html``); el.remove(); expect(el.isConnected).to.be.false; }); it('40. outerHTML', async () => { const el = await fixture(html``); expect(el.outerHTML).to.contain('nile-card'); }); it('41. matches', async () => { const el = await fixture(html``); expect(el.matches('nile-card.x')).to.be.true; }); it('42. closest', async () => { const el = await fixture(html``); expect(el.closest('nile-card')).to.equal(el); }); it('43. cloneNode', async () => { const el = await fixture(html``); expect((el.cloneNode(true) as Element).tagName.toLowerCase()).to.equal('nile-card'); }); it('44. getBoundingClientRect', async () => { const el = await fixture(html``); expect(el.getBoundingClientRect()).to.exist; }); it('45. 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('46. updateComplete', async () => { const el = await fixture(html``); const r = await el.updateComplete; expect(r).to.not.be.undefined; }); it('47. requestUpdate', async () => { const el = await fixture(html``); el.requestUpdate(); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; }); it('48. render method', async () => { const el = await fixture(html``); expect(el.render).to.be.a('function'); }); it('49. shadowRoot host', async () => { const el = await fixture(html``); expect(el.shadowRoot!.host).to.equal(el); }); it('50. class attr', async () => { const el = await fixture(html``); expect(el.classList.contains('c')).to.be.true; }); it('51. id attr', async () => { const el = await fixture(html``); expect(el.id).to.equal('c1'); }); it('52. style attr', async () => { const el = await fixture(html``); expect(el.style.color).to.equal('red'); }); it('53. data attr', async () => { const el = await fixture(html``); expect(el.getAttribute('data-x')).to.equal('1'); }); it('54. hidden', async () => { const el = await fixture(html``); expect(el.hidden).to.be.true; }); it('55. dir', async () => { const el = await fixture(html``); expect(el.dir).to.equal('rtl'); }); it('56. nodeType', async () => { const el = await fixture(html``); expect(el.nodeType).to.equal(1); }); it('57. multiple instances', async () => { const c = await fixture(html`
`); expect(c.querySelectorAll('nile-card').length).to.equal(2); }); it('58. parent-child', async () => { const c = await fixture(html`
`); expect(c.querySelector('nile-card')!.parentElement).to.equal(c); }); it('59. localName', async () => { const el = await fixture(html``); expect(el.localName).to.equal('nile-card'); }); it('60. namespaceURI', async () => { const el = await fixture(html``); expect(el.namespaceURI).to.equal('http://www.w3.org/1999/xhtml'); }); it('61. ownerDocument', async () => { const el = await fixture(html``); expect(el.ownerDocument).to.equal(document); }); it('62. classList add', async () => { const el = await fixture(html``); el.classList.add('z'); expect(el.classList.contains('z')).to.be.true; }); it('63. dataset', async () => { const el = await fixture(html``); expect(el.dataset.idx).to.equal('0'); }); it('64. hasAttribute', async () => { const el = await fixture(html``); expect(el.hasAttribute('disabled')).to.be.true; }); it('65. removeAttribute disabled', async () => { const el = await fixture(html``); el.removeAttribute('disabled'); await el.updateComplete; expect(el.disabled).to.be.false; }); it('66. setAttribute active', async () => { const el = await fixture(html``); el.setAttribute('active', ''); await el.updateComplete; expect(el.active).to.be.true; }); it('67. active type', async () => { const el = await fixture(html``); expect(typeof el.active).to.equal('boolean'); }); it('68. disabled type', async () => { const el = await fixture(html``); expect(typeof el.disabled).to.equal('boolean'); }); it('69. createElement', async () => { const el = document.createElement('nile-card') as NileCard; document.body.appendChild(el); await el.updateComplete; expect(el.shadowRoot).to.not.be.null; document.body.removeChild(el); }); it('70. aria-label', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-label')).to.equal('Card'); }); it('71. tabindex', async () => { const el = await fixture(html``); expect(el.getAttribute('tabindex')).to.equal('0'); }); it('72. role', async () => { const el = await fixture(html``); expect(el.getAttribute('role')).to.equal('article'); }); it('73. both active disabled', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.card--active')).to.exist; expect(el.shadowRoot!.querySelector('.card--disabled')).to.exist; }); it('74. rapid toggles', async () => { const el = await fixture(html``); el.active = true; await el.updateComplete; el.active = false; await el.updateComplete; el.active = true; await el.updateComplete; expect(el.shadowRoot!.querySelector('.card--active')).to.exist; }); it('75. body__wrapper class', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('.body__wrapper')).to.exist; }); it('76. all header content', async () => { const el = await fixture(html`

Title

Body

`); expect(el.querySelector('h3')).to.exist; expect(el.querySelector('p')).to.exist; }); it('77. all slots filled', async () => { const el = await fixture(html`
H
B
F
`); expect(el.querySelectorAll('div').length).to.equal(3); }); it('78. slot count', async () => { const el = await fixture(html``); const slots = el.shadowRoot!.querySelectorAll('slot'); expect(slots.length).to.be.greaterThanOrEqual(3); }); it('79. no form', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('form')).to.be.null; }); it('80. no input', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('input')).to.be.null; }); it('81. title attr', async () => { const el = await fixture(html``); expect(el.title).to.equal('Card1'); }); it('82. lang attr', async () => { const el = await fixture(html``); expect(el.lang).to.equal('en'); }); it('83. no aria-expanded', async () => { const el = await fixture(html``); expect(el.getAttribute('aria-expanded')).to.be.null; }); it('84. innerHTML', async () => { const el = await fixture(html``); el.innerHTML = '

New

'; expect(el.querySelector('p')!.textContent).to.equal('New'); }); it('85. textContent empty default', async () => { const el = await fixture(html``); expect(el.textContent!.trim()).to.equal(''); }); it('86. text children', async () => { const el = await fixture(html`Text`); expect(el.textContent).to.contain('Text'); }); it('87. firstElementChild null', async () => { const el = await fixture(html``); expect(el.firstElementChild).to.be.null; }); it('88. children with slot', async () => { const el = await fixture(html`A`); expect(el.children.length).to.equal(1); }); it('89. childElementCount', async () => { const el = await fixture(html`AB`); expect(el.childElementCount).to.equal(2); }); it('90. querySelector in shadow', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('div')).to.exist; }); it('91. all parts', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="base"]')).to.exist; expect(el.shadowRoot!.querySelector('[part="body"]')).to.exist; expect(el.shadowRoot!.querySelector('[part="footer"]')).to.exist; }); it('92. body wrapper has correct part', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelector('[part="body__wrapper"]')).to.exist; }); it('93. removeAttribute active', async () => { const el = await fixture(html``); el.removeAttribute('active'); await el.updateComplete; expect(el.active).to.be.false; }); it('94. setAttribute disabled', async () => { const el = await fixture(html``); el.setAttribute('disabled', ''); await el.updateComplete; expect(el.disabled).to.be.true; }); it('95. no links', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('a').length).to.equal(0); }); it('96. no buttons', async () => { const el = await fixture(html``); expect(el.shadowRoot!.querySelectorAll('button').length).to.equal(0); }); it('97. children survived update', async () => { const el = await fixture(html`Child`); el.active = true; await el.updateComplete; expect(el.querySelector('#s1')).to.exist; }); it('98. nested cards', async () => { const el = await fixture(html``); expect(el.querySelector('nile-card')).to.exist; }); it('99. slot content check', async () => { const el = await fixture(html`
H
`); expect(el.querySelector('[slot="header"]')!.textContent).to.equal('H'); }); it('100. full integration', async () => { const el = await fixture(html`
H

Body

F
`); expect(el.active).to.be.true; expect(el.disabled).to.be.true; expect(el.id).to.equal('c1'); expect(el.shadowRoot!.querySelector('.card--active')).to.exist; expect(el.shadowRoot!.querySelector('.card--disabled')).to.exist; expect(el.querySelector('[slot="header"]')).to.exist; expect(el.querySelector('[slot="footer"]')).to.exist; }); });