mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-07 20:23:05 +08:00
fix: test activity graph bugs (fehmer) (#5468)
This commit is contained in:
parent
eac0f7c6af
commit
01076986be
4 changed files with 77 additions and 18 deletions
backend
frontend
|
@ -254,11 +254,11 @@ describe("user controller test", () => {
|
|||
expect(testActivity?.lastDay).toEqual(1712102400000);
|
||||
|
||||
const testsByDays = testActivity?.testsByDays ?? [];
|
||||
expect(testsByDays).toHaveLength(366);
|
||||
expect(testsByDays[0]).toEqual(undefined); //2023-04-04
|
||||
expect(testsByDays[271]).toEqual(undefined); //2023-12-31
|
||||
expect(testsByDays[272]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[365]).toEqual(2024094); //2024-01
|
||||
expect(testsByDays).toHaveLength(372);
|
||||
expect(testsByDays[6]).toEqual(undefined); //2023-04-04
|
||||
expect(testsByDays[277]).toEqual(undefined); //2023-12-31
|
||||
expect(testsByDays[278]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[371]).toEqual(2024094); //2024-01
|
||||
});
|
||||
it("with current and last year", () => {
|
||||
//given
|
||||
|
@ -274,11 +274,11 @@ describe("user controller test", () => {
|
|||
expect(testActivity?.lastDay).toEqual(1712102400000);
|
||||
|
||||
const testsByDays = testActivity?.testsByDays ?? [];
|
||||
expect(testsByDays).toHaveLength(366);
|
||||
expect(testsByDays[0]).toEqual(2023094); //2023-04-04
|
||||
expect(testsByDays[271]).toEqual(2023365); //2023-12-31
|
||||
expect(testsByDays[272]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[365]).toEqual(2024094); //2024-01
|
||||
expect(testsByDays).toHaveLength(372);
|
||||
expect(testsByDays[6]).toEqual(2023094); //2023-04-04
|
||||
expect(testsByDays[277]).toEqual(2023365); //2023-12-31
|
||||
expect(testsByDays[278]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[371]).toEqual(2024094); //2024-01
|
||||
});
|
||||
it("with current and missing days of last year", () => {
|
||||
//given
|
||||
|
@ -294,11 +294,11 @@ describe("user controller test", () => {
|
|||
expect(testActivity?.lastDay).toEqual(1712102400000);
|
||||
|
||||
const testsByDays = testActivity?.testsByDays ?? [];
|
||||
expect(testsByDays).toHaveLength(366);
|
||||
expect(testsByDays[0]).toEqual(undefined); //2023-04-04
|
||||
expect(testsByDays[271]).toEqual(undefined); //2023-12-31
|
||||
expect(testsByDays[272]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[365]).toEqual(2024094); //2024-01
|
||||
expect(testsByDays).toHaveLength(372);
|
||||
expect(testsByDays[6]).toEqual(undefined); //2023-04-04
|
||||
expect(testsByDays[277]).toEqual(undefined); //2023-12-31
|
||||
expect(testsByDays[278]).toEqual(2024001); //2024-01-01
|
||||
expect(testsByDays[371]).toEqual(2024094); //2024-01
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1020,8 +1020,8 @@ export function getCurrentTestActivity(
|
|||
)
|
||||
);
|
||||
}
|
||||
//use enough days of the last year to have 366 days in total
|
||||
lastYearData = lastYearData.slice(-366 + thisYearData.length);
|
||||
//use enough days of the last year to have 372 days in total to always fill the first week of the graph
|
||||
lastYearData = lastYearData.slice(-372 + thisYearData.length);
|
||||
|
||||
const lastDay = Dates.startOfDay(
|
||||
Dates.addDays(thisYear, thisYearData.length - 1)
|
||||
|
|
|
@ -300,6 +300,62 @@ describe("test-activity-calendar.ts", () => {
|
|||
},
|
||||
]);
|
||||
});
|
||||
it("for first day in june", () => {
|
||||
//set today
|
||||
vi.setSystemTime(getDate("2024-06-01"));
|
||||
const calendar = new TestActivityCalendar([], getDate("2024-06-01"));
|
||||
|
||||
expect(calendar.getMonths()).toEqual([
|
||||
{
|
||||
text: "jun",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "jul",
|
||||
weeks: 5,
|
||||
},
|
||||
{
|
||||
text: "aug",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "sep",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "oct",
|
||||
weeks: 5,
|
||||
},
|
||||
{
|
||||
text: "nov",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "dec",
|
||||
weeks: 5,
|
||||
},
|
||||
{
|
||||
text: "jan",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "feb",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "mar",
|
||||
weeks: 5,
|
||||
},
|
||||
{
|
||||
text: "apr",
|
||||
weeks: 4,
|
||||
},
|
||||
{
|
||||
text: "may",
|
||||
weeks: 4,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDays", () => {
|
||||
|
|
|
@ -78,7 +78,10 @@ export class TestActivityCalendar implements MonkeyTypes.TestActivityCalendar {
|
|||
const month: Date = months[i] as Date;
|
||||
let start =
|
||||
i === 0 ? new UTCDateMini(this.startDay) : startOfMonth(month);
|
||||
let end = i === 12 ? new UTCDateMini(this.endDay) : endOfMonth(start);
|
||||
let end =
|
||||
i === months.length - 1
|
||||
? new UTCDateMini(this.endDay)
|
||||
: endOfMonth(start);
|
||||
|
||||
if (!isSunday(start))
|
||||
start = (i === 0 ? previousSunday : nextSunday)(start);
|
||||
|
|
Loading…
Reference in a new issue