Skip to content

Commit c6e25fa

Browse files
authored
test(VisualizationTooltip): add unit tests for tooltip rendering and positioning (JhaSourav07#3042)
## Description Adds a dedicated test suite for `VisualizationTooltip` covering its core rendering and positioning behavior. ## Changes - Added `components/dashboard/VisualizationTooltip.test.tsx` - Verified tooltip renders with `role="tooltip"` - Verified title is displayed correctly - Verified children content is rendered - Verified custom `x` and `y` coordinates are applied to tooltip styles - Verified nested React elements are rendered properly - Mocked `framer-motion` to isolate component behavior during testing Fixes JhaSourav07#2277 ## Pillar - [x] 🎨 Pillar 1 — New Theme Design - [x] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [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. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 7ab8de2 + 6de8910 commit c6e25fa

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// components/dashboard/VisualizationTooltip.test.tsx
2+
import { render, screen } from '@testing-library/react';
3+
import { describe, expect, it, vi } from 'vitest';
4+
import type { HTMLAttributes, ReactNode } from 'react';
5+
import VisualizationTooltip from './VisualizationTooltip';
6+
import '@testing-library/jest-dom/vitest';
7+
8+
// framer-motion mock
9+
vi.mock('framer-motion', () => ({
10+
motion: {
11+
div: ({ children, ...props }: HTMLAttributes<HTMLDivElement> & { children?: ReactNode }) => (
12+
<div {...props}>{children}</div>
13+
),
14+
},
15+
}));
16+
17+
describe('VisualizationTooltip', () => {
18+
it('renders tooltip role', () => {
19+
render(
20+
<VisualizationTooltip title="Tooltip Title" x={100} y={200}>
21+
Content
22+
</VisualizationTooltip>
23+
);
24+
25+
expect(screen.getByRole('tooltip')).toBeInTheDocument();
26+
});
27+
28+
it('renders title correctly', () => {
29+
render(
30+
<VisualizationTooltip title="Commits" x={100} y={200}>
31+
Content
32+
</VisualizationTooltip>
33+
);
34+
35+
expect(screen.getByText('Commits')).toBeInTheDocument();
36+
});
37+
38+
it('renders children content', () => {
39+
render(
40+
<VisualizationTooltip title="Title" x={100} y={200}>
41+
<span>5 contributions</span>
42+
</VisualizationTooltip>
43+
);
44+
45+
expect(screen.getByText('5 contributions')).toBeInTheDocument();
46+
});
47+
48+
it('applies x and y coordinates to style', () => {
49+
render(
50+
<VisualizationTooltip title="Title" x={150} y={250}>
51+
Content
52+
</VisualizationTooltip>
53+
);
54+
55+
const tooltip = screen.getByRole('tooltip');
56+
57+
expect(tooltip).toHaveStyle({
58+
left: '150px',
59+
top: '250px',
60+
});
61+
});
62+
63+
it('renders nested React elements passed as children', () => {
64+
render(
65+
<VisualizationTooltip title="Stats" x={10} y={20}>
66+
<>
67+
<div>Total: 10</div>
68+
<div>Today: 2</div>
69+
</>
70+
</VisualizationTooltip>
71+
);
72+
73+
expect(screen.getByText('Total: 10')).toBeInTheDocument();
74+
expect(screen.getByText('Today: 2')).toBeInTheDocument();
75+
});
76+
});

0 commit comments

Comments
 (0)