Skip to content

Commit

Permalink
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
Browse files Browse the repository at this point in the history
  • Loading branch information
hevelius authored Jan 30, 2024
2 parents 631a748 + d51761c commit aef6bf9
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 35 deletions.
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

0 comments on commit aef6bf9

Please sign in to comment.