|
| 1 | +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; |
| 2 | +import './feature-box.tsx'; |
| 3 | + |
| 4 | +describe('Components/Feature Box', () => { |
| 5 | + let featureBox: HTMLElement; |
| 6 | + |
| 7 | + describe('Default Behavior', () => { |
| 8 | + beforeEach(() => { |
| 9 | + featureBox = document.createElement('wcc-feature-box'); |
| 10 | + |
| 11 | + document.body.appendChild(featureBox); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should not be undefined', () => { |
| 15 | + expect(featureBox).not.equal(undefined); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should not have any heading text', () => { |
| 19 | + const heading = featureBox.querySelectorAll('h4'); |
| 20 | + |
| 21 | + expect(heading.length).equal(1); |
| 22 | + expect(heading[0].textContent.trim()).equal(''); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should not have an SVG mapped logo', () => { |
| 26 | + const logo = featureBox.querySelectorAll('svg'); |
| 27 | + |
| 28 | + expect(logo.length).equal(0); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('Custom Text and Heading', () => { |
| 33 | + const customHeading = 'JSX'; |
| 34 | + const customContent = 'This is a custom feature box'; |
| 35 | + |
| 36 | + beforeEach(() => { |
| 37 | + featureBox = document.createElement('wcc-feature-box'); |
| 38 | + featureBox.innerHTML = `<p>${customContent}</p>`; |
| 39 | + featureBox.setAttribute('heading', customHeading); |
| 40 | + |
| 41 | + document.body.appendChild(featureBox); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should not be undefined', () => { |
| 45 | + expect(featureBox).not.equal(undefined); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should have the expected text from setting the heading attribute', () => { |
| 49 | + const heading = featureBox.querySelectorAll('h4'); |
| 50 | + |
| 51 | + expect(heading.length).equal(1); |
| 52 | + expect(heading[0].textContent.trim()).equal(customHeading); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should have the expected inner HTML text', () => { |
| 56 | + const paragraph = featureBox.querySelectorAll('p'); |
| 57 | + |
| 58 | + expect(paragraph.length).equal(1); |
| 59 | + expect(paragraph[0].textContent).equal(customContent); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should not a mapped SVG logo', () => { |
| 63 | + const logo = featureBox.querySelectorAll('svg'); |
| 64 | + |
| 65 | + expect(logo.length).equal(1); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + afterEach(() => { |
| 70 | + featureBox.remove(); |
| 71 | + featureBox = undefined; |
| 72 | + }); |
| 73 | +}); |
0 commit comments