Skip to content

Commit 7d44472

Browse files
committed
test: add unit tests for commitpulse-logo component
1 parent 41222eb commit 7d44472

2 files changed

Lines changed: 36 additions & 28 deletions

File tree

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1+
import '@testing-library/jest-dom/vitest';
12
import { describe, it, expect } from 'vitest';
23
import { render } from '@testing-library/react';
4+
import React from 'react';
35
import { CommitPulseLogo } from './commitpulse-logo';
46

57
describe('CommitPulseLogo Component', () => {
6-
it('renders an <svg> element with proper viewport dimensions', () => {
8+
it('renders SVG element correctly', () => {
79
const { container } = render(<CommitPulseLogo />);
8-
const svg = container.querySelector('svg');
10+
const svgElement = container.querySelector('svg');
911

10-
expect(svg).not.toBeNull();
11-
expect(svg?.getAttribute('viewBox')).toBe('0 0 24 24');
12+
expect(svgElement).toBeInTheDocument();
13+
expect(svgElement).toHaveAttribute('viewBox', '0 0 24 24');
14+
expect(svgElement).toHaveAttribute('fill', 'none');
15+
expect(svgElement).toHaveAttribute('stroke', 'currentColor');
1216
});
1317

14-
it('asserts that path elements are drawn representing the pulse shape', () => {
18+
it('applies default className if none is provided', () => {
1519
const { container } = render(<CommitPulseLogo />);
16-
const paths = container.querySelectorAll('path');
17-
18-
// The component specifically draws 4 geometric paths
19-
expect(paths.length).toBe(4);
20+
const svgElement = container.querySelector('svg');
21+
expect(svgElement).toHaveClass('h-5', 'w-5');
2022
});
2123

22-
it('verifies support for custom className properties', () => {
23-
const testClass = 'custom-pulse-class';
24-
const { container } = render(<CommitPulseLogo className={testClass} />);
25-
const svg = container.querySelector('svg');
26-
27-
expect(svg?.classList.contains(testClass)).toBe(true);
24+
it('applies custom className passed via props', () => {
25+
const { container } = render(<CommitPulseLogo className="h-10 w-10 text-red-500" />);
26+
const svgElement = container.querySelector('svg');
27+
expect(svgElement).toHaveClass('h-10', 'w-10', 'text-red-500');
28+
expect(svgElement).not.toHaveClass('h-5', 'w-5');
2829
});
2930

30-
it('verifies support for custom width and height properties via Tailwind classes', () => {
31-
const { container } = render(<CommitPulseLogo className="w-12 h-12" />);
32-
const svg = container.querySelector('svg');
33-
34-
// The default h-5 w-5 should be replaced or overridden by the provided class
35-
expect(svg?.classList.contains('w-12')).toBe(true);
36-
expect(svg?.classList.contains('h-12')).toBe(true);
31+
it('sets aria-hidden to true for accessibility', () => {
32+
const { container } = render(<CommitPulseLogo />);
33+
const svgElement = container.querySelector('svg');
34+
expect(svgElement).toHaveAttribute('aria-hidden', 'true');
3735
});
3836

39-
it('verifies theme colors map correctly to the SVG via currentColor', () => {
37+
it('renders required path elements for the logo geometry', () => {
4038
const { container } = render(<CommitPulseLogo />);
41-
const svg = container.querySelector('svg');
39+
const paths = container.querySelectorAll('path');
40+
expect(paths.length).toBe(4);
4241

43-
// For Tailwind text-* classes to color the SVG, stroke must be currentColor and fill must be none
44-
expect(svg?.getAttribute('stroke')).toBe('currentColor');
45-
expect(svg?.getAttribute('fill')).toBe('none');
42+
// Check that one of the path d-attributes matches the 3D box frame
43+
const pathDAttributes = Array.from(paths).map((p) => p.getAttribute('d'));
44+
expect(pathDAttributes).toContain(
45+
'M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z'
46+
);
4647
});
4748
});

vercel.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"ignoreCommand": "bash vercel-ignore.sh"
2+
"ignoreCommand": "bash vercel-ignore.sh",
3+
"git": {
4+
"deploymentEnabled": {
5+
"main": true,
6+
"fix/issue-*": false,
7+
"test/*": false
8+
}
9+
}
310
}

0 commit comments

Comments
 (0)