From 4e60238d5d87f8eb749b751c0a3c34b9b2ee365c Mon Sep 17 00:00:00 2001 From: harshitsinghbhandari <24b4506@iitb.ac.in> Date: Sat, 4 Apr 2026 22:01:09 +0530 Subject: [PATCH] test: add edge case tests for formatRelativeTime Add tests to verify proper handling of: - Invalid date strings (returns "Unknown") - Future timestamps (returns "Just now") - Null dates (returns "Unknown") Co-Authored-By: Claude Opus 4.5 --- .../__tests__/OrchestratorSelector.test.tsx | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/packages/web/src/components/__tests__/OrchestratorSelector.test.tsx b/packages/web/src/components/__tests__/OrchestratorSelector.test.tsx index acae6d378..bd29d7128 100644 --- a/packages/web/src/components/__tests__/OrchestratorSelector.test.tsx +++ b/packages/web/src/components/__tests__/OrchestratorSelector.test.tsx @@ -148,4 +148,63 @@ describe("OrchestratorSelector", () => { expect(screen.getByText("Active")).toBeInTheDocument(); expect(screen.getByText("spawning")).toBeInTheDocument(); }); + + describe("formatRelativeTime edge cases", () => { + it("shows Unknown for invalid date strings", () => { + const orchestratorsWithInvalidDate = [ + { + ...mockOrchestrators[0], + createdAt: "not-a-valid-date", + lastActivityAt: null, + }, + ]; + render( + , + ); + + // The "Created Unknown" text should appear for invalid dates + expect(screen.getByText(/Created Unknown/)).toBeInTheDocument(); + }); + + it("shows Just now for future timestamps", () => { + const futureDate = new Date(Date.now() + 60000).toISOString(); // 1 minute in future + const orchestratorsWithFutureDate = [ + { + ...mockOrchestrators[0], + createdAt: futureDate, + lastActivityAt: null, + }, + ]; + render( + , + ); + + // Future timestamps should show "Just now" instead of negative values + expect(screen.getByText(/Created Just now/)).toBeInTheDocument(); + }); + + it("shows Unknown for null dates", () => { + const orchestratorsWithNullDate = [ + { + ...mockOrchestrators[0], + createdAt: null, + lastActivityAt: null, + }, + ]; + render( + , + ); + + expect(screen.getByText(/Created Unknown/)).toBeInTheDocument(); + }); + }); });