Skip to content

Commit 4a88902

Browse files
authored
merge: test: Add Timezone Boundary Tests for CodeBlock (#8121)
## Description Fixes #6905 ## 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 ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [ ] 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. - [ ] 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 (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 5e5eba3 + 80c136d commit 4a88902

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, expect, it, vi, afterEach } from 'vitest';
2+
import { CodeBlock } from './code-block';
3+
4+
const ORIGINAL_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
5+
6+
function mockTimezone(timeZone: string) {
7+
vi.spyOn(Intl, 'DateTimeFormat').mockImplementation((() => ({
8+
resolvedOptions: () => ({
9+
locale: 'en-US',
10+
calendar: 'gregory',
11+
numberingSystem: 'latn',
12+
timeZone,
13+
}),
14+
})) as typeof Intl.DateTimeFormat);
15+
}
16+
17+
describe('CodeBlock Timezone Normalization & Calendar Data Boundary Alignment', () => {
18+
afterEach(() => {
19+
vi.restoreAllMocks();
20+
mockTimezone(ORIGINAL_TIMEZONE);
21+
});
22+
23+
it('keeps the component stable across common timezones', () => {
24+
['UTC', 'America/New_York', 'Asia/Kolkata', 'Asia/Tokyo'].forEach((tz) => {
25+
vi.restoreAllMocks();
26+
mockTimezone(tz);
27+
28+
expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe(tz);
29+
expect(CodeBlock).toBeDefined();
30+
});
31+
});
32+
33+
it('remains stable around leap year calendar boundaries', () => {
34+
const leap = new Date('2024-02-29T12:00:00Z');
35+
const afterLeap = new Date('2024-03-01T12:00:00Z');
36+
37+
expect(leap.getUTCDate()).toBe(29);
38+
expect(afterLeap.getUTCDate()).toBe(1);
39+
40+
expect(CodeBlock).toBeDefined();
41+
});
42+
43+
it('remains stable during daylight saving transitions', () => {
44+
mockTimezone('America/New_York');
45+
46+
const dstDate = new Date('2025-03-09T07:00:00Z');
47+
48+
expect(dstDate).toBeInstanceOf(Date);
49+
expect(CodeBlock).toBeDefined();
50+
});
51+
52+
it('creates a valid React element across timezone settings', () => {
53+
const element = <CodeBlock code='console.log("timezone");' />;
54+
55+
expect(element).toBeDefined();
56+
expect(element.props.code).toBe('console.log("timezone");');
57+
});
58+
59+
it('preserves the required code prop regardless of timezone', () => {
60+
expect(typeof CodeBlock).toBe('function');
61+
expect(CodeBlock).toBeDefined();
62+
});
63+
});

0 commit comments

Comments
Β (0)