Skip to content

Commit f0ec0c0

Browse files
authored
fix: test activity graph showing 54 weeks (@fehmer) (#5497)
1 parent 92193f1 commit f0ec0c0

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

frontend/__tests__/elements/test-activity-calendar.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ describe("test-activity-calendar.ts", () => {
7878
const calendar = new TestActivityCalendar([], getDate("2024-04-10"));
7979

8080
expect(calendar.getMonths()).toEqual([
81+
{
82+
text: "",
83+
weeks: 2,
84+
},
8185
{
8286
text: "may",
8387
weeks: 4,
@@ -356,6 +360,66 @@ describe("test-activity-calendar.ts", () => {
356360
},
357361
]);
358362
});
363+
it("no double month for for 16th june", () => {
364+
//set today
365+
vi.setSystemTime(getDate("2024-06-16"));
366+
const calendar = new TestActivityCalendar([], getDate("2024-06-01"));
367+
368+
expect(calendar.getMonths()).toEqual([
369+
{
370+
text: "",
371+
weeks: 2,
372+
},
373+
{
374+
text: "jul",
375+
weeks: 5,
376+
},
377+
{
378+
text: "aug",
379+
weeks: 4,
380+
},
381+
{
382+
text: "sep",
383+
weeks: 4,
384+
},
385+
{
386+
text: "oct",
387+
weeks: 5,
388+
},
389+
{
390+
text: "nov",
391+
weeks: 4,
392+
},
393+
{
394+
text: "dec",
395+
weeks: 5,
396+
},
397+
{
398+
text: "jan",
399+
weeks: 4,
400+
},
401+
{
402+
text: "feb",
403+
weeks: 4,
404+
},
405+
{
406+
text: "mar",
407+
weeks: 5,
408+
},
409+
{
410+
text: "apr",
411+
weeks: 4,
412+
},
413+
{
414+
text: "may",
415+
weeks: 4,
416+
},
417+
{
418+
text: "jun",
419+
weeks: 3,
420+
},
421+
]);
422+
});
359423
});
360424

361425
describe("getDays", () => {

frontend/src/ts/elements/test-activity-calendar.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { UTCDateMini } from "@date-fns/utc/date/mini";
33
import {
44
format,
55
endOfMonth,
6-
subYears,
76
addDays,
87
differenceInDays,
98
eachMonthOfInterval,
@@ -18,6 +17,7 @@ import {
1817
isSunday,
1918
nextSaturday,
2019
isSaturday,
20+
subWeeks,
2121
} from "date-fns";
2222

2323
export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
@@ -44,7 +44,8 @@ export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
4444
const end = fullYear ? endOfYear(lastDay) : new Date();
4545
let start = startOfYear(lastDay);
4646
if (!fullYear) {
47-
start = addDays(subYears(end, 1), 1);
47+
//show the last 52 weeks. Not using one year to avoid the graph to show 54 weeks
48+
start = addDays(subWeeks(end, 52), 1);
4849
if (!isSunday(start)) start = previousSunday(start);
4950
}
5051

@@ -88,11 +89,14 @@ export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
8889
if (!isSaturday(end)) end = nextSaturday(end);
8990

9091
const weeks = differenceInWeeks(end, start, { roundingMethod: "ceil" });
91-
if (weeks > 2)
92+
if (weeks > 2) {
9293
results.push({
9394
text: format(month, "MMM").toLowerCase(),
9495
weeks: weeks,
9596
});
97+
} else if (i == 0) {
98+
results.push({ text: "", weeks: weeks });
99+
}
96100
}
97101
return results;
98102
}

0 commit comments

Comments
 (0)