Skip to content

Commit

Permalink
#238 Fix voucher execution alert (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevendyulgerov authored Sep 9, 2024
1 parent ea1a4c0 commit 0f7eed5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/components/inputs/voucherExecution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ const VoucherExecution: FC<VoucherExecutionType> = (props) => {
}, [wait.isSuccess]);

useEffect(() => {
if (prepare.isError) {
if (hasVoucherProof && prepare.isError) {
notifications.show({
message: prepare.error.message,
message: `Voucher error: ${prepare.error.message}`,
color: "red",
withBorder: true,
withCloseButton: true,
Expand All @@ -101,7 +101,7 @@ const VoucherExecution: FC<VoucherExecutionType> = (props) => {
},
});
}
}, [prepare.error, prepare.isError]);
}, [hasVoucherProof, prepare.error, prepare.isError]);

return (
<div>
Expand Down
31 changes: 30 additions & 1 deletion apps/web/test/components/inputs/voucherExecution.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe("VoucherExecution component", () => {

expect(showMock).toHaveBeenCalledWith(
expect.objectContaining({
message: prepareData.error.message,
message: `Voucher error: ${prepareData.error.message}`,
color: "red",
withBorder: true,
withCloseButton: true,
Expand All @@ -366,6 +366,35 @@ describe("VoucherExecution component", () => {
);
});

it("should not display prepare error when proof is pending", async () => {
const mantineNotifications = await import("@mantine/notifications");
const showMock = vi.fn();
mantineNotifications.notifications = {
...mantineNotifications.notifications,
show: showMock,
} as any;

const prepareData = {
data: false,
isError: true,
error: {
message: "Some error message",
},
};

useSimulateCartesiDAppExecuteVoucherMock.mockReturnValue(
prepareData as any,
);
render(
<Component
{...defaultProps}
voucher={{ ...defaultProps.voucher, proof: null }}
/>,
);

expect(showMock).toHaveBeenCalledTimes(0);
});

it("should not execute voucher when preparation has failed and execute button is clicked", () => {
useReadCartesiDAppWasVoucherExecutedMock.mockReturnValue({
data: false,
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/InputDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const Details: FC<InputDetailsProps> = (props) => {
<Tabs
defaultValue={selected}
orientation={isSmallDevice ? "horizontal" : "vertical"}
keepMounted={false}
>
<InputDetailsTabs />
<InputDetailsContent />
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/test/InputDetails/InputDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe("Rollups InputDetails", () => {
</InputDetailsE>,
);

fireEvent.click(screen.getByText("Reports"));
fireEvent.click(screen.getByText("As JSON"));
fireEvent.click(screen.getByText("As Text"));
fireEvent.click(screen.getByText("Raw"));
Expand All @@ -105,6 +106,7 @@ describe("Rollups InputDetails", () => {
</InputDetailsE>,
);

fireEvent.click(screen.getByText("Vouchers"));
fireEvent.click(screen.getByText("As JSON"));
fireEvent.click(screen.getByText("As Text"));
fireEvent.click(screen.getByText("Raw"));
Expand All @@ -126,6 +128,7 @@ describe("Rollups InputDetails", () => {
</InputDetailsE>,
);

fireEvent.click(screen.getByText("Notices"));
fireEvent.click(screen.getByText("As JSON"));
fireEvent.click(screen.getByText("As Text"));
fireEvent.click(screen.getByText("Raw"));
Expand Down

0 comments on commit 0f7eed5

Please sign in to comment.