import { describe, it, expect } from "vitest"; import { groupByDate } from "../data/groupByDate"; import type { ConversationSummary } from "../data/types"; function makeConversation(id: string, daysAgo: number): ConversationSummary { const date = new Date(); date.setDate(date.getDate() - daysAgo); date.setHours(10, 0, 0, 0); return { id, title: `Conversation ${id}`, createdAt: date.toISOString(), preview: "Preview text", }; } describe("groupByDate", () => { it("groups conversations into Today", () => { const conversations = [makeConversation("1", 0), makeConversation("2", 0)]; const result = groupByDate(conversations); expect(result).toHaveLength(1); expect(result[0].label).toBe("Today"); expect(result[0].conversations).toHaveLength(2); }); it("groups conversations into Yesterday", () => { const conversations = [makeConversation("1", 1)]; const result = groupByDate(conversations); expect(result).toHaveLength(1); expect(result[0].label).toBe("Yesterday"); expect(result[0].conversations).toHaveLength(1); }); it("groups conversations into Last 7 days", () => { const conversations = [makeConversation("1", 3), makeConversation("2", 5)]; const result = groupByDate(conversations); expect(result).toHaveLength(1); expect(result[0].label).toBe("Last 7 days"); expect(result[0].conversations).toHaveLength(2); }); it("groups conversations into Last 30 days", () => { const conversations = [ makeConversation("1", 10), makeConversation("2", 20), ]; const result = groupByDate(conversations); expect(result).toHaveLength(1); expect(result[0].label).toBe("Last 30 days"); expect(result[0].conversations).toHaveLength(2); }); it("groups conversations into Older", () => { const conversations = [makeConversation("1", 45)]; const result = groupByDate(conversations); expect(result).toHaveLength(1); expect(result[0].label).toBe("Older"); }); it("filters out empty groups", () => { const conversations = [makeConversation("1", 0), makeConversation("2", 1)]; const result = groupByDate(conversations); expect(result).toHaveLength(2); expect(result[0].label).toBe("Today"); expect(result[1].label).toBe("Yesterday"); }); it("maintains group order regardless of input order", () => { const conversations = [makeConversation("2", 1), makeConversation("1", 0)]; const result = groupByDate(conversations); expect(result[0].label).toBe("Today"); expect(result[1].label).toBe("Yesterday"); }); it("returns empty array for no conversations", () => { const result = groupByDate([]); expect(result).toHaveLength(0); }); it("groups all date ranges together", () => { const conversations = [ makeConversation("today", 0), makeConversation("yesterday", 1), makeConversation("week", 3), makeConversation("month", 15), makeConversation("older", 50), ]; const result = groupByDate(conversations); expect(result).toHaveLength(5); expect(result.map((g) => g.label)).toEqual([ "Today", "Yesterday", "Last 7 days", "Last 30 days", "Older", ]); }); });