Skip to content

Commit

Permalink
fix: date parsing (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
levinkerschberger authored Nov 6, 2024
1 parent 0a237e9 commit 75a3a2b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ export const ConnectionsTableColumns: ColumnDef<Connection>[] = [
return <SortableTableColumn column={column} title="JVM Start Time" />;
},
cell: ({ row }) => {
const date = new Date(parseInt(row.getValue("startTime")) * 1000);
return (
<div className="px-4 align-middle font-medium">
{date.toLocaleString()}
{row.getValue("startTime")}
</div>
);
},
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/types/Connection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { z } from "zod";

export const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;

export const ConnectionSchema = z.object({
id: z.string().uuid(),
registrationTime: z.string(),
serviceName: z.string(),
gepardVersion: z.string(),
otelVersion: z.string(),
pid: z.number().int(),
startTime: z.number().int(),
startTime: z
.string()
.regex(iso8601Regex, "Invalid ISO 8601 UTC timestamp format"),
javaVersion: z.string(),
attributes: z.record(z.string()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ describe("ConnectionsView", () => {
{ timeout: 1000 }
);
});

it("renders JVM Start Time Correctly", () => {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;

render(<ConnectionsView connections={mockConnections} />);
const elements = screen.getAllByText(iso8601Regex);
expect(screen.getByText("JVM Start Time")).toBeInTheDocument();
expect(elements).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useConnectionsQuery } from "@/hooks/features/connections/useConnections
import { server } from "../../../vitest.setup";
import { http, HttpResponse } from "msw";

describe("group", () => {
describe("useConnections", () => {
it("should return data, if network call was successful", async () => {
const { result } = renderHook(() => useConnectionsQuery(), {
wrapper: createWrapper(),
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/mocks-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const generateMockConnection = (serviceName: string): Connection => ({
gepardVersion: "1.0.0",
otelVersion: "1.0.0",
pid: 12345,
startTime: Date.now(),
startTime: new Date().toISOString(),
javaVersion: "17.0.1",
attributes: {
environment: "test",
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/pages/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ describe("ErrorPage", () => {

const result = render(<ErrorPage />);

expect(result.getByText(/error of unknown type occured/i));
expect(result.getByText(/error of unknown type/i));
});
});

0 comments on commit 75a3a2b

Please sign in to comment.