Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [IOCOM-866] Display tags in the header of a SEND message #5440

Merged
merged 18 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,8 @@ features:
activated: "Grazie, il servizio è attivo!"
error: "Si è verificato un errore con la tua richiesta"
details:
badge:
legalValue: "Legal value"
title: Dettaglio del messaggio
noticeCode: "Codice avviso"
loadError:
Expand Down
2 changes: 2 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,8 @@ features:
activated: "Grazie, il servizio è attivo!"
error: "Si è verificato un errore con la tua richiesta"
details:
badge:
legalValue: "Valore legale"
title: Dettaglio del messaggio
noticeCode: "Codice avviso"
loadError:
Expand Down
35 changes: 17 additions & 18 deletions ts/features/pn/__mocks__/message.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import { ThirdPartyMessageWithContent } from "../../../../definitions/backend/ThirdPartyMessageWithContent";
import { ThirdPartyAttachment } from "../../../../definitions/pn/ThirdPartyAttachment";
import { message_1 } from "../../messages/__mocks__/message";
import { ATTACHMENT_CATEGORY } from "../../messages/types/attachmentCategory";

export const thirdPartyMessage: ThirdPartyMessageWithContent = {
...message_1,
created_at: new Date("2020-01-01T00:00:00.000Z"),
third_party_message: {
attachments: [
{
id: "1",
name: "A First Attachment",
content_type: "application/pdf",
category: ATTACHMENT_CATEGORY.DOCUMENT,
url: "/resource/attachment1.pdf"
},
{
id: "2",
name: "A Second Attachment",
content_type: "application/pdf",
category: ATTACHMENT_CATEGORY.DOCUMENT,
url: "/resource/attachment2.pdf"
}
] as Array<ThirdPartyAttachment>,
details: {
abstract: "######## abstract ########",
attachments: [
{
messageId: message_1.id,
id: "1",
displayName: "A First Attachment",
contentType: "application/pdf",
category: ATTACHMENT_CATEGORY.DOCUMENT,
resourceUrl: { href: "/resource/attachment1.pdf" }
},
{
messageId: message_1.id,
id: "2",
displayName: "A Second Attachment",
contentType: "application/pdf",
category: ATTACHMENT_CATEGORY.DOCUMENT,
resourceUrl: { href: "/resource/attachment2.pdf" }
}
],
iun: "731143-7-0317-8200-0",
subject: "######## subject ########",
recipients: [
Expand Down
58 changes: 45 additions & 13 deletions ts/features/pn/components/MessageDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React from "react";
import { ScrollView } from "react-native";
import { ScrollView, View } from "react-native";
import { pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as RA from "fp-ts/lib/ReadonlyArray";
import * as SEP from "fp-ts/lib/Separated";
import { HSpacer, IOStyles, Tag, VSpacer } from "@pagopa/io-app-design-system";
import { ServicePublic } from "../../../../definitions/backend/ServicePublic";
import { UIMessageId } from "../../messages/types";
import { UIAttachment, UIMessageId } from "../../messages/types";
import { PNMessage } from "../store/types/types";
import { NotificationPaymentInfo } from "../../../../definitions/pn/NotificationPaymentInfo";
import { MessageDetailHeader } from "../../messages/components/MessageDetail/MessageDetailHeader";
import { ATTACHMENT_CATEGORY } from "../../messages/types/attachmentCategory";
import I18n from "../../../i18n";
import { MessageDetailsContent } from "./MessageDetailsContent";

type MessageDetailsProps = {
Expand All @@ -14,14 +21,39 @@ type MessageDetailsProps = {
payments?: ReadonlyArray<NotificationPaymentInfo>;
};

export const MessageDetails = ({ message, service }: MessageDetailsProps) => (
<ScrollView>
<MessageDetailHeader
service={service}
sender={message.senderDenomination}
subject={message.subject}
createdAt={message.created_at}
/>
<MessageDetailsContent abstract={message.abstract} />
</ScrollView>
);
export const MessageDetails = ({ message, service }: MessageDetailsProps) => {
const partitionedAttachments = pipe(
message.attachments,
O.fromNullable,
O.getOrElse<ReadonlyArray<UIAttachment>>(() => []),
RA.partition(attachment => attachment.category === ATTACHMENT_CATEGORY.F24)
);

const attachmentList = SEP.left(partitionedAttachments);

return (
<ScrollView>
<MessageDetailHeader
service={service}
sender={message.senderDenomination}
subject={message.subject}
createdAt={message.created_at}
>
<View style={IOStyles.row}>
<Tag
text={I18n.t("features.pn.details.badge.legalValue")}
variant="legalMessage"
/>
{attachmentList.length > 0 && (
<>
<HSpacer size={8} />
<Tag variant="attachment" testID="attachment-tag" />
</>
)}
</View>
<VSpacer size={8} />
</MessageDetailHeader>
<MessageDetailsContent abstract={message.abstract} />
</ScrollView>
);
};
39 changes: 36 additions & 3 deletions ts/features/pn/components/__test__/MessageDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,52 @@ import { PNMessage } from "../../store/types/types";
import { thirdPartyMessage } from "../../__mocks__/message";
import { toPNMessage } from "../../store/types/transformers";
import { UIMessageId } from "../../../messages/types";
import I18n from "../../../../i18n";

const pnMessage = pipe(thirdPartyMessage, toPNMessage, O.toUndefined);
const pnMessage = pipe(thirdPartyMessage, toPNMessage, O.toUndefined)!;

describe("MessageDetails component", () => {
it("should match the snapshot", () => {
it("should match the snapshot with default props", () => {
const { component } = renderComponent(
generateComponentProperties(
thirdPartyMessage.id as UIMessageId,
pnMessage!
pnMessage
)
);
expect(component).toMatchSnapshot();
});

it("should display the legalMessage tag", () => {
const { component } = renderComponent(
generateComponentProperties(
thirdPartyMessage.id as UIMessageId,
pnMessage
)
);
expect(
component.queryByText(I18n.t("features.pn.details.badge.legalValue"))
).not.toBeNull();
});

it("should display the attachment tag if there are attachments", () => {
const { component } = renderComponent(
generateComponentProperties(
thirdPartyMessage.id as UIMessageId,
pnMessage
)
);
expect(component.queryByTestId("attachment-tag")).not.toBeNull();
});

it("should NOT display the attachment tag if there are no attachments", () => {
const { component } = renderComponent(
generateComponentProperties(thirdPartyMessage.id as UIMessageId, {
...pnMessage,
attachments: []
})
);
expect(component.queryByTestId("attachment-tag")).toBeNull();
});
});

const generateComponentProperties = (
Expand Down
Loading
Loading