-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOBP-1122] Remove PSP preselection logic based on the onUs fi…
…eld (#6612) ## Short description This PR removes the logic to preselect a PSP if there is the `onUs` field; ## List of changes proposed in this pull request - Removed the `onUs` check to preselect the PSP when in the PSP list choosing screen; - Edited the featured label; - Added the onUs as first element in the sorting algorithm; - Added unit tests; ## How to test - Update the dev-server; - Run the dev-server and start a new payment; - After choosing a payment method, check that when the PSP list presents, there is any element preselected but there must be the featured text `Sei già cliente` https://github.com/user-attachments/assets/34c69c71-2287-4db5-bc27-fc816fe8de30
- Loading branch information
Showing
7 changed files
with
223 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
154 changes: 154 additions & 0 deletions
154
ts/features/payments/checkout/screens/__tests__/WalletPaymentPickPspScreen.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,154 @@ | ||
import { View } from "react-native"; | ||
import React from "react"; | ||
import { fireEvent } from "@testing-library/react-native"; | ||
import { createStore } from "redux"; | ||
import configureMockStore from "redux-mock-store"; | ||
import { appReducer } from "../../../../../store/reducers"; | ||
import { applicationChangeState } from "../../../../../store/actions/application"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { RptId } from "../../../../../../definitions/pagopa/ecommerce/RptId"; | ||
import { renderScreenWithNavigationStoreContext } from "../../../../../utils/testWrapper"; | ||
import { PaymentsCheckoutRoutes } from "../../navigation/routes"; | ||
import { paymentsCalculatePaymentFeesAction } from "../../store/actions/networking"; | ||
import { useIOBottomSheetAutoresizableModal } from "../../../../../utils/hooks/bottomSheet"; | ||
import { WalletPaymentPickPspScreen } from "../WalletPaymentPickPspScreen"; | ||
import { Bundle } from "../../../../../../definitions/pagopa/ecommerce/Bundle"; | ||
import { PaymentMethodStatusEnum } from "../../../../../../definitions/pagopa/ecommerce/PaymentMethodStatus"; | ||
import I18n from "../../../../../i18n"; | ||
|
||
jest.mock("../../analytics"); | ||
jest.mock("../../../../../utils/hooks/bottomSheet"); | ||
|
||
const mockNavigation = { | ||
navigate: jest.fn(), | ||
setOptions: jest.fn() | ||
}; | ||
|
||
jest.mock("@react-navigation/native", () => ({ | ||
...jest.requireActual("@react-navigation/native"), | ||
useNavigation: () => mockNavigation, | ||
useRoute: () => ({ | ||
params: { rptId: "1234567890" as RptId } | ||
}) | ||
})); | ||
|
||
const CHEAPER_VALUE = 123; | ||
const MIDDLE_VALUE = 456; | ||
const EXPENSIVE_VALUE = 789; | ||
const MOCKED_PSP_LIST: ReadonlyArray<Bundle> = [ | ||
{ | ||
idPsp: "1", | ||
abi: "01010", | ||
pspBusinessName: "BANCO di NAPOLI", | ||
taxPayerFee: CHEAPER_VALUE, | ||
primaryCiIncurredFee: CHEAPER_VALUE, | ||
idBundle: "A" | ||
}, | ||
{ | ||
idPsp: "2", | ||
abi: "01015", | ||
pspBusinessName: "Banco di Sardegna", | ||
taxPayerFee: MIDDLE_VALUE, | ||
primaryCiIncurredFee: MIDDLE_VALUE, | ||
idBundle: "B", | ||
onUs: true | ||
}, | ||
{ | ||
idPsp: "3", | ||
abi: "03015", | ||
pspBusinessName: "FINECO", | ||
taxPayerFee: EXPENSIVE_VALUE, | ||
primaryCiIncurredFee: EXPENSIVE_VALUE, | ||
idBundle: "C" | ||
} | ||
]; | ||
|
||
const globalState = appReducer(undefined, applicationChangeState("active")); | ||
const mockStore = configureMockStore<GlobalState>(); | ||
const mockModal = { | ||
present: jest.fn(), | ||
dismiss: jest.fn(), | ||
bottomSheet: <View testID="modal-view-test" /> | ||
}; | ||
const mockedUseIOBottomSheetAutoresizableModal = | ||
useIOBottomSheetAutoresizableModal as jest.Mock; | ||
mockedUseIOBottomSheetAutoresizableModal.mockReturnValue(mockModal); | ||
|
||
describe("WalletPaymentPickPspScreen", () => { | ||
const renderComponent = () => { | ||
const state = mockStore(globalState); | ||
const store = createStore(appReducer, state as any); | ||
return { | ||
...renderScreenWithNavigationStoreContext<GlobalState>( | ||
WalletPaymentPickPspScreen, | ||
PaymentsCheckoutRoutes.PAYMENT_CHECKOUT_MAKE, | ||
{}, | ||
store | ||
), | ||
store | ||
}; | ||
}; | ||
|
||
it("renders the main content with the list content if psp list is available", () => { | ||
const { getAllByText, store } = renderComponent(); | ||
|
||
store.dispatch( | ||
paymentsCalculatePaymentFeesAction.success({ | ||
bundles: MOCKED_PSP_LIST, | ||
asset: "MOCK", | ||
paymentMethodDescription: "MOCK", | ||
paymentMethodName: "MOCK", | ||
paymentMethodStatus: PaymentMethodStatusEnum.ENABLED | ||
}) | ||
); | ||
|
||
expect(getAllByText("BANCO di NAPOLI")).toBeTruthy(); | ||
}); | ||
|
||
it("shows the featured reason if there is a psp with the onUs flag", () => { | ||
const { getByText, store } = renderComponent(); | ||
store.dispatch( | ||
paymentsCalculatePaymentFeesAction.success({ | ||
bundles: MOCKED_PSP_LIST, | ||
asset: "MOCK", | ||
paymentMethodDescription: "MOCK", | ||
paymentMethodName: "MOCK", | ||
paymentMethodStatus: PaymentMethodStatusEnum.ENABLED | ||
}) | ||
); | ||
expect(getByText(I18n.t("wallet.payment.psp.featuredReason"))).toBeTruthy(); | ||
}); | ||
|
||
it("doesn't show the featured reason if there is not a psp with the onUs flag", () => { | ||
const { queryByText, store } = renderComponent(); | ||
store.dispatch( | ||
paymentsCalculatePaymentFeesAction.success({ | ||
bundles: MOCKED_PSP_LIST.map(psp => { | ||
const { onUs, ...rest } = psp; | ||
return rest; | ||
}), | ||
asset: "MOCK", | ||
paymentMethodDescription: "MOCK", | ||
paymentMethodName: "MOCK", | ||
paymentMethodStatus: PaymentMethodStatusEnum.ENABLED | ||
}) | ||
); | ||
expect(queryByText(I18n.t("wallet.payment.psp.featuredReason"))).toBeNull(); | ||
}); | ||
|
||
it("presents bottom sheet press the sort button", () => { | ||
const { getByTestId, store } = renderComponent(); | ||
store.dispatch( | ||
paymentsCalculatePaymentFeesAction.success({ | ||
bundles: MOCKED_PSP_LIST, | ||
asset: "MOCK", | ||
paymentMethodDescription: "MOCK", | ||
paymentMethodName: "MOCK", | ||
paymentMethodStatus: PaymentMethodStatusEnum.ENABLED | ||
}) | ||
); | ||
const sortButton = getByTestId("wallet-payment-pick-psp-sort-button"); | ||
fireEvent.press(sortButton); | ||
expect(mockModal.present).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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
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