Skip to content

Commit

Permalink
fix: [IOBP-953] Capitalize transaction fields (#6365)
Browse files Browse the repository at this point in the history
## Short description
This pull request includes importing and utilizing a new utility
function for text capitalization, and updating the test cases to cover
new scenarios.

## List of changes proposed in this pull request
- Apply `capitalizeTextName` to `getPayerInfoLabel` function
- Update test suite of `getPayerInfoLabel` to handle uppercase string

## How to test
- Go in `Pagamenti`
- Tap on a transaction
- Check _Eseguita da_ and _Metodo intestato a_ field to be capitalize
(Edit `PaymentsBizEventsTransactionInfoSection` file with custom string
and check results)

---------

Co-authored-by: Alessandro <[email protected]>
  • Loading branch information
LeleDallas and Hantex9 authored Nov 5, 2024
1 parent cb1583e commit 0881665
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 @@ -22,6 +22,7 @@ import { WalletInfo } from "../../../../../definitions/pagopa/biz-events/WalletI
import { getPayerInfoLabel } from "../utils";
import { NoticeDetailResponse } from "../../../../../definitions/pagopa/biz-events/NoticeDetailResponse";
import { OriginEnum } from "../../../../../definitions/pagopa/biz-events/InfoNotice";
import { capitalizeTextName } from "../../../../utils/strings";

type PaymentsBizEventsTransactionInfoSectionProps = {
transaction?: NoticeDetailResponse;
Expand Down Expand Up @@ -99,7 +100,9 @@ const PaymentsBizEventsTransactionInfoSection = ({
label={I18n.t("transaction.details.info.headedTo")}
value={
transactionInfo.walletInfo?.maskedEmail ??
transactionInfo.walletInfo?.accountHolder
capitalizeTextName(
transactionInfo.walletInfo?.accountHolder ?? ""
)
}
/>
<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ describe("getPayerInfoLabel", () => {
const result = getPayerInfoLabel(payer);
expect(result).toBe("John Doe\n(123456789)");
});

it("should return only the name if taxCode is empty string", () => {
const payer = { name: "John Doe", taxCode: "" };
const result = getPayerInfoLabel(payer);
expect(result).toBe("John Doe");
});

it("should return capitalize string", () => {
const payer = { name: "john doe", taxCode: "123456789" };
const result = getPayerInfoLabel(payer);
expect(result).toBe("John Doe\n(123456789)");
});
});

describe("calculateTotalAmount", () => {
Expand Down
3 changes: 2 additions & 1 deletion ts/features/payments/bizEventsTransaction/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SectionListData } from "react-native";
import { NoticeListItem } from "../../../../../definitions/pagopa/biz-events/NoticeListItem";
import { InfoNotice } from "../../../../../definitions/pagopa/biz-events/InfoNotice";
import { capitalizeTextName } from "../../../../utils/strings";

export const RECEIPT_DOCUMENT_TYPE_PREFIX = "data:application/pdf;base64,";

Expand Down Expand Up @@ -64,7 +65,7 @@ export const getPayerInfoLabel = (payer: InfoNotice["payer"]): string => {
return "";
}

const name = payer.name ? payer.name.trim() : "";
const name = payer.name ? capitalizeTextName(payer.name).trim() : "";
const taxCode = payer.taxCode ? payer.taxCode.trim() : "";

const payerInfo = name ? (taxCode ? `${name}\n(${taxCode})` : name) : taxCode;
Expand Down

0 comments on commit 0881665

Please sign in to comment.