2021-07-07 10:09:47 +00:00
|
|
|
import { fireEvent, screen, render } from "@testing-library/react";
|
2020-09-25 13:17:55 +00:00
|
|
|
import React from "react";
|
2021-07-07 10:09:47 +00:00
|
|
|
import { useConfirmDialog } from "./ConfirmDialog";
|
2020-09-25 13:17:55 +00:00
|
|
|
|
2021-07-07 10:09:47 +00:00
|
|
|
describe("ConfirmDialog", () => {
|
|
|
|
it("renders a simple confirm dialog", () => {
|
2020-09-25 13:17:55 +00:00
|
|
|
const onConfirm = jest.fn();
|
|
|
|
const Test = () => {
|
|
|
|
const [toggle, ConfirmDialog] = useConfirmDialog({
|
|
|
|
titleKey: "Delete app02?",
|
|
|
|
messageKey:
|
|
|
|
"If you delete this client, all associated data will be removed.",
|
|
|
|
continueButtonLabel: "Delete",
|
|
|
|
onConfirm: onConfirm,
|
|
|
|
});
|
2021-07-07 10:09:47 +00:00
|
|
|
|
2020-09-25 13:17:55 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-07-07 10:09:47 +00:00
|
|
|
<button data-testid="show" onClick={toggle}>
|
2020-09-25 13:17:55 +00:00
|
|
|
Show
|
|
|
|
</button>
|
|
|
|
<ConfirmDialog />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-07-07 10:09:47 +00:00
|
|
|
render(<Test />);
|
|
|
|
fireEvent.click(screen.getByTestId("show"));
|
2020-09-25 13:17:55 +00:00
|
|
|
|
2021-07-07 10:09:47 +00:00
|
|
|
const confirmButton = screen.getByTestId("modalConfirm");
|
|
|
|
expect(confirmButton).toBeInTheDocument();
|
2020-09-25 13:17:55 +00:00
|
|
|
|
2021-07-07 10:09:47 +00:00
|
|
|
fireEvent.click(confirmButton);
|
2020-09-25 13:17:55 +00:00
|
|
|
expect(onConfirm).toBeCalled();
|
|
|
|
});
|
|
|
|
});
|