|
| 1 | +import '@testing-library/jest-dom/vitest'; |
1 | 2 | import { describe, it, expect } from 'vitest'; |
2 | 3 | import { render } from '@testing-library/react'; |
| 4 | +import React from 'react'; |
3 | 5 | import { CommitPulseLogo } from './commitpulse-logo'; |
4 | 6 |
|
5 | 7 | describe('CommitPulseLogo Component', () => { |
6 | | - it('renders an <svg> element with proper viewport dimensions', () => { |
| 8 | + it('renders SVG element correctly', () => { |
7 | 9 | const { container } = render(<CommitPulseLogo />); |
8 | | - const svg = container.querySelector('svg'); |
| 10 | + const svgElement = container.querySelector('svg'); |
9 | 11 |
|
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'); |
12 | 16 | }); |
13 | 17 |
|
14 | | - it('asserts that path elements are drawn representing the pulse shape', () => { |
| 18 | + it('applies default className if none is provided', () => { |
15 | 19 | 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'); |
20 | 22 | }); |
21 | 23 |
|
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'); |
28 | 29 | }); |
29 | 30 |
|
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'); |
37 | 35 | }); |
38 | 36 |
|
39 | | - it('verifies theme colors map correctly to the SVG via currentColor', () => { |
| 37 | + it('renders required path elements for the logo geometry', () => { |
40 | 38 | const { container } = render(<CommitPulseLogo />); |
41 | | - const svg = container.querySelector('svg'); |
| 39 | + const paths = container.querySelectorAll('path'); |
| 40 | + expect(paths.length).toBe(4); |
42 | 41 |
|
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 | + ); |
46 | 47 | }); |
47 | 48 | }); |
0 commit comments