Skip to content

Commit

Permalink
chore: [IOBP-1231] Removed total amount from IdPayCard if reward type…
Browse files Browse the repository at this point in the history
… 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
Hantex9 authored Mar 3, 2025
1 parent 085181b commit 191a24e
Show file tree
Hide file tree
Showing 4 changed files with 650 additions and 192 deletions.
2 changes: 1 addition & 1 deletion scripts/generate-api-models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare -a apis=(
"./definitions/pagopa/cobadge/configuration https://raw.githubusercontent.com/pagopa/io-services-metadata/$IO_SERVICES_METADATA_VERSION/pagopa/cobadge/abi_definitions.yml"
"./definitions/pagopa/privative/configuration https://raw.githubusercontent.com/pagopa/io-services-metadata/$IO_SERVICES_METADATA_VERSION/pagopa/privative/definitions.yml"
# IDPay APIs
"./definitions/idpay https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v11.7.1/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml"
"./definitions/idpay https://raw.githubusercontent.com/pagopa/cstar-infrastructure/v12.2.1/src/domains/idpay-app/api/idpay_appio_full/openapi.appio.full.yml"
# Services APIs
"./definitions/services https://raw.githubusercontent.com/pagopa/io-backend/$IO_BACKEND_VERSION/api_services_app_backend.yaml"
# Lollipop APIs
Expand Down
85 changes: 53 additions & 32 deletions ts/features/idpay/wallet/components/IdPayCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as pot from "@pagopa/ts-commons/lib/pot";
import { Avatar, Body, H3, H6, VSpacer } from "@pagopa/io-app-design-system";
import { format } from "date-fns";
import { ImageURISource, StyleSheet, View } from "react-native";
import WalletCardShape from "../../../../../img/features/idpay/wallet_card.svg";
import I18n from "../../../../i18n";
import { formatNumberCentsToAmount } from "../../../../utils/stringBuilder";
import { useIOSelector } from "../../../../store/hooks";
import { idPayWalletInitiativeListSelector } from "../store/reducers";
import { InitiativeRewardTypeEnum } from "../../../../../definitions/idpay/InitiativeDTO";

export type IdPayCardProps = {
name: string;
Expand All @@ -15,42 +19,59 @@ export type IdPayCardProps = {
/**
* Component that renders the ID PAy card in the wallet
*/
export const IdPayCard = (props: IdPayCardProps) => (
<View style={styles.container}>
<View style={styles.card}>
<WalletCardShape />
</View>
<View style={styles.content}>
<View>
<View style={styles.header}>
<H6
color="blueItalia-850"
ellipsizeMode="tail"
numberOfLines={1}
style={{
width: "80%"
}}
>
{props.name}
</H6>
<Avatar size="small" logoUri={props.avatarSource} />
export const IdPayCard = (props: IdPayCardProps) => {
const initiativeListPot = useIOSelector(idPayWalletInitiativeListSelector);
const initiativeCardDetails = pot.getOrElse(
pot.map(initiativeListPot, initiativeList =>
initiativeList.find(
initiative => initiative.initiativeName === props.name
)
),
undefined
);

return (
<View style={styles.container}>
<View style={styles.card}>
<WalletCardShape />
</View>
<View style={styles.content}>
<View>
<View style={styles.header}>
<H6
color="blueItalia-850"
ellipsizeMode="tail"
numberOfLines={1}
style={{
width: "80%"
}}
>
{props.name}
</H6>
<Avatar size="small" logoUri={props.avatarSource} />
</View>
{initiativeCardDetails?.initiativeRewardType !==
InitiativeRewardTypeEnum.EXPENSE && (
<>
<VSpacer size={16} />
<Body weight="Semibold" color="black">
Disponibile
</Body>
<H3 testID="idpay-card-amount" color="blueItalia-500">
{formatNumberCentsToAmount(props.amount, true, "right")}
</H3>
</>
)}
</View>
<VSpacer size={16} />
<Body weight="Semibold" color="black">
Disponibile
<Body weight="Semibold" color="blueItalia-850">
{I18n.t("bonusCard.validUntil", {
endDate: format(props.expireDate, "MM/YY")
})}
</Body>
<H3 color="blueItalia-500">
{formatNumberCentsToAmount(props.amount, true, "right")}
</H3>
</View>
<Body weight="Semibold" color="blueItalia-850">
{I18n.t("bonusCard.validUntil", {
endDate: format(props.expireDate, "MM/YY")
})}
</Body>
</View>
</View>
);
);
};

const styles = StyleSheet.create({
container: {
Expand Down
114 changes: 103 additions & 11 deletions ts/features/idpay/wallet/components/__tests__/IdPayCard.test.tsx
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
};
};
Loading

0 comments on commit 191a24e

Please sign in to comment.