diff --git a/ts/features/pn/__mocks__/message.ts b/ts/features/pn/__mocks__/message.ts index 3019e1df815..6bfc8eeaccb 100644 --- a/ts/features/pn/__mocks__/message.ts +++ b/ts/features/pn/__mocks__/message.ts @@ -1,44 +1,46 @@ -import { UIAttachment, UIMessageId } from "../../messages/types"; -import { PNMessage } from "../store/types/types"; +import { ThirdPartyMessageWithContent } from "../../../../definitions/backend/ThirdPartyMessageWithContent"; +import { message_1 } from "../../messages/__mocks__/message"; import { ATTACHMENT_CATEGORY } from "../../messages/types/attachmentCategory"; -import { NotificationRecipient } from "../../../../definitions/pn/NotificationRecipient"; -export const messageId = "00000000000000000000000004" as UIMessageId; - -export const pnMessage: PNMessage = { +export const thirdPartyMessage: ThirdPartyMessageWithContent = { + ...message_1, created_at: new Date("2020-01-01T00:00:00.000Z"), - iun: "731143-7-0317-8200-0", - subject: "This is the message subject", - senderDenomination: "Sender denomination", - abstract: "Message abstract", - notificationStatusHistory: [], - recipients: [ - { - recipientType: "-", - taxId: "AAABBB00A00A000A", - denomination: "AaAaAa BbBbBb", - payment: { - noticeCode: "026773337463073118", - creditorTaxId: "00000000009" - } - } - ] as Array, - attachments: [ - { - messageId, - id: "1", - displayName: "A First Attachment", - contentType: "application/pdf", - category: ATTACHMENT_CATEGORY.DOCUMENT, - resourceUrl: { href: "/resource/attachment1.pdf" } - }, - { - messageId, - id: "2", - displayName: "A Second Attachment", - contentType: "application/pdf", - category: ATTACHMENT_CATEGORY.DOCUMENT, - resourceUrl: { href: "/resource/attachment2.pdf" } + third_party_message: { + 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: [ + { + recipientType: "-", + taxId: "AAABBB00A00A000A", + denomination: "AaAaAa BbBbBb", + payment: { + noticeCode: "026773337463073118", + creditorTaxId: "00000000009" + } + } + ], + notificationStatusHistory: [], + senderDenomination: "Sender denomination" } - ] as Array + } }; diff --git a/ts/features/pn/components/__test__/MessageDetails.test.tsx b/ts/features/pn/components/__test__/MessageDetails.test.tsx index 879b8ec686e..b6c8687b84c 100644 --- a/ts/features/pn/components/__test__/MessageDetails.test.tsx +++ b/ts/features/pn/components/__test__/MessageDetails.test.tsx @@ -1,23 +1,35 @@ import React from "react"; import configureMockStore from "redux-mock-store"; +import { pipe } from "fp-ts/lib/function"; +import * as O from "fp-ts/lib/Option"; import { applicationChangeState } from "../../../../store/actions/application"; import { appReducer } from "../../../../store/reducers"; import { MessageDetails } from "../MessageDetails"; import { GlobalState } from "../../../../store/reducers/types"; import { renderScreenWithNavigationStoreContext } from "../../../../utils/testWrapper"; import { PNMessage } from "../../store/types/types"; -import { messageId, pnMessage } from "../../__mocks__/message"; +import { thirdPartyMessage } from "../../__mocks__/message"; +import { toPNMessage } from "../../store/types/transformers"; +import { UIMessageId } from "../../../messages/types"; + +const pnMessage = pipe(thirdPartyMessage, toPNMessage, O.toUndefined); describe("MessageDetails component", () => { it("should match the snapshot", () => { const { component } = renderComponent( - generateComponentProperties(pnMessage) + generateComponentProperties( + thirdPartyMessage.id as UIMessageId, + pnMessage! + ) ); expect(component).toMatchSnapshot(); }); }); -const generateComponentProperties = (message: PNMessage) => ({ +const generateComponentProperties = ( + messageId: UIMessageId, + message: PNMessage +) => ({ messageId, message, payments: undefined, diff --git a/ts/features/pn/components/__test__/__snapshots__/MessageDetails.test.tsx.snap b/ts/features/pn/components/__test__/__snapshots__/MessageDetails.test.tsx.snap index 76c4c33377b..45785dc4e5f 100644 --- a/ts/features/pn/components/__test__/__snapshots__/MessageDetails.test.tsx.snap +++ b/ts/features/pn/components/__test__/__snapshots__/MessageDetails.test.tsx.snap @@ -333,7 +333,7 @@ exports[`MessageDetails component should match the snapshot 1`] = ` testID="message-header-subject" weight="SemiBold" > - This is the message subject + ######## subject ######## - Message abstract + ######## abstract ######## diff --git a/ts/features/pn/screens/__test__/MessageDetailsScreen.test.tsx b/ts/features/pn/screens/__test__/MessageDetailsScreen.test.tsx new file mode 100644 index 00000000000..0aa4268dca0 --- /dev/null +++ b/ts/features/pn/screens/__test__/MessageDetailsScreen.test.tsx @@ -0,0 +1,83 @@ +import configureMockStore from "redux-mock-store"; +import { Action, Store } from "redux"; +import PN_ROUTES from "../../navigation/routes"; +import { GlobalState } from "../../../../store/reducers/types"; +import { appReducer } from "../../../../store/reducers"; +import { MessageDetailsScreen } from "../MessageDetailsScreen"; +import { renderScreenWithNavigationStoreContext } from "../../../../utils/testWrapper"; +import { reproduceSequence } from "../../../../utils/tests"; +import { + loadMessageById, + loadMessageDetails, + loadThirdPartyMessage +} from "../../../messages/store/actions"; +import { + toUIMessage, + toUIMessageDetails +} from "../../../messages/store/reducers/transformers"; +import { message_1 } from "../../../messages/__mocks__/message"; +import { loadServiceDetail } from "../../../../store/actions/services"; +import { service_1 } from "../../../messages/__mocks__/messages"; +import { UIMessageId } from "../../../messages/types"; +import { applicationChangeState } from "../../../../store/actions/application"; +import { thirdPartyMessage } from "../../__mocks__/message"; + +describe("MessageDetailsScreen", () => { + it("should match the snapshot when there is an error", () => { + const sequenceOfActions: ReadonlyArray = [ + applicationChangeState("active") + ]; + + const state: GlobalState = reproduceSequence( + {} as GlobalState, + appReducer, + sequenceOfActions + ); + const mockStore = configureMockStore(); + const store: Store = mockStore(state); + + const { component } = renderComponent(store); + expect(component).toMatchSnapshot(); + }); + + it("should match the snapshot when everything went fine", () => { + const sequenceOfActions: ReadonlyArray = [ + applicationChangeState("active"), + loadMessageById.success(toUIMessage(message_1)), + loadServiceDetail.success(service_1), + loadMessageDetails.success(toUIMessageDetails(message_1)), + loadThirdPartyMessage.success({ + id: message_1.id as UIMessageId, + content: thirdPartyMessage + }) + ]; + + const state: GlobalState = reproduceSequence( + {} as GlobalState, + appReducer, + sequenceOfActions + ); + const mockStore = configureMockStore(); + const store: Store = mockStore(state); + + const { component } = renderComponent(store); + expect(component).toMatchSnapshot(); + }); +}); + +const renderComponent = (store: Store) => { + const { id, sender_service_id } = message_1; + + return { + component: renderScreenWithNavigationStoreContext( + MessageDetailsScreen, + PN_ROUTES.MESSAGE_DETAILS, + { + firstTimeOpening: false, + messageId: id, + serviceId: sender_service_id + }, + store + ) + }; +}; diff --git a/ts/features/pn/screens/__test__/__snapshots__/MessageDetailsScreen.test.tsx.snap b/ts/features/pn/screens/__test__/__snapshots__/MessageDetailsScreen.test.tsx.snap new file mode 100644 index 00000000000..48edcca56d3 --- /dev/null +++ b/ts/features/pn/screens/__test__/__snapshots__/MessageDetailsScreen.test.tsx.snap @@ -0,0 +1,1372 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MessageDetailsScreen should match the snapshot when everything went fine 1`] = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ######## subject ######## + + + + 01 Jan 2020, 00:00 + + + + + + + + ######## abstract ######## + + + + + + + + + + + + + + +`; + +exports[`MessageDetailsScreen should match the snapshot when there is an error 1`] = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Qualcosa è andato storto + + + + Non è stato possibile recuperare i dettagli del tuo messaggio. Riprova per favore + + + + + + + + + + + + + + +`;