-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added unit tests for components
Signed-off-by: Darshan Simha <[email protected]>
- Loading branch information
Darshan Simha
committed
Nov 2, 2023
1 parent
23cc375
commit 9a886d2
Showing
6 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
ui/src/components/common/DebouncedSearchInput/index.test.tsx
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,40 @@ | ||
import React from "react"; | ||
import { | ||
act, | ||
fireEvent, | ||
render, | ||
screen, | ||
waitFor, | ||
} from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { DebouncedSearchInput } from "./index"; | ||
|
||
describe("DebouncedSearchInput", () => { | ||
it("renders", async () => { | ||
const mockOnChange = jest.fn(); | ||
render(<DebouncedSearchInput onChange={mockOnChange} />); | ||
await waitFor(() => { | ||
expect(screen.getByTestId("debounced-search-input")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("calls onChange when input changes", async () => { | ||
const mockOnChange = jest.fn(); | ||
render(<DebouncedSearchInput onChange={mockOnChange} />); | ||
await waitFor(() => { | ||
expect(screen.getByTestId("debounced-search-input")).toBeInTheDocument(); | ||
}); | ||
const field = screen | ||
.getByTestId("debounced-search-input") | ||
.querySelector("input"); | ||
expect(field).toBeInTheDocument(); | ||
|
||
await act(async () => { | ||
fireEvent.change(field, { | ||
target: { value: "test" }, | ||
}); | ||
}); | ||
expect(field?.value).toBe("test"); | ||
}); | ||
}); |
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,15 @@ | ||
import React from "react"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { ErrorDisplay } from "./index"; | ||
|
||
describe("ErrorDisplay", () => { | ||
it("renders", async () => { | ||
render(<ErrorDisplay title={"test"} message={"test error"} />); | ||
await waitFor(() => { | ||
expect(screen.getByText("test")).toBeInTheDocument(); | ||
expect(screen.getByText("test error")).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
...c/components/common/SlidingSidebar/partials/VertexDetails/partials/Buffers/index.test.tsx
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,60 @@ | ||
import React from "react"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { Buffers } from "./index"; | ||
|
||
const mockBuffers = [ | ||
{ | ||
partition: 1000, | ||
isFull: false, | ||
ackPending: false, | ||
pending: false, | ||
bufferLength: 1001, | ||
bufferUsage: 1002, | ||
totalPendingMessages: 1003, | ||
}, | ||
{ | ||
partition: 1004, | ||
isFull: false, | ||
ackPending: false, | ||
pending: false, | ||
bufferLength: 1005, | ||
bufferUsage: 1006, | ||
totalPendingMessages: 1007, | ||
}, | ||
{ | ||
partition: 1008, | ||
isFull: true, | ||
ackPending: false, | ||
pending: false, | ||
bufferLength: 1009, | ||
bufferUsage: 1010, | ||
totalPendingMessages: 1011, | ||
}, | ||
]; | ||
|
||
describe("Buffers", () => { | ||
it("renders with empty buffers", async () => { | ||
render(<Buffers buffers={[]} />); | ||
await waitFor(() => { | ||
expect(screen.getByText("Partition")).toBeInTheDocument(); | ||
expect(screen.getByText("isFull")).toBeInTheDocument(); | ||
expect(screen.getByText("AckPending")).toBeInTheDocument(); | ||
expect( | ||
screen.getByText("No buffer information found") | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("renders with buffers", async () => { | ||
render(<Buffers buffers={mockBuffers} />); | ||
await waitFor(() => { | ||
expect(screen.getByText("1001")).toBeInTheDocument(); | ||
expect(screen.getByText("100200.00%")).toBeInTheDocument(); | ||
expect(screen.getByText("1005")).toBeInTheDocument(); | ||
expect(screen.getByText("100600.00%")).toBeInTheDocument(); | ||
expect(screen.getAllByText("no").length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
}); |
86 changes: 86 additions & 0 deletions
86
...ents/common/SlidingSidebar/partials/VertexDetails/partials/ProcessingRates/index.test.tsx
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,86 @@ | ||
import React from "react"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { ProcessingRates } from "./index"; | ||
|
||
const mockPipelineId = "simple-pipeline"; | ||
const mockVertexId = "in"; | ||
const mockVertexMetrics = { | ||
cat: [ | ||
{ | ||
pipeline: "simple-pipeline", | ||
vertex: "cat", | ||
processingRates: { | ||
"15m": 0, | ||
"1m": 0, | ||
"5m": 0, | ||
default: 0, | ||
}, | ||
}, | ||
], | ||
in: [ | ||
{ | ||
pipeline: "simple-pipeline", | ||
vertex: "in", | ||
processingRates: { | ||
"15m": 10, | ||
"1m": 20, | ||
"5m": 30, | ||
default: 0, | ||
}, | ||
}, | ||
], | ||
out: [ | ||
{ | ||
pipeline: "simple-pipeline", | ||
vertex: "out", | ||
processingRates: { | ||
"15m": 0, | ||
"1m": 0, | ||
"5m": 0, | ||
default: 0, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
describe("ProcessingRates", () => { | ||
it("renders with empty processing rates", async () => { | ||
render( | ||
<ProcessingRates vertexId={""} pipelineId={""} vertexMetrics={[]} /> | ||
); | ||
await waitFor(() => { | ||
expect(screen.getByText("Partition")).toBeInTheDocument(); | ||
expect(screen.getByText("No metrics found")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("renders with processing rates", async () => { | ||
render( | ||
<ProcessingRates | ||
vertexId={mockVertexId} | ||
pipelineId={mockPipelineId} | ||
vertexMetrics={mockVertexMetrics} | ||
/> | ||
); | ||
await waitFor(() => { | ||
expect(screen.getByText("Partition")).toBeInTheDocument(); | ||
expect(screen.getByText("20.00")).toBeInTheDocument(); | ||
expect(screen.getByText("30.00")).toBeInTheDocument(); | ||
expect(screen.getByText("10.00")).toBeInTheDocument(); | ||
}); | ||
}); | ||
it("Renders when vertexData is null", async () => { | ||
render( | ||
<ProcessingRates | ||
vertexId={"zzz"} | ||
pipelineId={mockPipelineId} | ||
vertexMetrics={mockVertexMetrics} | ||
/> | ||
); | ||
await waitFor(() => { | ||
expect(screen.getByText("No metrics found")).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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