Skip to content

Commit 6ea7a5b

Browse files
authored
test: add unit tests for commitpulse-logo component (JhaSourav07#3547)
## Description This PR implements unit tests for the CommitPulseLogo branding component, verifying default classes, custom SVG class override props, accessibility attributes (aria-hidden), and geometric layout path elements. Fixes JhaSourav07#3344 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Utility/Unit Tests only) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. - [ ] (Recommended) I joined the CommitPulse Discord community.
2 parents a85890e + 7d44472 commit 6ea7a5b

1 file changed

Lines changed: 28 additions & 27 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
});

0 commit comments

Comments
 (0)