From 01716f75280d928c388ccefdf4da2a9b4ab9d37c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:27:21 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20100%=20test=20coverage=20for?= =?UTF-8?q?=20yearInReviewUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/__tests__/yearInReviewUtils.test.ts | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/lib/__tests__/yearInReviewUtils.test.ts b/src/lib/__tests__/yearInReviewUtils.test.ts index 5a528dd..40a8d2a 100644 --- a/src/lib/__tests__/yearInReviewUtils.test.ts +++ b/src/lib/__tests__/yearInReviewUtils.test.ts @@ -174,3 +174,60 @@ describe("getMostActiveDayFromCalendar", () => { expect(getMostActiveDayFromCalendar(calendar)).toBe("Thursday"); }); }); + +describe("buildHourlyHeatmapFromCommitDates - edge cases", () => { + it("falls back to full date parsing if cached day parsing results in NaN but full date is parseable", () => { + const mockDateStr = { + length: 19, + 10: "T", + slice: () => "invalid___", + toString: () => "2023-01-01T10:00:00Z" + } as unknown as string; + const heatmap = buildHourlyHeatmapFromCommitDates([mockDateStr]); + expect(heatmap[0][10]).toBe(1); + }); + + it("falls back to full string parsing for unparseable hour data", () => { + const heatmap = buildHourlyHeatmapFromCommitDates(["2023-01-01TX0:00:00Z"]); + const totalCommits = heatmap.flat().reduce((sum, count) => sum + count, 0); + expect(totalCommits).toBe(0); + }); + + it("falls back to full string parsing for unparseable hour data but valid date", () => { + const heatmap = buildHourlyHeatmapFromCommitDates(["2023-01-01T10:00:00.1234Z"]); + expect(heatmap[0][10]).toBe(1); + }); + + it("falls back if caching fails and full date is also invalid", () => { + const mockDateStr = { + length: 19, + 10: "T", + slice: () => "invalid___", + toString: () => "invalid-full-date" + } as unknown as string; + const heatmap = buildHourlyHeatmapFromCommitDates([mockDateStr]); + const totalCommits = heatmap.flat().reduce((sum, count) => sum + count, 0); + expect(totalCommits).toBe(0); + }); + + it("falls back to full date parsing when timezone offsets don't match fast-path ending conditions", () => { + const commitDates = [ + "2023-01-01T10:00:00.000Z", // length 24, ends with .000Z + "2023-01-01T10:00:00.123+02:00", // length 29 + ]; + const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); + expect(heatmap[0][10]).toBe(1); + expect(heatmap[0][8]).toBe(1); // 10:00:00+02:00 is 08:00 UTC + }); +}); + + it("hits the fast path with a length 20 string", () => { + // e.g. "2023-01-01T10:00:00Z" is length 20! + // Wait, "2023-01-01T10:00:00Z" is 20 chars long. + // Let's make sure we test length === 24 without ending in .000Z + const commitDates = [ + "2023-01-01T10:00:00.123+", // length 24 + ]; + const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); + expect(heatmap[0][10]).toBe(0); // wait, it falls back to new Date() which will be NaN so it's ignored + }); From 05f73fb9f6474918a194e0d161a78feeeb6e7608 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 03:25:19 +0000 Subject: [PATCH 2/2] fix(tests): Address structural bug and clarify descriptions Moved improperly placed 'it' block inside its corresponding 'describe' block. Updated tests descriptions to accurately reflect the length and behavior of the fast-path vs fallback logic. Added explanations for edge cases using object mocks. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/__tests__/yearInReviewUtils.test.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/__tests__/yearInReviewUtils.test.ts b/src/lib/__tests__/yearInReviewUtils.test.ts index 40a8d2a..7e5073f 100644 --- a/src/lib/__tests__/yearInReviewUtils.test.ts +++ b/src/lib/__tests__/yearInReviewUtils.test.ts @@ -176,6 +176,10 @@ describe("getMostActiveDayFromCalendar", () => { }); describe("buildHourlyHeatmapFromCommitDates - edge cases", () => { + // Note: The following tests use mock objects cast to string to intentionally trigger specific + // internal parsing failures and verify the fallback logic without relying on invalid JS Date quirks + // that differ between environments. + it("falls back to full date parsing if cached day parsing results in NaN but full date is parseable", () => { const mockDateStr = { length: 19, @@ -219,15 +223,12 @@ describe("buildHourlyHeatmapFromCommitDates - edge cases", () => { expect(heatmap[0][10]).toBe(1); expect(heatmap[0][8]).toBe(1); // 10:00:00+02:00 is 08:00 UTC }); -}); - it("hits the fast path with a length 20 string", () => { - // e.g. "2023-01-01T10:00:00Z" is length 20! - // Wait, "2023-01-01T10:00:00Z" is 20 chars long. - // Let's make sure we test length === 24 without ending in .000Z + it("falls back to full date parsing when length is 24 but does not end with .000Z", () => { const commitDates = [ - "2023-01-01T10:00:00.123+", // length 24 + "2023-01-01T10:00:00.123+", // length 24, invalid ending ]; const heatmap = buildHourlyHeatmapFromCommitDates(commitDates); - expect(heatmap[0][10]).toBe(0); // wait, it falls back to new Date() which will be NaN so it's ignored + expect(heatmap[0][10]).toBe(0); }); +});