Skip to content

Commit 56710ad

Browse files
authored
test(ShareSheet-timezone-boundaries): add timezone normalization and calendar boundary alignment coverage (JhaSourav07#3618)
## Description Fixes JhaSourav07#2620 - `components/dashboard/ShareSheet.timezone-boundaries.test.tsx` — added `5` timezone boundary tests: asserting profile URL stability at `UTC` midnight, verifying correct rendering under `IST (+05:30)` non-integer offset, confirming no rendering gaps when activity data spans a leap year `Feb 29`, validating clean rendering across the US DST spring-forward transition (Mar 10 2024), and asserting username and URL alignment at `JST (+09:00)` midnight boundary. ## Pillar - 🛠️ Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - I have read the `CONTRIBUTING.md` file. - I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - I have run `npm run format` and `npm run lint` locally and resolved all errors. - My commits follow the Conventional Commits format. - I have starred the repo. - I have made sure that i have only one commit to merge in this PR.
2 parents 459abce + b26be1f commit 56710ad

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2+
import { render, screen } from '@testing-library/react';
3+
import ShareSheet from './ShareSheet';
4+
import type { DashboardExportData } from '@/types/dashboard';
5+
6+
vi.mock('framer-motion', () => ({
7+
motion: {
8+
div: ({ children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
9+
<div {...props}>{children}</div>
10+
),
11+
},
12+
AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}</>,
13+
}));
14+
15+
vi.mock('react-qr-code', () => ({
16+
default: ({ value }: { value: string }) => <svg data-testid="qr-code" data-value={value} />,
17+
}));
18+
19+
vi.mock('@/hooks/useShareActions', () => ({
20+
useShareActions: () => ({
21+
states: {},
22+
handleTwitter: vi.fn(),
23+
handleLinkedIn: vi.fn(),
24+
handleReddit: vi.fn(),
25+
handleDownloadPNG: vi.fn(),
26+
handleDownloadWEBP: vi.fn(),
27+
handleDownloadSVG: vi.fn(),
28+
handleCopyMarkdown: vi.fn(),
29+
handleDownloadJSON: vi.fn(),
30+
handleNativeShare: vi.fn(),
31+
}),
32+
}));
33+
34+
function makeMockExportData(overrides?: Partial<DashboardExportData>): DashboardExportData {
35+
return {
36+
stats: { currentStreak: 5, peakStreak: 10, totalContributions: 100 },
37+
languages: [],
38+
activity: [],
39+
...overrides,
40+
};
41+
}
42+
43+
const defaultProps = {
44+
username: 'octocat',
45+
isOpen: true,
46+
onClose: vi.fn(),
47+
exportData: makeMockExportData(),
48+
};
49+
50+
describe('ShareSheet - Timezone Normalization & Calendar Data Boundary Alignment', () => {
51+
beforeEach(() => {
52+
vi.clearAllMocks();
53+
});
54+
55+
afterEach(() => {
56+
vi.useRealTimers();
57+
});
58+
59+
it('UTC boundary: profile URL is constructed correctly when system clock is at UTC midnight boundary', () => {
60+
vi.useFakeTimers();
61+
vi.setSystemTime(new Date('2024-03-15T00:00:00.000Z'));
62+
63+
render(<ShareSheet {...defaultProps} />);
64+
65+
const input = screen.getByDisplayValue(/commitpulse\.vercel\.app\/dashboard\/octocat/i);
66+
expect(input).toBeTruthy();
67+
expect((input as HTMLInputElement).value).toBe(
68+
'https://commitpulse.vercel.app/dashboard/octocat'
69+
);
70+
});
71+
72+
it('IST offset (+05:30): component renders correctly when system is in IST timezone offset', () => {
73+
vi.useFakeTimers();
74+
vi.setSystemTime(new Date('2024-06-15T18:30:00.000Z'));
75+
76+
render(<ShareSheet {...defaultProps} />);
77+
78+
expect(screen.getByText('octocat')).toBeTruthy();
79+
const input = screen.getByDisplayValue(/commitpulse\.vercel\.app\/dashboard\/octocat/i);
80+
expect((input as HTMLInputElement).value).toContain('octocat');
81+
});
82+
83+
it('Leap year boundary: component renders without gaps when exportData spans Feb 29 of a leap year', () => {
84+
const leapYearActivity = [
85+
{ date: '2024-02-28', count: 3, intensity: 2 as const },
86+
{ date: '2024-02-29', count: 7, intensity: 3 as const },
87+
{ date: '2024-03-01', count: 2, intensity: 1 as const },
88+
];
89+
90+
render(
91+
<ShareSheet
92+
{...defaultProps}
93+
exportData={makeMockExportData({ activity: leapYearActivity })}
94+
/>
95+
);
96+
97+
expect(screen.getByText('octocat')).toBeTruthy();
98+
expect(screen.getByDisplayValue(/commitpulse\.vercel\.app\/dashboard\/octocat/i)).toBeTruthy();
99+
});
100+
101+
it('DST transition boundary: component renders correctly around US DST spring-forward date (Mar 10 2024)', () => {
102+
vi.useFakeTimers();
103+
vi.setSystemTime(new Date('2024-03-10T07:00:00.000Z'));
104+
105+
const dstActivity = [
106+
{ date: '2024-03-09', count: 5, intensity: 3 as const },
107+
{ date: '2024-03-10', count: 4, intensity: 2 as const },
108+
{ date: '2024-03-11', count: 6, intensity: 3 as const },
109+
];
110+
111+
render(
112+
<ShareSheet {...defaultProps} exportData={makeMockExportData({ activity: dstActivity })} />
113+
);
114+
115+
expect(screen.getByText('octocat')).toBeTruthy();
116+
const input = screen.getByDisplayValue(/commitpulse\.vercel\.app\/dashboard\/octocat/i);
117+
expect(input).toBeTruthy();
118+
});
119+
120+
it('JST offset (+09:00): profile URL and username render stably when clock is at JST day boundary', () => {
121+
vi.useFakeTimers();
122+
vi.setSystemTime(new Date('2024-08-20T15:00:00.000Z'));
123+
124+
render(<ShareSheet {...defaultProps} username="jst-user" />);
125+
126+
expect(screen.getByText('jst-user')).toBeTruthy();
127+
const input = screen.getByDisplayValue(/commitpulse\.vercel\.app\/dashboard\/jst-user/i);
128+
expect((input as HTMLInputElement).value).toBe(
129+
'https://commitpulse.vercel.app/dashboard/jst-user'
130+
);
131+
});
132+
});

0 commit comments

Comments
 (0)