Skip to content

Commit cf54a75

Browse files
authored
test(refresh-policy): add responsive breakpoints test suite (JhaSourav07#2939) (JhaSourav07#3051)
2 parents b5e879c + a80a419 commit cf54a75

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { beforeEach, describe, expect, it } from 'vitest';
2+
import { RefreshPolicy } from './refresh-policy';
3+
4+
describe('RefreshPolicy - Responsive Breakpoints Layout Cohesion', () => {
5+
beforeEach(() => {
6+
window.innerWidth = 375;
7+
window.dispatchEvent(new Event('resize'));
8+
});
9+
10+
it('maintains expected cooldown constraints under simulated mobile viewport dimensions', () => {
11+
const policy = RefreshPolicy.getInstance();
12+
policy.reset();
13+
14+
expect(window.innerWidth).toBe(375);
15+
16+
const allowed = policy.isRefreshAllowed('mobile-user');
17+
expect(allowed).toBe(true);
18+
19+
policy.recordRefresh('mobile-user');
20+
expect(policy.isRefreshAllowed('mobile-user')).toBe(false);
21+
});
22+
23+
it('verifies that resizing viewport does not disrupt existing active cooldown timers', () => {
24+
const policy = RefreshPolicy.getInstance();
25+
policy.reset();
26+
policy.recordRefresh('resizable-user');
27+
28+
// Verify it is blocked on mobile
29+
expect(policy.isRefreshAllowed('resizable-user')).toBe(false);
30+
31+
// Resize viewport to desktop breakpoint
32+
window.innerWidth = 1440;
33+
window.dispatchEvent(new Event('resize'));
34+
35+
// Cooldown state must be preserved
36+
expect(window.innerWidth).toBe(1440);
37+
expect(policy.isRefreshAllowed('resizable-user')).toBe(false);
38+
});
39+
40+
it('ensures duration limits are independent of window/responsive viewport heights', () => {
41+
const policy = RefreshPolicy.getInstance();
42+
policy.reset();
43+
policy.setCooldown(5000);
44+
45+
window.innerHeight = 812;
46+
window.dispatchEvent(new Event('resize'));
47+
48+
expect(policy.getRemainingCooldown('user-a')).toBe(0);
49+
});
50+
});

0 commit comments

Comments
 (0)