-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for useCertificateDeleteDialog hook
- Loading branch information
1 parent
d085c3d
commit b198bf3
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/dialogs/certificate-delete-dialog/useCertificateDeleteDialog.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,57 @@ | ||
import { describe, it, renderHook, act, expect } from "@testing"; | ||
import { vi } from "vitest"; | ||
import { useCertificateDeleteDialog } from "./useCertificateDeleteDialog"; | ||
|
||
import type { FortifyAPI } from "@peculiar/fortify-client-core"; | ||
|
||
vi.mock("@peculiar/react-components", async () => { | ||
const actual = await vi.importActual("@peculiar/react-components"); | ||
return { | ||
...actual, | ||
useToast: () => ({ | ||
addToast: vi.fn(), | ||
}), | ||
}; | ||
}); | ||
|
||
describe("useCertificateDeleteDialog", () => { | ||
it("Should initialize", async () => { | ||
const mockFortifyClient: Partial<FortifyAPI> = { | ||
removeCertificateById: vi.fn().mockResolvedValue({}), | ||
}; | ||
const handleSuccess = vi.fn(); | ||
const { result } = renderHook(() => | ||
useCertificateDeleteDialog({ | ||
onSuccess: handleSuccess, | ||
fortifyClient: mockFortifyClient as FortifyAPI, | ||
}) | ||
); | ||
|
||
expect(result.current.dialog).toBeInstanceOf(Function); | ||
expect(result.current.open).toBeInstanceOf(Function); | ||
|
||
const certificateIndex = "1"; | ||
const providerId = "2"; | ||
|
||
act(() => { | ||
result.current.open({ | ||
certificateIndex, | ||
providerId, | ||
label: "Message", | ||
}); | ||
}); | ||
|
||
await act(async () => { | ||
const DialogComponent = result.current.dialog(); | ||
|
||
DialogComponent && | ||
(await DialogComponent.props.onDeleteClick(certificateIndex)); | ||
}); | ||
|
||
expect(handleSuccess).toHaveBeenCalledWith(providerId); | ||
expect(mockFortifyClient.removeCertificateById).toHaveBeenCalledWith( | ||
providerId, | ||
certificateIndex | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export { describe, it, expect, vi, afterEach } from "vitest"; | ||
export { render, screen, cleanup, fireEvent } from "@testing-library/react"; | ||
export { | ||
render, | ||
screen, | ||
cleanup, | ||
fireEvent, | ||
renderHook, | ||
act, | ||
waitFor, | ||
} from "@testing-library/react"; | ||
export { userEvent } from "@testing-library/user-event"; |