-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOBP-1231] Removed total amount from IdPayCard if reward type…
… is `EXPENSE` (#6771) ## Short description This PR removes the total amount label from the IdPayCard shown in the wallet home screen if the IdPay initiative is of the `EXPENSE` type. ## List of changes proposed in this pull request - Updated the IDPay openAPI version; - Added a conditional render inside the `IdPayCard` to show the total amount; ## How to test With the dev-server started, onboard a new IDPay EXPENSE type and check that you don't see the total amount inside the wallet home page.
- Loading branch information
Showing
4 changed files
with
650 additions
and
192 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
114 changes: 103 additions & 11 deletions
114
ts/features/idpay/wallet/components/__tests__/IdPayCard.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 |
---|---|---|
@@ -1,18 +1,110 @@ | ||
import { render } from "@testing-library/react-native"; | ||
import { IdPayCard } from "../IdPayCard"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import configureMockStore from "redux-mock-store"; | ||
import { IdPayCard, IdPayCardProps } from "../IdPayCard"; | ||
import { appReducer } from "../../../../../store/reducers"; | ||
|
||
import { applicationChangeState } from "../../../../../store/actions/application"; | ||
import { renderScreenWithNavigationStoreContext } from "../../../../../utils/testWrapper"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { IDPayDetailsRoutes } from "../../../details/navigation"; | ||
import { WalletDTO } from "../../../../../../definitions/idpay/WalletDTO"; | ||
import { | ||
InitiativeRewardTypeEnum, | ||
StatusEnum | ||
} from "../../../../../../definitions/idpay/InitiativeDTO"; | ||
import { formatNumberCentsToAmount } from "../../../../../utils/stringBuilder"; | ||
|
||
const IDPAY_INITIATIVE_ID_MOCK = "1"; | ||
const IDPAY_INITIATIVE_NAME = "18 app"; | ||
const IDPAY_INITIATIVE_END_DATE_MOCK = new Date(2023, 11, 2); | ||
const IDPAY_INITIATIVE_AMOUNT_CENTS_MOCK = 9999; | ||
|
||
const idPayCardProps: IdPayCardProps = { | ||
name: IDPAY_INITIATIVE_NAME, | ||
amount: IDPAY_INITIATIVE_AMOUNT_CENTS_MOCK, | ||
avatarSource: { | ||
uri: "https://vtlogo.com/wp-content/uploads/2021/08/18app-vector-logo.png" | ||
}, | ||
expireDate: new Date(2023, 11, 2) | ||
}; | ||
|
||
const baseInitiativeCardDetails: WalletDTO = { | ||
initiativeList: [ | ||
{ | ||
initiativeId: IDPAY_INITIATIVE_ID_MOCK, | ||
endDate: IDPAY_INITIATIVE_END_DATE_MOCK, | ||
nInstr: 1, | ||
status: StatusEnum.NOT_REFUNDABLE_ONLY_IBAN, | ||
initiativeName: IDPAY_INITIATIVE_NAME, | ||
amountCents: IDPAY_INITIATIVE_AMOUNT_CENTS_MOCK | ||
} | ||
] | ||
}; | ||
|
||
describe("IdPayCard", () => { | ||
it("should match the snapshot", () => { | ||
const component = render( | ||
<IdPayCard | ||
name="18 app" | ||
amount={9999} | ||
avatarSource={{ | ||
uri: "https://vtlogo.com/wp-content/uploads/2021/08/18app-vector-logo.png" | ||
}} | ||
expireDate={new Date(2023, 11, 2)} | ||
/> | ||
const { component } = renderComponent( | ||
idPayCardProps, | ||
InitiativeRewardTypeEnum.REFUND | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it("should hide total amount if reward type is EXPENSE", () => { | ||
const { | ||
component: { queryByTestId } | ||
} = renderComponent(idPayCardProps, InitiativeRewardTypeEnum.EXPENSE); | ||
expect(queryByTestId("idpay-card-amount")).toBeNull(); | ||
}); | ||
|
||
it("should show total amount if reward type is not EXPENSE", () => { | ||
const { | ||
component: { queryByTestId } | ||
} = renderComponent(idPayCardProps, InitiativeRewardTypeEnum.DISCOUNT); | ||
expect(queryByTestId("idpay-card-amount")).toHaveTextContent( | ||
formatNumberCentsToAmount( | ||
IDPAY_INITIATIVE_AMOUNT_CENTS_MOCK, | ||
true, | ||
"right" | ||
) | ||
); | ||
}); | ||
}); | ||
|
||
const renderComponent = ( | ||
props: IdPayCardProps, | ||
rewardType: InitiativeRewardTypeEnum | ||
) => { | ||
const globalState = appReducer(undefined, applicationChangeState("active")); | ||
const mockStore = configureMockStore<GlobalState>(); | ||
const store: ReturnType<typeof mockStore> = mockStore({ | ||
...globalState, | ||
features: { | ||
...globalState.features, | ||
idPay: { | ||
...globalState.features.idPay, | ||
wallet: { | ||
...globalState.features.idPay.wallet, | ||
initiatives: pot.some({ | ||
initiativeList: baseInitiativeCardDetails.initiativeList.map( | ||
initiative => ({ | ||
...initiative, | ||
initiativeRewardType: rewardType | ||
}) | ||
) | ||
}) | ||
} | ||
} | ||
} | ||
} as GlobalState); | ||
|
||
return { | ||
component: renderScreenWithNavigationStoreContext<GlobalState>( | ||
() => <IdPayCard {...props} />, | ||
IDPayDetailsRoutes.IDPAY_DETAILS_MAIN, | ||
{}, | ||
store | ||
), | ||
store | ||
}; | ||
}; |
Oops, something went wrong.