Skip to content

Commit c676262

Browse files
chore: moar test cases
1 parent 39e7315 commit c676262

File tree

7 files changed

+224
-6
lines changed

7 files changed

+224
-6
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import './banner-cta.tsx';
3+
4+
describe('Components/Banner CTA', () => {
5+
let bannerCta: HTMLElement;
6+
7+
describe('Default Behavior', () => {
8+
const cta = 'npm i -D wc-compiler';
9+
10+
beforeEach(() => {
11+
bannerCta = document.createElement('wcc-banner-cta');
12+
13+
document.body.appendChild(bannerCta);
14+
});
15+
16+
it('should not be undefined', () => {
17+
expect(bannerCta).not.equal(undefined);
18+
});
19+
20+
it('should have the main overview text', () => {
21+
const paragraph = bannerCta.querySelectorAll('p');
22+
23+
expect(paragraph.length).equal(1);
24+
expect(paragraph[0].textContent.trim().replace(/\s+/g, ' ')).toContain(
25+
'WCC (WC Compiler) is a NodeJS based package for server-rendering native Web Components.',
26+
);
27+
});
28+
29+
it('should have the copy to clipboard snippet', () => {
30+
const pre = bannerCta.querySelectorAll('pre');
31+
32+
expect(pre.length).equal(1);
33+
expect(pre[0].textContent.trim()).equal(`$ ${cta}`);
34+
});
35+
36+
it('should have the copy to clipboard component', () => {
37+
const ctcButton = bannerCta.querySelectorAll('wcc-ctc-button');
38+
39+
expect(ctcButton.length).equal(1);
40+
expect(ctcButton[0].getAttribute('content')).equal(cta);
41+
});
42+
});
43+
44+
afterEach(() => {
45+
bannerCta.remove();
46+
bannerCta = undefined;
47+
});
48+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import './banner-splash.tsx';
3+
4+
describe('Components/Banner Splash', () => {
5+
let bannerSplash: HTMLElement;
6+
7+
describe('Default Behavior', () => {
8+
beforeEach(() => {
9+
bannerSplash = document.createElement('wcc-banner-splash');
10+
11+
document.body.appendChild(bannerSplash);
12+
});
13+
14+
it('should not be undefined', () => {
15+
expect(bannerSplash).not.equal(undefined);
16+
});
17+
18+
it('should have to the expected heading text', () => {
19+
const heading = bannerSplash.querySelectorAll('h1');
20+
21+
expect(heading.length).equal(1);
22+
expect(heading[0].textContent.trim().replace(/\s+/g, ' ')).equal('SSR for Web Components');
23+
});
24+
});
25+
26+
afterEach(() => {
27+
bannerSplash.remove();
28+
bannerSplash = undefined;
29+
});
30+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import './capability-box.tsx';
3+
4+
describe('Components/Capability Box', () => {
5+
let capabilityBox: HTMLElement;
6+
7+
describe('Default Behavior', () => {
8+
beforeEach(() => {
9+
capabilityBox = document.createElement('wcc-capability-box');
10+
11+
document.body.appendChild(capabilityBox);
12+
});
13+
14+
it('should not be undefined', () => {
15+
expect(capabilityBox).not.equal(undefined);
16+
});
17+
18+
it('should not have any heading text', () => {
19+
const heading = capabilityBox.querySelectorAll('h4');
20+
21+
expect(heading.length).equal(1);
22+
expect(heading[0].textContent).equal('');
23+
});
24+
});
25+
26+
describe('Custom Text and Heading', () => {
27+
const customHeading = 'JSX';
28+
const customContent = 'This is a custom feature box';
29+
30+
beforeEach(() => {
31+
capabilityBox = document.createElement('wcc-capability-box');
32+
capabilityBox.innerHTML = `<p>${customContent}</p>`;
33+
capabilityBox.setAttribute('heading', customHeading);
34+
35+
document.body.appendChild(capabilityBox);
36+
});
37+
38+
it('should not be undefined', () => {
39+
expect(capabilityBox).not.equal(undefined);
40+
});
41+
42+
it('should have the expected text from setting the heading attribute', () => {
43+
const heading = capabilityBox.querySelectorAll('h4');
44+
45+
expect(heading.length).equal(1);
46+
expect(heading[0].textContent).equal(customHeading);
47+
});
48+
49+
it('should have the expected inner HTML text', () => {
50+
const paragraph = capabilityBox.querySelectorAll('p');
51+
52+
expect(paragraph.length).equal(1);
53+
expect(paragraph[0].textContent).equal(customContent);
54+
});
55+
});
56+
57+
afterEach(() => {
58+
capabilityBox.remove();
59+
capabilityBox = undefined;
60+
});
61+
});

docs/components/capability-box/capability-box.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export default class CapabilityBox extends HTMLElement {
66
}
77

88
render() {
9-
const heading = this.getAttribute('heading');
9+
const heading = this.getAttribute('heading') ?? '';
1010
const { innerHTML } = this;
1111

1212
return (
1313
<div class={styles.container}>
14-
<span class={styles.heading}>{heading}</span>
14+
<h4 class={styles.heading}>{heading}</h4>
1515
{innerHTML}
1616
</div>
1717
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
});

docs/components/feature-box/feature-box.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ export default class FeatureBox extends HTMLElement {
1515
}
1616

1717
render() {
18-
const heading = this.getAttribute('heading');
18+
const heading = this.getAttribute('heading') ?? '';
1919
const { innerHTML } = this;
20-
const icon = FeatureBox.ICON_MAPPER[heading];
20+
const icon = FeatureBox.ICON_MAPPER[heading] ?? '';
2121

2222
return (
2323
<div class={styles.container}>
24-
<span class={styles.heading}>
24+
<h4 class={styles.heading}>
2525
<span class={styles.icon}>{icon}</span>
2626
<span>{heading}</span>
27-
</span>
27+
</h4>
2828
{innerHTML}
2929
</div>
3030
);

vitest.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ export default defineConfig({
108108
provider: 'v8',
109109
include: ['./docs/components/**'],
110110
exclude: ['./docs/components/sandbox/**'],
111+
thresholds: {
112+
lines: 65,
113+
functions: 75,
114+
branches: 50,
115+
statements: 65,
116+
},
111117
},
112118
},
113119
plugins: [transformJsx(), transformRawImports(), transformConstructableStylesheetsPlugin()],

0 commit comments

Comments
 (0)