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 <noreply@anthropic.com>
This commit is contained in:
harshitsinghbhandari 2026-04-04 22:01:09 +05:30
parent f9abcdf32f
commit 4e60238d5d
1 changed files with 59 additions and 0 deletions

View File

@ -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(
<OrchestratorSelector
{...defaultProps}
orchestrators={orchestratorsWithInvalidDate}
/>,
);
// 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(
<OrchestratorSelector
{...defaultProps}
orchestrators={orchestratorsWithFutureDate}
/>,
);
// 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(
<OrchestratorSelector
{...defaultProps}
orchestrators={orchestratorsWithNullDate}
/>,
);
expect(screen.getByText(/Created Unknown/)).toBeInTheDocument();
});
});
});