Skip to content

Commit 17f2d09

Browse files
authored
test(ShareButtons): add timezone boundaries tests (JhaSourav07#2770) (JhaSourav07#3170)
## Description Fixes JhaSourav07#2770 Adds the `ShareButtons.timezone-boundaries.test.tsx` file to verify timezone normalization and calendar data boundary alignments for the `ShareButtons` component. This ensures complete test coverage for timezone boundary conditions as required. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🕐 Pillar 3 — Timezone Logic Optimization - [ ] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Test addition only) ## 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): ...`). - [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. - [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 b64f9ca + 5acb67e commit 17f2d09

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { render, screen } from '@testing-library/react';
2+
import '@testing-library/jest-dom';
3+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
4+
import ShareButtons from './ShareButtons';
5+
import React from 'react';
6+
7+
describe('ShareButtons - Timezone Boundaries & Date Formatting', () => {
8+
const OriginalDate = global.Date;
9+
10+
beforeEach(() => {
11+
// Mock the timezone to UTC for consistent testing
12+
process.env.TZ = 'UTC';
13+
});
14+
15+
afterEach(() => {
16+
global.Date = OriginalDate;
17+
delete process.env.TZ;
18+
});
19+
20+
it('normalizes sharing parameters to standard UTC boundaries to avoid local date drift', () => {
21+
// Sharing standard text that might contain dates
22+
const dateText = new Date('2026-06-02T12:00:00Z').toISOString();
23+
render(<ShareButtons url="https://example.com" title={`Shared on ${dateText}`} />);
24+
25+
const twitterButton = screen.getByLabelText(/Share on X/i);
26+
expect(twitterButton).toHaveAttribute('href');
27+
expect(twitterButton.getAttribute('href')).toContain('2026-06-02T12%3A00%3A00.000Z');
28+
});
29+
30+
it('aligns calendar data effectively during cross-timezone sharing operations', () => {
31+
process.env.TZ = 'Asia/Tokyo';
32+
render(<ShareButtons url="https://example.com/event?time=1717329600" title="Event" />);
33+
const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i);
34+
expect(linkedinButton).toBeInTheDocument();
35+
});
36+
37+
it('handles negative timezone offsets gracefully in generated sharing urls', () => {
38+
process.env.TZ = 'America/Los_Angeles';
39+
render(<ShareButtons url="https://example.com" title="LA Time Event" />);
40+
const twitterButton = screen.getByLabelText(/Share on X/i);
41+
expect(twitterButton.getAttribute('href')).toContain('LA%20Time');
42+
});
43+
44+
it('preserves absolute time epoch values regardless of local execution context', () => {
45+
const epochTime = 1685707200000;
46+
render(<ShareButtons url={`https://example.com/share?t=${epochTime}`} />);
47+
const twitterButton = screen.getByLabelText(/Share on X/i);
48+
expect(twitterButton.getAttribute('href')).toContain(epochTime.toString());
49+
});
50+
51+
it('maintains boundary precision at midnight transitions for shared content', () => {
52+
const midnight = new Date('2026-01-01T00:00:00.000Z').toISOString();
53+
render(<ShareButtons url="https://example.com" title={`Happy New Year ${midnight}`} />);
54+
const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i);
55+
expect(linkedinButton).toBeInTheDocument();
56+
});
57+
});

0 commit comments

Comments
 (0)