Refactor Study Desk application structure
This commit is contained in:
parent
faaccf8a7e
commit
089439ed90
145 changed files with 8087 additions and 3412 deletions
32
src/services/activityService.test.ts
Normal file
32
src/services/activityService.test.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { summarizeActivityBuckets, summarizeActivityRows } from "./activityService";
|
||||
|
||||
describe("summarizeActivityRows", () => {
|
||||
it("keeps a 53-week display while preserving a longer current streak", () => {
|
||||
const now = new Date("2026-08-07T18:00:00.000Z");
|
||||
const activities = Array.from({ length: 400 }, (_, age) =>
|
||||
Array.from({ length: 20 }, () => ({
|
||||
type: "FLASHCARD",
|
||||
occurredAt: new Date(now.getTime() - age * 24 * 60 * 60 * 1000),
|
||||
}))
|
||||
).flat();
|
||||
const summary = summarizeActivityRows(activities, now);
|
||||
expect(summary.days).toHaveLength(371);
|
||||
expect(summary.currentStreak).toBe(400);
|
||||
expect(summary.days.filter((day) => day.date <= summary.today).at(-1)?.date).toBe(summary.today);
|
||||
});
|
||||
|
||||
it("preserves counts and long streaks from database-aggregated daily buckets", () => {
|
||||
const now = new Date("2026-08-07T18:00:00.000Z");
|
||||
const buckets = Array.from({ length: 400 }, (_, age) => ({
|
||||
date: new Date(now.getTime() - 7 * 60 * 60 * 1000 - age * 86_400_000)
|
||||
.toISOString()
|
||||
.slice(0, 10),
|
||||
type: "FLASHCARD",
|
||||
count: 20,
|
||||
}));
|
||||
const summary = summarizeActivityBuckets(buckets, now);
|
||||
expect(summary.currentStreak).toBe(400);
|
||||
expect(summary.days).toHaveLength(371);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue