-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathMessageDetails.test.tsx
88 lines (80 loc) · 2.71 KB
/
MessageDetails.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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 { 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)!;
describe("MessageDetails component", () => {
it("should match the snapshot with default props", () => {
const { component } = renderComponent(
generateComponentProperties(
thirdPartyMessage.id as UIMessageId,
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 = (
messageId: UIMessageId,
message: PNMessage
) => ({
messageId,
message,
payments: undefined,
service: undefined
});
const renderComponent = (
props: React.ComponentProps<typeof MessageDetails>
) => {
const globalState = appReducer(undefined, applicationChangeState("active"));
const mockStore = configureMockStore<GlobalState>();
const store: ReturnType<typeof mockStore> = mockStore(globalState);
return {
component: renderScreenWithNavigationStoreContext<GlobalState>(
() => <MessageDetails {...props} />,
"DUMMY_ROUTE",
{},
store
),
store
};
};