-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFalsePositiveModal.test.tsx
More file actions
59 lines (52 loc) · 2.04 KB
/
FalsePositiveModal.test.tsx
File metadata and controls
59 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Juno contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from "react"
import { render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { PortalProvider } from "@cloudoperators/juno-ui-components"
import { AuthProvider } from "@cloudoperators/greenhouse-auth-provider"
import { FalsePositiveModal } from "./index"
const mockAuth = { getSnapshot: () => ({ status: "anonymous" as const }) }
const defaultProps = {
open: true,
onClose: () => {},
onConfirm: () => Promise.resolve(),
vulnerability: "CVE-2024-1234",
service: "my-service",
image: "my-image",
}
const renderModal = (props = {}) => {
return render(
<AuthProvider embedded auth={mockAuth}>
<PortalProvider>
<FalsePositiveModal {...defaultProps} {...props} />
</PortalProvider>
</AuthProvider>
)
}
describe("FalsePositiveModal", () => {
it("renders with title and vulnerability details when open", () => {
renderModal()
expect(screen.getByRole("heading", { name: "Mark as False Positive" })).toBeInTheDocument()
expect(screen.getByText(/Vulnerability:/)).toBeInTheDocument()
expect(screen.getByText("CVE-2024-1234")).toBeInTheDocument()
expect(screen.getByText(/Service:/)).toBeInTheDocument()
expect(screen.getByText("my-service")).toBeInTheDocument()
expect(screen.getByText(/Image:/)).toBeInTheDocument()
expect(screen.getByText("my-image")).toBeInTheDocument()
})
it("renders Cancel and Mark as False Positive buttons", () => {
renderModal()
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument()
expect(screen.getByRole("button", { name: "Mark as False Positive" })).toBeInTheDocument()
})
it("calls onClose when Cancel is clicked", async () => {
const onClose = vi.fn()
const user = userEvent.setup()
renderModal({ onClose })
await user.click(screen.getByRole("button", { name: "Cancel" }))
expect(onClose).toHaveBeenCalledTimes(1)
})
})