Skip to content

Commit 5f024be

Browse files
committed
test(heureka): add tests for new components
1 parent 29ccff0 commit 5f024be

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Juno contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from "react"
7+
import { render, screen } from "@testing-library/react"
8+
import { ErrorMessage } from "./ErrorMessage"
9+
10+
describe("ErrorMessage", () => {
11+
it("renders error message with name and message", () => {
12+
const error = new Error("Something went wrong")
13+
error.name = "TestError"
14+
render(<ErrorMessage error={error} />)
15+
const errorText = screen.getByText("TestError: Something went wrong")
16+
expect(errorText).toBeInTheDocument()
17+
})
18+
19+
it("renders error message with default name", () => {
20+
const error = new Error("Something went wrong")
21+
error.name = ""
22+
render(<ErrorMessage error={error} />)
23+
const errorText = screen.getByText("Error: Something went wrong")
24+
expect(errorText).toBeInTheDocument()
25+
})
26+
27+
it("renders default message when error message is empty", () => {
28+
const error = new Error("")
29+
error.name = "TestError"
30+
render(<ErrorMessage error={error} />)
31+
const errorText = screen.getByText("TestError: Something went wrong")
32+
expect(errorText).toBeInTheDocument()
33+
})
34+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Juno contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from "react"
7+
import { render, screen } from "@testing-library/react"
8+
import { LoadingDataRow } from "./LoadingDataRow"
9+
10+
describe("LoadingDataRow", () => {
11+
it("should correctly render", () => {
12+
render(<LoadingDataRow colSpan={5} />)
13+
const loadingText = screen.getByText("Loading")
14+
const spinner = screen.getByRole("progressbar")
15+
expect(loadingText).toBeInTheDocument()
16+
expect(spinner).toBeInTheDocument()
17+
})
18+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Juno contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from "react"
7+
import { render, screen } from "@testing-library/react"
8+
import { getErrorDataRowComponent } from "./getErrorDataRow"
9+
10+
describe("getErrorDataRowComponent", () => {
11+
it("should render error message when ErrorDataRow component is used", () => {
12+
const ErrorDataRow = getErrorDataRowComponent({ colspan: 5 })
13+
const testError = new Error("Test error message")
14+
render(<ErrorDataRow error={testError} />)
15+
const errorText = screen.getByText(/Test error message/)
16+
expect(errorText).toBeInTheDocument()
17+
})
18+
19+
it("should render with correct colSpan prop", () => {
20+
const ErrorDataRow = getErrorDataRowComponent({ colspan: 7 })
21+
const testError = new Error("Test error")
22+
const { container } = render(<ErrorDataRow error={testError} />)
23+
const cell = container.querySelector('[style*="grid-column: span 7"]')
24+
expect(cell).toBeInTheDocument()
25+
})
26+
})

0 commit comments

Comments
 (0)