-
Notifications
You must be signed in to change notification settings - Fork 2.7k
CodeRabbit Generated Unit Tests: Add unit tests for PR changes #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,17 @@ | |
| EnvironmentProject, | ||
| EnvironmentThreadShell, | ||
| } from "@t3tools/client-runtime/state/shell"; | ||
| import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts"; | ||
| import { | ||
| CommandId, | ||
| EnvironmentId, | ||
| MessageId, | ||
| ProjectId, | ||
| ProviderInstanceId, | ||
| ThreadId, | ||
| } from "@t3tools/contracts"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import type { PendingNewTask } from "../../state/use-pending-new-tasks"; | ||
| import { buildHomeThreadGroups } from "./homeThreadList"; | ||
|
|
||
| function makeProject( | ||
|
|
@@ -44,6 +52,33 @@ | |
| }; | ||
| } | ||
|
|
||
| function makePendingTask( | ||
| input: Pick<EnvironmentProject, "environmentId" | "id" | "title" | "workspaceRoot">, | ||
| ): PendingNewTask { | ||
| return { | ||
| title: input.title, | ||
| message: { | ||
| environmentId: input.environmentId, | ||
| threadId: ThreadId.make(`pending-thread-${input.id}`), | ||
| messageId: MessageId.make(`pending-message-${input.id}`), | ||
| commandId: CommandId.make(`pending-command-${input.id}`), | ||
| text: input.title, | ||
| attachments: [], | ||
| createdAt: "2026-06-29T00:00:00.000Z", | ||
| }, | ||
| creation: { | ||
| projectId: input.id, | ||
| projectTitle: input.title, | ||
| projectCwd: input.workspaceRoot, | ||
| workspaceMode: "local", | ||
| branch: null, | ||
| worktreePath: null, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| const NOW = Date.parse("2026-06-29T00:00:00.000Z"); | ||
|
|
||
| function buildGroups( | ||
| projects: ReadonlyArray<EnvironmentProject>, | ||
| threads: ReadonlyArray<EnvironmentThreadShell>, | ||
|
|
@@ -57,6 +92,7 @@ | |
| projectSortOrder: "updated_at", | ||
| threadSortOrder: "updated_at", | ||
| projectGroupingMode: "repository", | ||
| now: NOW, | ||
| ...overrides, | ||
| }); | ||
| } | ||
|
|
@@ -220,4 +256,141 @@ | |
| ); | ||
| expect(buildGroups(projects, threads, { projectGroupingMode: "separate" })).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("default view shows only threads from the last 5 days", () => { | ||
| const environmentId = EnvironmentId.make("environment-1"); | ||
| const project = makeProject({ | ||
| environmentId, | ||
| id: ProjectId.make("project-1"), | ||
| title: "T3 Code", | ||
| }); | ||
| const threads = [ | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make("recent-1"), | ||
| projectId: project.id, | ||
| title: "Today", | ||
| updatedAt: "2026-06-28T00:00:00.000Z", | ||
| }), | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make("recent-2"), | ||
| projectId: project.id, | ||
| title: "Within window", | ||
| updatedAt: "2026-06-25T00:00:00.000Z", | ||
| }), | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make("old"), | ||
| projectId: project.id, | ||
| title: "Two weeks ago", | ||
| updatedAt: "2026-06-14T00:00:00.000Z", | ||
| }), | ||
| ]; | ||
|
|
||
| const group = buildGroups([project], threads)[0]; | ||
| // Default view trims to recent threads... | ||
| expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2"]); | ||
|
Check failure on line 293 in apps/mobile/src/features/home/homeThreadList.test.ts
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests map undefined recentThreadsHigh Severity The new Reviewed by Cursor Bugbot for commit b987aae. Configure here. |
||
| // ...while full history stays available for the expanded view. | ||
| expect(group?.threads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2", "old"]); | ||
| }); | ||
|
|
||
| it("falls back to the most recent 3 threads when none are within 5 days", () => { | ||
| const environmentId = EnvironmentId.make("environment-1"); | ||
| const project = makeProject({ | ||
| environmentId, | ||
| id: ProjectId.make("project-1"), | ||
| title: "T3 Code", | ||
| }); | ||
| const threads = ["2026-06-01", "2026-06-02", "2026-06-03", "2026-06-04", "2026-06-05"].map( | ||
| (day, index) => | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make(`thread-${index}`), | ||
| projectId: project.id, | ||
| title: `Thread ${index}`, | ||
| updatedAt: `${day}T00:00:00.000Z`, | ||
| }), | ||
| ); | ||
|
|
||
| const group = buildGroups([project], threads)[0]; | ||
| expect(group?.recentThreads.map((thread) => thread.id)).toEqual([ | ||
|
Check failure on line 317 in apps/mobile/src/features/home/homeThreadList.test.ts
|
||
| "thread-4", | ||
| "thread-3", | ||
| "thread-2", | ||
| ]); | ||
| expect(group?.threads).toHaveLength(5); | ||
| }); | ||
|
|
||
| it("includes a thread exactly at the 5-day cutoff", () => { | ||
| const environmentId = EnvironmentId.make("environment-1"); | ||
| const project = makeProject({ | ||
| environmentId, | ||
| id: ProjectId.make("project-1"), | ||
| title: "T3 Code", | ||
| }); | ||
| const exactlyAtCutoff = new Date(NOW - 5 * 24 * 60 * 60 * 1000).toISOString(); | ||
| const justPastCutoff = new Date(NOW - 5 * 24 * 60 * 60 * 1000 - 1).toISOString(); | ||
| const threads = [ | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make("at-cutoff"), | ||
| projectId: project.id, | ||
| title: "At cutoff", | ||
| updatedAt: exactlyAtCutoff, | ||
| }), | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make("past-cutoff"), | ||
| projectId: project.id, | ||
| title: "Past cutoff", | ||
| updatedAt: justPastCutoff, | ||
| }), | ||
| ]; | ||
|
|
||
| const group = buildGroups([project], threads)[0]; | ||
| expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["at-cutoff"]); | ||
|
Check failure on line 352 in apps/mobile/src/features/home/homeThreadList.test.ts
|
||
| }); | ||
|
|
||
| it("returns an empty recentThreads list for a group with no threads", () => { | ||
| const environmentId = EnvironmentId.make("environment-1"); | ||
| const project = makeProject({ | ||
| environmentId, | ||
| id: ProjectId.make("project-1"), | ||
| title: "T3 Code", | ||
| }); | ||
|
|
||
| const group = buildGroups([project], [], { | ||
| pendingTasks: [makePendingTask(project)], | ||
| })[0]; | ||
|
|
||
| expect(group?.threads).toEqual([]); | ||
| expect(group?.recentThreads).toEqual([]); | ||
|
Check failure on line 368 in apps/mobile/src/features/home/homeThreadList.test.ts
|
||
| }); | ||
|
|
||
| it("does not apply the recency window while searching", () => { | ||
| const environmentId = EnvironmentId.make("environment-1"); | ||
| const project = makeProject({ | ||
| environmentId, | ||
| id: ProjectId.make("project-1"), | ||
| title: "T3 Code", | ||
| }); | ||
| const threads = ["2026-06-01", "2026-06-02", "2026-06-03", "2026-06-04", "2026-06-05"].map( | ||
| (day, index) => | ||
| makeThread({ | ||
| environmentId, | ||
| id: ThreadId.make(`thread-${index}`), | ||
| projectId: project.id, | ||
| title: `Thread ${index}`, | ||
| updatedAt: `${day}T00:00:00.000Z`, | ||
| }), | ||
| ); | ||
|
|
||
| const group = buildGroups([project], threads, { searchQuery: "T3 Code" })[0]; | ||
| // Search reaches the full history rather than the 3-thread fallback. | ||
| expect(group?.recentThreads).toHaveLength(5); | ||
| expect(group?.recentThreads.map((thread) => thread.id)).toEqual( | ||
| group?.threads.map((thread) => thread.id), | ||
| ); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import { relativeTime } from "./time"; | ||
|
|
||
| const NOW = Date.parse("2026-06-29T12:00:00.000Z"); | ||
|
|
||
| describe("relativeTime", () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(NOW); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it("returns '<1m' for unparseable input", () => { | ||
| expect(relativeTime("not-a-date")).toBe("<1m"); | ||
|
Check failure on line 18 in apps/mobile/src/lib/time.test.ts
|
||
| }); | ||
|
|
||
| it("returns '<1m' for a timestamp that is right now", () => { | ||
| expect(relativeTime(new Date(NOW).toISOString())).toBe("<1m"); | ||
|
Check failure on line 22 in apps/mobile/src/lib/time.test.ts
|
||
| }); | ||
|
|
||
| it("returns '<1m' for anything under a minute old, instead of a live seconds count", () => { | ||
| expect(relativeTime(new Date(NOW - 1_000).toISOString())).toBe("<1m"); | ||
|
Check failure on line 26 in apps/mobile/src/lib/time.test.ts
|
||
| expect(relativeTime(new Date(NOW - 59_000).toISOString())).toBe("<1m"); | ||
| }); | ||
|
|
||
| it("clamps timestamps in the future to '<1m' rather than a negative duration", () => { | ||
| expect(relativeTime(new Date(NOW + 60_000).toISOString())).toBe("<1m"); | ||
|
Check failure on line 31 in apps/mobile/src/lib/time.test.ts
|
||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. relativeTime tests expect wrong stringsMedium Severity The Reviewed by Cursor Bugbot for commit b987aae. Configure here. |
||
|
|
||
| it("renders whole minutes once a minute has elapsed", () => { | ||
| expect(relativeTime(new Date(NOW - 60_000).toISOString())).toBe("1m"); | ||
| expect(relativeTime(new Date(NOW - 90_000).toISOString())).toBe("1m"); | ||
| expect(relativeTime(new Date(NOW - 59 * 60_000).toISOString())).toBe("59m"); | ||
| }); | ||
|
|
||
| it("switches to hours once 60 minutes have elapsed", () => { | ||
| expect(relativeTime(new Date(NOW - 60 * 60_000).toISOString())).toBe("1h"); | ||
| expect(relativeTime(new Date(NOW - 23 * 60 * 60_000).toISOString())).toBe("23h"); | ||
| }); | ||
|
|
||
| it("switches to days once 24 hours have elapsed", () => { | ||
| expect(relativeTime(new Date(NOW - 24 * 60 * 60_000).toISOString())).toBe("1d"); | ||
| expect(relativeTime(new Date(NOW - 9 * 24 * 60 * 60_000).toISOString())).toBe("9d"); | ||
| }); | ||
| }); | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout tests ignore recentThreads
Medium Severity
New
buildHomeListLayoutcases assume a recency baseline fromrecentThreads(e.g. two visible threads and show-less back to two), butbuildHomeListLayoutonly slicesgroup.threadswithHOME_INITIAL_VISIBLE_THREADSandnextGroupDisplayStateshow-less still resets to six.Additional Locations (1)
apps/mobile/src/features/home/homeListItems.test.ts#L275-L288Reviewed by Cursor Bugbot for commit b987aae. Configure here.