Skip to content

Commit

Permalink
chore: [IOBP-1040] Update the latest receipt list everytime the user …
Browse files Browse the repository at this point in the history
…closes the success outcome (#6485)

## Short description
This PR introduces a feature to fetch the latest user receipts whenever
the user closes the thank-you page after a successful payment.
Previously, the fetch action was triggered only when the user initiated
a payment from the "Payment" section, and not when starting a payment
from the "Messages" section.

## List of changes proposed in this pull request
- Moved the dispatch action to fetch the latest receipts (transactions)
outside the condition.
- Added a test to check that when received success outcome and the user
press on the "Close" button, it dispatches the fetch of latest
transactions.

## How to test
- Tests should pass without any error.

---------

Co-authored-by: Emanuele Dall'Ara <[email protected]>
  • Loading branch information
Hantex9 and LeleDallas authored Dec 3, 2024
1 parent 5a5493f commit 446cabc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ const WalletPaymentOutcomeScreen = () => {
};

const handleClose = () => {
dispatch(getPaymentsLatestBizEventsTransactionsAction.request());
if (
onSuccessAction === "showHome" ||
onSuccessAction === "showTransaction"
) {
dispatch(getPaymentsLatestBizEventsTransactionsAction.request());
// Currently we do support only navigation to the wallet
// TODO navigate to the transaction details if payment outcome is success
navigation.popToTop();
Expand All @@ -153,7 +153,8 @@ const WalletPaymentOutcomeScreen = () => {
const closeSuccessAction: OperationResultScreenContentProps["action"] = {
label: I18n.t("wallet.payment.outcome.SUCCESS.button"),
accessibilityLabel: I18n.t("wallet.payment.outcome.SUCCESS.button"),
onPress: handleClose
onPress: handleClose,
testID: "wallet-payment-outcome-success-button"
};

const closeFailureAction: OperationResultScreenContentProps["action"] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fireEvent } from "@testing-library/react-native";
import { default as configureMockStore } from "redux-mock-store";
import { applicationChangeState } from "../../../../../store/actions/application";
import { appReducer } from "../../../../../store/reducers";
Expand All @@ -6,6 +7,8 @@ import { renderScreenWithNavigationStoreContext } from "../../../../../utils/tes
import { PaymentsCheckoutRoutes } from "../../navigation/routes";
import { WalletPaymentOutcomeScreen } from "../WalletPaymentOutcomeScreen";
import { WalletPaymentOutcomeEnum } from "../../types/PaymentOutcomeEnum";
import { getPaymentsLatestBizEventsTransactionsAction } from "../../../bizEventsTransaction/store/actions";
import * as useIO from "../../../../../store/hooks";

const renderComponent = (outcome: WalletPaymentOutcomeEnum) => {
const globalState = appReducer(undefined, applicationChangeState("active"));
Expand All @@ -23,11 +26,22 @@ const renderComponent = (outcome: WalletPaymentOutcomeEnum) => {
store
);
};

describe("WalletPaymentOutcomeScreen for all outcomes", () => {
Object.values(WalletPaymentOutcomeEnum).forEach(outcome => {
it(`should render the WalletPaymentOutcomeScreen for outcome: ${outcome}`, () => {
const renderedComponent = renderComponent(outcome);
expect(renderedComponent.toJSON()).toMatchSnapshot();
});
});
it(`should fetch the latest transaction when closing the thank you page after a success outcome`, () => {
const mockedDispatch = jest.fn();
jest.spyOn(useIO, "useIODispatch").mockImplementation(() => mockedDispatch);

const { getByTestId } = renderComponent(WalletPaymentOutcomeEnum.SUCCESS);
fireEvent.press(getByTestId("wallet-payment-outcome-success-button"));
expect(mockedDispatch).toHaveBeenCalledWith(
getPaymentsLatestBizEventsTransactionsAction.request()
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ exports[`WalletPaymentOutcomeScreen for all outcomes should render the WalletPay
"alignSelf": "flex-start",
}
}
testID="wallet-payment-outcome-success-button"
>
<View
style={
Expand Down

0 comments on commit 446cabc

Please sign in to comment.