Skip to content

Commit 2c83906

Browse files
Merge branch 'main' into feat/shareable-customize-url
2 parents fc9a820 + 018763e commit 2c83906

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

app/page.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,26 @@ describe('LandingPage', () => {
274274
});
275275
});
276276

277+
it('does not show copied state when clipboard write fails', async () => {
278+
vi.mocked(navigator.clipboard.writeText).mockRejectedValueOnce(new Error('Permission denied'));
279+
280+
render(<LandingPage />);
281+
const input = screen.getByPlaceholderText('Enter GitHub Username') as HTMLInputElement;
282+
fireEvent.change(input, { target: { value: 'jhasourav07' } });
283+
284+
const copyButton = screen.getByText('Copy Link').closest('button');
285+
fireEvent.click(copyButton!);
286+
287+
await waitFor(() => {
288+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
289+
expect.stringContaining('/api/streak?user=jhasourav07')
290+
);
291+
});
292+
293+
expect(screen.queryByText('Copied')).toBeNull();
294+
expect(screen.queryByText('Your Monolith is Ready - Deploy It in 4 Steps')).toBeNull();
295+
});
296+
277297
it('disables Copy Link button when username is empty', () => {
278298
render(<LandingPage />);
279299

app/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,18 @@ export default function LandingPage() {
104104
badgeResult?.username === debouncedUsername && badgeResult?.status === 'loaded';
105105
const badgeError = badgeResult?.username === debouncedUsername && badgeResult?.status === 'error';
106106

107-
const copyToClipboard = () => {
107+
const copyToClipboard = async () => {
108108
if (trimmedUsername.length === 0) return;
109109

110+
try {
111+
await navigator.clipboard.writeText(markdown);
112+
} catch {
113+
setCopied(false);
114+
return;
115+
}
116+
110117
trackUser(trimmedUsername);
111118
addSearch(trimmedUsername);
112-
113-
navigator.clipboard.writeText(markdown);
114119
setCopied(true);
115120
setTimeout(() => {
116121
guideRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });

lib/calculate.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,20 @@ describe('calculateStreak — empty and sparse year edge cases', () => {
13521352
expect(result.todayDate).toBeDefined();
13531353
});
13541354

1355+
it('returns all zeros for an entire year (52 weeks × 7 days) of empty contributions (Variation 5)', () => {
1356+
// 52 weeks × 7 days = 364 days, every day has 0 commits.
1357+
const emptyYearCounts = Array(364).fill(0);
1358+
const calendar = buildCalendar(emptyYearCounts);
1359+
1360+
const fixedNow = new Date('2024-01-15T12:00:00Z');
1361+
const result = calculateStreak(calendar, 'UTC', fixedNow);
1362+
1363+
expect(result.currentStreak).toBe(0);
1364+
expect(result.longestStreak).toBe(0);
1365+
expect(result.totalContributions).toBe(0);
1366+
expect(result.todayDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
1367+
});
1368+
13551369
it('is deterministic: same empty calendar always returns identical output', () => {
13561370
const calendar = buildCalendar([]);
13571371
const fixedNow = new Date('2024-01-15T12:00:00Z');

lib/github.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,12 @@ export async function getOrgDashboardData(orgName: string, options: FetchOptions
749749

750750
const members = membersOrError;
751751

752+
// Limit active members to first 60 to protect shared token rate limit
753+
const activeMembers = members.slice(0, 60);
754+
752755
// Fetch calendars for all members concurrently with capped concurrency to avoid 429s/timeouts
753756
const calendars = (
754-
await runCappedConcurrency(members, 5, (member) =>
757+
await runCappedConcurrency(activeMembers, 5, (member) =>
755758
fetchGitHubContributions(member, options)
756759
.then((data) => data.calendar)
757760
.catch(() => null)

0 commit comments

Comments
 (0)