-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankAccount.spec.tsx
145 lines (124 loc) · 3.93 KB
/
BankAccount.spec.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React from "react";
import { ScreenSize } from "@/shared/constants";
import { BankAccountDetails, Gender } from "@/shared/models";
import {
fireEvent,
mockScreenSize,
render,
screen,
within,
} from "@/shared/utils/tests";
import withTestId from "@/shared/utils/tests/withTestId";
import BankAccount from "./BankAccount";
jest.mock(
"@/pages/OldCommon/components/CommonDetailContainer/AddProposalComponent/AddBankDetails/AddBankDetails",
() => {
const module = jest.requireActual(
"@/pages/OldCommon/components/CommonDetailContainer/AddProposalComponent/AddBankDetails/AddBankDetails",
);
return {
...module,
AddBankDetails: jest.fn(
withTestId("add-bank-details", module.AddBankDetails),
),
};
},
);
jest.mock("../AddingCard", () => {
const module = jest.requireActual("../AddingCard");
return {
...module,
AddingCard: jest.fn(withTestId("adding-card", module.AddingCard)),
};
});
jest.mock("../BankAccountInfo", () => {
const module = jest.requireActual("../BankAccountInfo");
return {
...module,
BankAccountInfo: jest.fn(
withTestId("bank-account-info", module.BankAccountInfo),
),
};
});
jest.mock("@/shared/components", () => {
const module = jest.requireActual("@/shared/components");
const { default: withTestId } = jest.requireActual(
"@/shared/utils/tests/withTestId",
);
return {
...module,
Modal: jest.fn(
withTestId("modal", module.Modal, { shouldWrapChildren: true }),
),
};
});
describe("BankAccount", () => {
const bankAccount: BankAccountDetails = {
bankCode: 123,
branchNumber: 11111,
accountNumber: 22222,
identificationDocs: [],
city: "City",
country: "IL",
streetAddress: "Street Address",
streetNumber: 33,
firstName: "Ignat",
lastName: "Petrovich",
socialId: "123456789",
socialIdIssueDate: "10/03/2022",
birthdate: "01/02/1995",
gender: Gender.Male,
phoneNumber: "9999999999",
email: "example@gmail.com",
};
beforeEach(() => {
mockScreenSize(ScreenSize.Desktop);
});
it("should allow to add details", () => {
render(<BankAccount bankAccount={null} onBankAccountChange={() => {}} />);
expect(screen.getByTestId("adding-card")).toBeInTheDocument();
});
it("should open modal to add details", () => {
render(<BankAccount bankAccount={null} onBankAccountChange={() => {}} />);
fireEvent.click(screen.getByText(/Add Bank Account/i));
const modals = screen.getAllByTestId("modal");
expect(screen.queryByTestId("adding-card")).toBeInTheDocument();
expect(
modals.some((modal) => within(modal).queryByTestId("add-bank-details")),
).toBeTruthy();
});
it("should show details", () => {
render(
<BankAccount bankAccount={bankAccount} onBankAccountChange={() => {}} />,
);
expect(screen.getByTestId("bank-account-info")).toBeInTheDocument();
});
it("should open modal to edit bank details", () => {
render(
<BankAccount bankAccount={bankAccount} onBankAccountChange={() => {}} />,
);
fireEvent.click(screen.getByText(/Edit Details/i));
const modals = screen.getAllByTestId("modal");
expect(screen.queryByTestId("bank-account-info")).toBeInTheDocument();
expect(
modals.some((modal) => within(modal).queryByTestId("add-bank-details")),
).toBeTruthy();
});
describe("for mobile view", () => {
beforeEach(() => {
mockScreenSize(ScreenSize.Mobile);
});
it("should allow to add details", () => {
render(<BankAccount bankAccount={null} onBankAccountChange={() => {}} />);
fireEvent.click(screen.getByText(/Add Bank Account/i));
const modals = screen.queryAllByTestId("modal");
expect(screen.queryByTestId("adding-card")).not.toBeInTheDocument();
expect(
modals &&
modals.every(
(modal) => !within(modal).queryByTestId("add-bank-details"),
),
).toBeTruthy();
});
});
});