Skip to content

Commit 49d21b4

Browse files
authored
test(discordbutton-mouse-interactivity): add hover interaction coverage (JhaSourav07#3304)
## Description Fixes JhaSourav07#2737 ## Summary Added mouse interaction coverage for `DiscordButton` hover behavior and GSAP animation handling. ## Changes Made * Added hover interaction test cases * Verified GSAP animation triggers during mouse movement * Verified transform reset behavior on mouse leave * Added interaction-focused coverage without duplicating existing render tests ## Validation ```bash npx vitest components/DiscordButton.test.tsx npm run lint npm run format ``` ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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): ...`). - [] 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 bae8288 + 3231c16 commit 49d21b4

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

components/DiscordButton.test.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render, screen, fireEvent } from '@testing-library/react';
22
import '@testing-library/jest-dom/vitest';
3-
import { describe, expect, it, vi } from 'vitest';
3+
import { describe, expect, it, vi, beforeEach } from 'vitest';
4+
import gsap from 'gsap';
45
import { DiscordButton } from './DiscordButton';
56
// Mock framer-motion
67
vi.mock('framer-motion', () => ({
@@ -58,3 +59,53 @@ describe('DiscordButton', () => {
5859
expect(link).toHaveAttribute('target', '_blank');
5960
});
6061
});
62+
63+
describe('DiscordButton mouse interactivity', () => {
64+
beforeEach(() => {
65+
vi.clearAllMocks();
66+
});
67+
68+
it('sets hover state on mouse enter', () => {
69+
render(<DiscordButton />);
70+
71+
const link = screen.getByRole('link');
72+
73+
fireEvent.mouseEnter(link);
74+
75+
expect(link).toBeInTheDocument();
76+
});
77+
78+
it('triggers gsap animation on mouse move while hovered', () => {
79+
render(<DiscordButton />);
80+
81+
const link = screen.getByRole('link');
82+
83+
fireEvent.mouseEnter(link);
84+
85+
fireEvent.mouseMove(link, {
86+
clientX: 100,
87+
clientY: 50,
88+
});
89+
90+
expect(gsap.to).toHaveBeenCalled();
91+
});
92+
93+
it('resets gsap transforms on mouse leave', () => {
94+
render(<DiscordButton />);
95+
96+
const link = screen.getByRole('link');
97+
98+
fireEvent.mouseEnter(link);
99+
fireEvent.mouseLeave(link);
100+
101+
expect(gsap.to).toHaveBeenCalledWith(
102+
expect.anything(),
103+
expect.objectContaining({
104+
x: 0,
105+
y: 0,
106+
rotationX: 0,
107+
rotationY: 0,
108+
})
109+
);
110+
});
111+
});

0 commit comments

Comments
 (0)