Skip to content

Commit 292db5e

Browse files
authored
test(glow): add useGlowEffect hook tests (JhaSourav07#1237)
## Description Fixes JhaSourav07#1019 Added test coverage for the `useGlowEffect` hook. ### Test Coverage Added * Verifies the hook returns the expected public API. * Verifies `shellVars` contains the required CSS variable keys. * Verifies `--glow-opacity` defaults to `'0'`. * Verifies `cancelAnimationFrame` is called during cleanup after pointer movement. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## 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 starred 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 0a341f0 + b51848b commit 292db5e

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

hooks/useGlowEffect.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { renderHook } from '@testing-library/react';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { useGlowEffect } from './useGlowEffect';
4+
5+
class MockResizeObserver {
6+
observe = vi.fn();
7+
unobserve = vi.fn();
8+
disconnect = vi.fn();
9+
}
10+
11+
describe('useGlowEffect', () => {
12+
beforeEach(() => {
13+
vi.stubGlobal('ResizeObserver', MockResizeObserver);
14+
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {
15+
callback(0);
16+
return 1;
17+
});
18+
vi.spyOn(window, 'cancelAnimationFrame').mockImplementation(() => {});
19+
});
20+
21+
afterEach(() => {
22+
vi.restoreAllMocks();
23+
vi.unstubAllGlobals();
24+
});
25+
26+
it('returns the public API for the glow effect', () => {
27+
const { result } = renderHook(() => useGlowEffect());
28+
29+
expect(result.current.shellRef).toBeDefined();
30+
expect(result.current.shellVars).toBeDefined();
31+
expect(result.current.handleMouseEnter).toEqual(expect.any(Function));
32+
expect(result.current.handleMouseMove).toEqual(expect.any(Function));
33+
expect(result.current.handleMouseLeave).toEqual(expect.any(Function));
34+
});
35+
36+
it('returns CSS variable keys in shellVars', () => {
37+
const { result } = renderHook(() => useGlowEffect());
38+
39+
expect(result.current.shellVars).toHaveProperty('--mx');
40+
expect(result.current.shellVars).toHaveProperty('--my');
41+
expect(result.current.shellVars).toHaveProperty('--glow-opacity');
42+
expect(result.current.shellVars).toHaveProperty('--border-opacity');
43+
});
44+
45+
it('defaults glow opacity to 0', () => {
46+
const { result } = renderHook(() => useGlowEffect());
47+
48+
expect(result.current.shellVars['--glow-opacity']).toBe('0');
49+
});
50+
51+
it('cancels animation frame on unmount after pointer movement', () => {
52+
const cancelAnimationFrameSpy = vi.spyOn(window, 'cancelAnimationFrame');
53+
54+
const { result, unmount } = renderHook(() => useGlowEffect());
55+
56+
result.current.handleMouseMove({
57+
clientX: 100,
58+
clientY: 50,
59+
currentTarget: document.createElement('div'),
60+
} as unknown as React.MouseEvent<HTMLDivElement>);
61+
62+
unmount();
63+
64+
expect(cancelAnimationFrameSpy).toHaveBeenCalled();
65+
});
66+
});

0 commit comments

Comments
 (0)