-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c1599d
commit b500ae6
Showing
10 changed files
with
1,822 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Imports | ||
import { describe, it, expect } from "vitest"; | ||
import ConnectionsPage from "../ConnectionsPage"; | ||
import { createQueryClient, renderWithClient } from "@/tests/utils"; | ||
import { beforeEach } from "node:test"; | ||
|
||
// Tests | ||
describe("Renders main page correctly", () => { | ||
const queryClient = createQueryClient({ | ||
defaultOptions: { queries: { retry: false } }, | ||
}); | ||
beforeEach(() => { | ||
queryClient.clear(); | ||
}); | ||
|
||
it("Successfully fetched data", async () => { | ||
const result = renderWithClient(queryClient, <ConnectionsPage />); | ||
|
||
expect(await result.findByText(/Connections/i)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Connection } from "@/types/Connection"; | ||
import { http, HttpResponse } from "msw"; | ||
import { generateMockConnection } from "./mocks-data"; | ||
|
||
export const handlers = [ | ||
http.get<never, never, Connection[]>( | ||
"http://localhost:8080/api/v1/connections", | ||
() => { | ||
const connections = [generateMockConnection(), generateMockConnection()]; | ||
return HttpResponse.json(connections); | ||
} | ||
), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Connection } from "@/types/Connection"; | ||
|
||
export const generateMockConnection = (): Connection => ({ | ||
id: "123e4567-e89b-12d3-a456-426614174000", | ||
registrationTime: new Date().toISOString(), | ||
serviceName: "test-service", | ||
gepardVersion: "1.0.0", | ||
otelVersion: "1.0.0", | ||
pid: 12345, | ||
startTime: Date.now(), | ||
javaVersion: "17.0.1", | ||
attributes: { | ||
environment: "test", | ||
region: "us-east-1", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
QueryClient, | ||
QueryClientConfig, | ||
QueryClientProvider, | ||
} from "@tanstack/react-query"; | ||
import { render } from "@testing-library/react"; | ||
|
||
export function renderWithClient(client: QueryClient, ui: React.ReactElement) { | ||
const { rerender, ...result } = render( | ||
<QueryClientProvider client={client}>{ui}</QueryClientProvider> | ||
); | ||
return { | ||
...result, | ||
rerender: (rerenderUi: React.ReactElement) => { | ||
rerender( | ||
<QueryClientProvider client={client}>{rerenderUi}</QueryClientProvider> | ||
); | ||
}, | ||
}; | ||
} | ||
|
||
export function createQueryClient(config?: QueryClientConfig): QueryClient { | ||
return new QueryClient(config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { setupServer } from "msw/node"; | ||
import { afterAll, afterEach, beforeAll, vi } from "vitest"; | ||
import { handlers } from "./handlers"; | ||
|
||
export const server = setupServer(...handlers); | ||
|
||
beforeAll(() => { | ||
server.listen(); | ||
}); | ||
|
||
afterEach(() => { | ||
server.resetHandlers(); | ||
}); | ||
|
||
afterAll(() => { | ||
server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters