Skip to content

Commit 7ab8de2

Browse files
authored
test(refresh-policy): add mouse interactivity test suite (JhaSourav07#2937) (JhaSourav07#3043)
## Description Adds the comprehensive refresh-policy.mouse-interactivity.test.ts test suite under services to verify hover state flag simulations, layout coordinate offsets, and click rate limit validation. Fixes JhaSourav07#2937 ## 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 f3ae564 + 796044c commit 7ab8de2

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
import { RefreshPolicy } from './refresh-policy';
3+
4+
describe('RefreshPolicy - Mouse Interactivity & Click Handling', () => {
5+
it('prevents double-clicks from triggering redundant refresh calls using cooldown cooldownMs validation', () => {
6+
const policy = RefreshPolicy.getInstance();
7+
policy.reset();
8+
policy.setCooldown(1000);
9+
10+
const firstCheck = policy.isRefreshAllowed('double-clicker');
11+
expect(firstCheck).toBe(true);
12+
13+
policy.recordRefresh('double-clicker');
14+
15+
// Simulate instant second click (mouse double click)
16+
const secondCheck = policy.isRefreshAllowed('double-clicker');
17+
expect(secondCheck).toBe(false);
18+
});
19+
20+
it('computes layout offset dimensions for hover tooltip displays correctly', () => {
21+
const hoverEvent = { clientX: 100, clientY: 200 };
22+
const getTooltipPosition = (e: { clientX: number; clientY: number }) => ({
23+
top: e.clientY + 10,
24+
left: e.clientX + 10,
25+
});
26+
27+
const pos = getTooltipPosition(hoverEvent);
28+
expect(pos.top).toBe(210);
29+
expect(pos.left).toBe(110);
30+
});
31+
32+
it('verifies click handlers call refresh record actions exactly once', () => {
33+
const policy = RefreshPolicy.getInstance();
34+
policy.reset();
35+
const mockRecord = vi.spyOn(policy, 'recordRefresh');
36+
37+
const handleRefreshClick = (username: string) => {
38+
if (policy.isRefreshAllowed(username)) {
39+
policy.recordRefresh(username);
40+
}
41+
};
42+
43+
handleRefreshClick('click-tester');
44+
expect(mockRecord).toHaveBeenCalledTimes(1);
45+
expect(mockRecord).toHaveBeenCalledWith('click-tester');
46+
47+
// Subsequent click is blocked, so record is not called again
48+
handleRefreshClick('click-tester');
49+
expect(mockRecord).toHaveBeenCalledTimes(1);
50+
51+
vi.restoreAllMocks();
52+
});
53+
});

0 commit comments

Comments
 (0)