@licklist/design 0.63.1 → 0.63.3-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bitbucket-pipelines.yml +0 -8
- package/dist/date-time-button/DateTimeButton.js +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts.map +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.js +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts.map +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.js +1 -1
- package/dist/iframe/payment/order-items-table/utils/paymentSummary.d.ts.map +1 -1
- package/dist/product-set/control/DateAndRecurrenceInput.d.ts +1 -1
- package/dist/product-set/control/DateAndRecurrenceInput.d.ts.map +1 -1
- package/dist/product-set/control/DateAndRecurrenceInput.js +1 -1
- package/dist/product-set/control/DateInput.js +1 -1
- package/dist/product-set/control/ProductSetControl.d.ts +3 -2
- package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
- package/dist/product-set/control/ProductSetControl.js +1 -1
- package/dist/product-set/form/ProductCategoriesControl.d.ts +3 -1
- package/dist/product-set/form/ProductCategoriesControl.d.ts.map +1 -1
- package/dist/product-set/form/ProductCategoriesControl.js +1 -1
- package/dist/product-set/form/ProductSetForm.d.ts +6 -2
- package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
- package/dist/product-set/form/ProductSetForm.js +1 -1
- package/dist/product-set/form/ProductsControl.d.ts +3 -1
- package/dist/product-set/form/ProductsControl.d.ts.map +1 -1
- package/dist/product-set/form/ProductsControl.js +1 -1
- package/dist/product-set/form/StepsControl.d.ts +3 -1
- package/dist/product-set/form/StepsControl.d.ts.map +1 -1
- package/dist/product-set/form/StepsControl.js +1 -1
- package/dist/product-set/product/ProductControl.d.ts +1 -0
- package/dist/product-set/product/ProductControl.d.ts.map +1 -1
- package/dist/product-set/product/ProductControl.js +1 -1
- package/dist/product-set/step/StepControl.d.ts +2 -1
- package/dist/product-set/step/StepControl.d.ts.map +1 -1
- package/dist/product-set/step/StepControl.js +1 -1
- package/dist/provider/working-hours-input/WorkingHoursInputDescription.d.ts.map +1 -1
- package/dist/provider/working-hours-input/WorkingHoursInputDescription.js +1 -1
- package/dist/recurring-date-picker-input/RecurrenceIntervalAndFrequencyInput.d.ts.map +1 -1
- package/dist/recurring-date-picker-input/RecurrenceIntervalAndFrequencyInput.js +1 -1
- package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts +3 -1
- package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts.map +1 -1
- package/dist/recurring-date-picker-input/RecurringDatePickerInput.js +1 -1
- package/dist/recurring-date-picker-input/utils.d.ts +5 -0
- package/dist/recurring-date-picker-input/utils.d.ts.map +1 -1
- package/dist/recurring-date-picker-input/utils.js +1 -1
- package/dist/sales/booking/results/components/ResultCard.d.ts.map +1 -1
- package/dist/sales/coupon/control/CouponFormControl.d.ts +2 -1
- package/dist/sales/coupon/control/CouponFormControl.d.ts.map +1 -1
- package/dist/sales/coupon/control/CouponFormControl.js +1 -1
- package/dist/sales/coupon/form/CouponFrom.d.ts +2 -2
- package/dist/sales/coupon/form/CouponFrom.d.ts.map +1 -1
- package/dist/sales/coupon/utils/index.d.ts +7 -0
- package/dist/sales/coupon/utils/index.d.ts.map +1 -0
- package/dist/sales/coupon/utils/index.js +1 -0
- package/dist/setting/admin/AdminSettingForm.d.ts +2 -2
- package/dist/setting/admin/AdminSettingForm.d.ts.map +1 -1
- package/dist/setting/dashboard/DashboardSettingForm.d.ts +1 -0
- package/dist/setting/dashboard/DashboardSettingForm.d.ts.map +1 -1
- package/dist/setting/dashboard/DashboardSettingForm.js +1 -1
- package/dist/sortable-tree/SortableTreeItem.d.ts +1 -2
- package/dist/sortable-tree/SortableTreeItem.d.ts.map +1 -1
- package/dist/sortable-tree/SortableTreeItem.js +1 -1
- package/dist/styles/iframe-page/PageBody.scss +0 -1
- package/dist/styles/sales/BookingResults.scss +1 -1
- package/dist/styles/zones/ZoneForm.scss +2 -1
- package/dist/typeahead/Typeahead.d.ts +2 -1
- package/dist/typeahead/Typeahead.d.ts.map +1 -1
- package/dist/typeahead/Typeahead.js +1 -1
- package/dist/zone/form/ZoneForm.d.ts +2 -2
- package/dist/zone/form/ZoneForm.d.ts.map +1 -1
- package/dist/zone/form/ZoneForm.js +1 -1
- package/dist/zone/form/components/ZoneControl.d.ts +2 -2
- package/dist/zone/form/components/ZoneControl.d.ts.map +1 -1
- package/dist/zone/form/components/ZoneControl.js +1 -1
- package/dist/zone/form/components/ZoneRecurrencesControl.d.ts +4 -4
- package/dist/zone/form/components/ZoneRecurrencesControl.d.ts.map +1 -1
- package/dist/zone/form/components/ZoneRecurrencesControl.js +1 -1
- package/dist/zone/form/utils/dates.d.ts.map +1 -1
- package/package.json +12 -37
- package/src/date-time-button/DateTimeButton.stories.tsx +2 -1
- package/src/date-time-button/DateTimeButton.tsx +7 -5
- package/src/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.tsx +14 -9
- package/src/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.tsx +2 -0
- package/src/iframe/payment/order-items-table/utils/paymentSummary.tsx +1 -0
- package/src/product-set/control/DateAndRecurrenceInput.tsx +3 -4
- package/src/product-set/control/DateInput.tsx +2 -2
- package/src/product-set/control/ProductSetControl.tsx +11 -4
- package/src/product-set/form/ProductCategoriesControl.tsx +15 -4
- package/src/product-set/form/ProductSetForm.tsx +13 -2
- package/src/product-set/form/ProductsControl.tsx +93 -77
- package/src/product-set/form/StepsControl.tsx +15 -7
- package/src/product-set/product/ProductControl.tsx +39 -39
- package/src/product-set/step/StepControl.tsx +4 -3
- package/src/provider/working-hours-input/WorkingHoursInputDescription.tsx +4 -18
- package/src/recurring-date-picker-input/RecurrenceIntervalAndFrequencyInput.tsx +40 -21
- package/src/recurring-date-picker-input/RecurringDatePickerInput.stories.tsx +13 -7
- package/src/recurring-date-picker-input/RecurringDatePickerInput.tsx +12 -1
- package/src/recurring-date-picker-input/utils.ts +90 -1
- package/src/sales/booking/results/components/ResultCard.tsx +0 -3
- package/src/sales/coupon/control/CouponFormControl.tsx +28 -51
- package/src/sales/coupon/form/CouponFrom.tsx +5 -15
- package/src/sales/coupon/utils/index.ts +13 -0
- package/src/setting/admin/AdminSettingForm.tsx +2 -2
- package/src/setting/dashboard/DashboardSettingForm.tsx +13 -0
- package/src/sortable-tree/SortableTreeItem.tsx +0 -3
- package/src/static/switch/BooleanSwitch.tsx +1 -1
- package/src/styles/iframe-page/PageBody.scss +0 -1
- package/src/styles/sales/BookingResults.scss +1 -1
- package/src/styles/zones/ZoneForm.scss +2 -1
- package/src/typeahead/Typeahead.tsx +16 -3
- package/src/zone/form/ZoneForm.tsx +3 -2
- package/src/zone/form/components/ZoneControl.tsx +3 -3
- package/src/zone/form/components/ZoneRecurrencesControl.tsx +7 -5
- package/src/zone/form/utils/dates.ts +9 -10
- package/jest.config.js +0 -29
- package/tests/Auth/Authorizer.test.tsx +0 -194
- package/tests/Auth/Layout/UserNavDropDown.test.tsx +0 -43
- package/tests/Auth/Layout/UserNavDropDownToggle.test.tsx +0 -33
- package/tests/Auth/Login/LoginComponent.test.tsx +0 -246
- package/tests/Auth/Login/LoginFormComponent.test.tsx +0 -182
- package/tests/Auth/Register/RegisterComponent.test.tsx +0 -285
- package/tests/Auth/Register/RegisterFormComponent.test.tsx +0 -170
- package/tests/Auth/Settings/Dashboard/IpInput.test.tsx +0 -130
- package/tests/Auth/Social/SocialCallbackComponent.test.tsx +0 -133
- package/tests/Auth/Social/SocialFormComponent.test.tsx +0 -118
- package/tests/FileUpload/FileUpload.test.tsx +0 -42
- package/tests/Notification/EmailTemplate.test.tsx +0 -82
- package/tests/ProductSet/ProductSetPopover.test.tsx +0 -40
- package/tests/Report/Report.test.tsx +0 -48
- package/tests/Sales/Coupon.test.tsx +0 -51
- package/tests/Sales/SalesAndVIews.test.tsx +0 -63
- package/tests/SnippetTemplates/SnippetTemplates.test.tsx +0 -56
- package/tests/Table/FilterHelperComponent.test.tsx +0 -88
- package/tests/Table/PaginationHelperComponent.test.tsx +0 -109
- package/tests/Table/PerPageHelperComponent.test.tsx +0 -34
- package/tests/Table/TableHelperComponent.test.tsx +0 -295
- package/tests/TipTapEditor/TipTapEditor.test.tsx +0 -28
- package/tests/__mock__/hooks/useAuthApi.ts +0 -13
- package/tests/__mock__/hooks/useAuthMock.ts +0 -13
- package/tests/__mock__/hooks/useFormMock.ts +0 -27
- package/tests/__mock__/hooks/useNotificationMock.ts +0 -13
- package/tests/__mock__/hooks/useQueryMock.ts +0 -16
- package/tests/__mock__/hooks/useSocialApiMock.ts +0 -20
- package/tests/__mock__/hooks/useTranslationMock.ts +0 -17
- package/tests/__mock__/hooks/useUserApiMock.ts +0 -18
- package/tests/__mock__/hooks/useUserMock.ts +0 -13
- package/tests/__mock__/styleMock.js +0 -1
- package/tests/__mock__/windowMock.ts +0 -5
- package/tests/packages/react-query.tsx +0 -28
- package/tests/setupTests.ts +0 -10
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prefer-promise-reject-errors */
|
|
2
|
-
import RouteService from "@licklist/plugins/dist/services/Route/RouteService";
|
|
3
|
-
import { UserRegisterRequest } from "@licklist/plugins/dist/types/Request/UserRegisterRequest";
|
|
4
|
-
import { mount, shallow } from "enzyme";
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
import { act } from "react-dom/test-utils";
|
|
7
|
-
import { MemoryRouter } from "react-router-dom";
|
|
8
|
-
import {
|
|
9
|
-
RegisterComponent,
|
|
10
|
-
RegisterFormComponent,
|
|
11
|
-
} from "../../../src/auth/Register";
|
|
12
|
-
import useAuthMock from "../../__mock__/hooks/useAuthMock";
|
|
13
|
-
import useNotificationMock from "../../__mock__/hooks/useNotificationMock";
|
|
14
|
-
import useTranslationMock from "../../__mock__/hooks/useTranslationMock";
|
|
15
|
-
import useUserApiMock from "../../__mock__/hooks/useUserApiMock";
|
|
16
|
-
import useUserMock from "../../__mock__/hooks/useUserMock";
|
|
17
|
-
|
|
18
|
-
jest.mock("moment", () => () => ({
|
|
19
|
-
year: jest.fn().mockReturnThis(),
|
|
20
|
-
month: jest.fn().mockReturnThis(),
|
|
21
|
-
date: jest.fn().mockReturnThis(),
|
|
22
|
-
diff: jest.fn().mockReturnThis(),
|
|
23
|
-
format: "format",
|
|
24
|
-
}));
|
|
25
|
-
jest.mock("react-i18next", () => ({
|
|
26
|
-
Trans: jest.fn().mockReturnValue("test"),
|
|
27
|
-
useTranslation: jest.fn(),
|
|
28
|
-
}));
|
|
29
|
-
jest.mock("react-hook-form", () => ({
|
|
30
|
-
Controller: () => "controller",
|
|
31
|
-
useForm: () => ({
|
|
32
|
-
register: jest.fn(),
|
|
33
|
-
handleSubmit: (callback: (e: any) => void) => (e: any) => callback(e),
|
|
34
|
-
formState: {
|
|
35
|
-
errors: jest.fn(),
|
|
36
|
-
dirtyFields: {
|
|
37
|
-
has: jest.fn(),
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
setValue: jest.fn(),
|
|
41
|
-
getValues: jest.fn(),
|
|
42
|
-
control: jest.fn(),
|
|
43
|
-
watch: jest.fn(),
|
|
44
|
-
}),
|
|
45
|
-
}));
|
|
46
|
-
jest.mock("@licklist/plugins/dist/context/app/hooks/useNotification");
|
|
47
|
-
jest.mock("@licklist/plugins/dist/context/user/hooks/useAuth");
|
|
48
|
-
jest.mock("@licklist/plugins/dist/context/user/hooks/useUser");
|
|
49
|
-
jest.mock("@licklist/plugins/dist/hooks/Api/useUserApi");
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
useTranslationMock();
|
|
53
|
-
useNotificationMock({
|
|
54
|
-
danger: jest.fn(),
|
|
55
|
-
success: jest.fn(),
|
|
56
|
-
});
|
|
57
|
-
useAuthMock({
|
|
58
|
-
setSecrets: jest.fn(),
|
|
59
|
-
});
|
|
60
|
-
useUserMock({
|
|
61
|
-
login: jest.fn(),
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
afterAll(() => {
|
|
66
|
-
jest.resetAllMocks();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("RegisterComponent", () => {
|
|
70
|
-
it("should be rendered without issues", () => {
|
|
71
|
-
const component = shallow(
|
|
72
|
-
<MemoryRouter initialEntries={["/"]}>
|
|
73
|
-
<RegisterComponent />
|
|
74
|
-
</MemoryRouter>
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(component.exists()).toBeTruthy();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should show danger notification if register did not succeed", async () => {
|
|
81
|
-
let component: any;
|
|
82
|
-
|
|
83
|
-
const notificationDangerMock = jest.fn();
|
|
84
|
-
const notificationSuccessMock = jest.fn();
|
|
85
|
-
const registerMock = jest.fn(() =>
|
|
86
|
-
Promise.reject({
|
|
87
|
-
config: "",
|
|
88
|
-
request: "",
|
|
89
|
-
response: {
|
|
90
|
-
data: { errors: ["Something went wrong"] },
|
|
91
|
-
},
|
|
92
|
-
} as any)
|
|
93
|
-
);
|
|
94
|
-
const profileMock = jest.fn();
|
|
95
|
-
|
|
96
|
-
useNotificationMock({
|
|
97
|
-
danger: notificationDangerMock,
|
|
98
|
-
success: notificationSuccessMock,
|
|
99
|
-
});
|
|
100
|
-
useUserApiMock({
|
|
101
|
-
register: registerMock,
|
|
102
|
-
profile: profileMock,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
RouteService.redirectTo = jest.fn();
|
|
106
|
-
|
|
107
|
-
act(() => {
|
|
108
|
-
component = mount(
|
|
109
|
-
<MemoryRouter>
|
|
110
|
-
<RegisterComponent />
|
|
111
|
-
</MemoryRouter>
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await act(async () => {
|
|
116
|
-
const credentials: UserRegisterRequest = {
|
|
117
|
-
email: "email",
|
|
118
|
-
password: "password",
|
|
119
|
-
first_name: "first_name",
|
|
120
|
-
last_name: "last_name",
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
await component.find(RegisterFormComponent).prop("onSubmit")(credentials);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
component.update();
|
|
127
|
-
|
|
128
|
-
expect(component.exists()).toBeTruthy();
|
|
129
|
-
expect(registerMock).toHaveBeenCalledTimes(1);
|
|
130
|
-
expect(notificationDangerMock).toHaveBeenCalledTimes(0);
|
|
131
|
-
expect(profileMock).toHaveBeenCalledTimes(0);
|
|
132
|
-
expect(notificationSuccessMock).toHaveBeenCalledTimes(0);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("should show danger notification if profile did not succeed", async () => {
|
|
136
|
-
let component: any;
|
|
137
|
-
|
|
138
|
-
const registerResponse = {
|
|
139
|
-
access_token: "access_token",
|
|
140
|
-
refresh_token: "refresh_token",
|
|
141
|
-
token_type: "token_type",
|
|
142
|
-
expires_in: null,
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const notificationDangerMock = jest.fn();
|
|
146
|
-
const notificationSuccessMock = jest.fn();
|
|
147
|
-
const registerMock = jest.fn(() => Promise.resolve(registerResponse));
|
|
148
|
-
const profileMock = jest.fn(() => Promise.reject(new Error("danger")));
|
|
149
|
-
const setAuthorizationTokenMock = jest.fn();
|
|
150
|
-
const setSecretsMock = jest.fn();
|
|
151
|
-
|
|
152
|
-
useNotificationMock({
|
|
153
|
-
danger: notificationDangerMock,
|
|
154
|
-
success: notificationSuccessMock,
|
|
155
|
-
});
|
|
156
|
-
useUserApiMock({
|
|
157
|
-
register: registerMock,
|
|
158
|
-
profile: profileMock,
|
|
159
|
-
setAuthorizationToken: setAuthorizationTokenMock,
|
|
160
|
-
});
|
|
161
|
-
useAuthMock({
|
|
162
|
-
setSecrets: setSecretsMock,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
RouteService.redirectTo = jest.fn();
|
|
166
|
-
|
|
167
|
-
act(() => {
|
|
168
|
-
component = mount(
|
|
169
|
-
<MemoryRouter>
|
|
170
|
-
<RegisterComponent />
|
|
171
|
-
</MemoryRouter>
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
await act(async () => {
|
|
176
|
-
const credentials: UserRegisterRequest = {
|
|
177
|
-
email: "email",
|
|
178
|
-
password: "password",
|
|
179
|
-
first_name: "first_name",
|
|
180
|
-
last_name: "last_name",
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
await component.find(RegisterFormComponent).prop("onSubmit")(credentials);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
component.update();
|
|
187
|
-
|
|
188
|
-
expect(component.exists()).toBeTruthy();
|
|
189
|
-
expect(registerMock).toHaveBeenCalledTimes(1);
|
|
190
|
-
expect(setSecretsMock).toHaveBeenCalledTimes(1);
|
|
191
|
-
expect(setSecretsMock).toHaveBeenCalledWith(registerResponse);
|
|
192
|
-
expect(setAuthorizationTokenMock).toHaveBeenCalledTimes(1);
|
|
193
|
-
expect(setAuthorizationTokenMock).toHaveBeenCalledWith(
|
|
194
|
-
registerResponse.access_token
|
|
195
|
-
);
|
|
196
|
-
expect(profileMock).toHaveBeenCalledTimes(1);
|
|
197
|
-
expect(notificationDangerMock).toHaveBeenCalledTimes(1);
|
|
198
|
-
expect(notificationSuccessMock).toHaveBeenCalledTimes(0);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("should show success notification if register and profile did succeed", async () => {
|
|
202
|
-
let component: any;
|
|
203
|
-
|
|
204
|
-
const registerResponse = {
|
|
205
|
-
access_token: "access_token",
|
|
206
|
-
refresh_token: "refresh_token",
|
|
207
|
-
token_type: "token_type",
|
|
208
|
-
expires_in: null,
|
|
209
|
-
};
|
|
210
|
-
const profileResponse = {
|
|
211
|
-
id: 1,
|
|
212
|
-
first_name: "first_name",
|
|
213
|
-
last_name: "last_name",
|
|
214
|
-
email: "email",
|
|
215
|
-
role: null,
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const notificationDangerMock = jest.fn();
|
|
219
|
-
const notificationSuccessMock = jest.fn();
|
|
220
|
-
const registerMock = jest.fn(() => Promise.resolve(registerResponse));
|
|
221
|
-
const profileMock = jest.fn(() =>
|
|
222
|
-
Promise.resolve({
|
|
223
|
-
error: false,
|
|
224
|
-
message: profileResponse,
|
|
225
|
-
})
|
|
226
|
-
);
|
|
227
|
-
const setAuthorizationTokenMock = jest.fn();
|
|
228
|
-
const setSecretsMock = jest.fn();
|
|
229
|
-
const userLoginMock = jest.fn();
|
|
230
|
-
|
|
231
|
-
useNotificationMock({
|
|
232
|
-
danger: notificationDangerMock,
|
|
233
|
-
success: notificationSuccessMock,
|
|
234
|
-
});
|
|
235
|
-
useUserApiMock({
|
|
236
|
-
register: registerMock,
|
|
237
|
-
profile: profileMock,
|
|
238
|
-
setAuthorizationToken: setAuthorizationTokenMock,
|
|
239
|
-
});
|
|
240
|
-
useAuthMock({
|
|
241
|
-
setSecrets: setSecretsMock,
|
|
242
|
-
});
|
|
243
|
-
useUserMock({
|
|
244
|
-
login: userLoginMock,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
RouteService.redirectTo = jest.fn();
|
|
248
|
-
|
|
249
|
-
act(() => {
|
|
250
|
-
component = mount(
|
|
251
|
-
<MemoryRouter>
|
|
252
|
-
<RegisterComponent />
|
|
253
|
-
</MemoryRouter>
|
|
254
|
-
);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
await act(async () => {
|
|
258
|
-
const credentials: UserRegisterRequest = {
|
|
259
|
-
email: "email",
|
|
260
|
-
password: "password",
|
|
261
|
-
first_name: "first_name",
|
|
262
|
-
last_name: "last_name",
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
await component.find(RegisterFormComponent).prop("onSubmit")(credentials);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
component.update();
|
|
269
|
-
|
|
270
|
-
expect(component.exists()).toBeTruthy();
|
|
271
|
-
expect(registerMock).toHaveBeenCalledTimes(1);
|
|
272
|
-
expect(setSecretsMock).toHaveBeenCalledTimes(1);
|
|
273
|
-
expect(setSecretsMock).toHaveBeenCalledWith(registerResponse);
|
|
274
|
-
expect(setAuthorizationTokenMock).toHaveBeenCalledTimes(1);
|
|
275
|
-
expect(setAuthorizationTokenMock).toHaveBeenCalledWith(
|
|
276
|
-
registerResponse.access_token
|
|
277
|
-
);
|
|
278
|
-
expect(profileMock).toHaveBeenCalledTimes(1);
|
|
279
|
-
expect(userLoginMock).toHaveBeenCalledTimes(1);
|
|
280
|
-
expect(userLoginMock).toHaveBeenCalledWith(profileResponse);
|
|
281
|
-
expect(notificationDangerMock).toHaveBeenCalledTimes(0);
|
|
282
|
-
expect(notificationSuccessMock).toHaveBeenCalledTimes(1);
|
|
283
|
-
expect(RouteService.redirectTo).toHaveBeenCalledTimes(1);
|
|
284
|
-
});
|
|
285
|
-
});
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/* eslint-disable testing-library/no-unnecessary-act */
|
|
2
|
-
/* eslint-disable testing-library/no-node-access */
|
|
3
|
-
/* eslint-disable testing-library/no-container */
|
|
4
|
-
import { mount, shallow } from "enzyme";
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
import { act } from "react-dom/test-utils";
|
|
7
|
-
import { fireEvent, render } from "@testing-library/react";
|
|
8
|
-
import { RegisterFormComponent } from "../../../src/auth/Register/RegisterFormComponent";
|
|
9
|
-
import useTranslationMock from "../../__mock__/hooks/useTranslationMock";
|
|
10
|
-
|
|
11
|
-
jest.mock("moment", () => () => ({
|
|
12
|
-
year: jest.fn().mockReturnThis(),
|
|
13
|
-
month: jest.fn().mockReturnThis(),
|
|
14
|
-
date: jest.fn().mockReturnThis(),
|
|
15
|
-
diff: jest.fn().mockReturnThis(),
|
|
16
|
-
format: "format",
|
|
17
|
-
}));
|
|
18
|
-
jest.mock("react-i18next", () => ({
|
|
19
|
-
Trans: jest.fn().mockReturnValue("test"),
|
|
20
|
-
useTranslation: jest.fn(),
|
|
21
|
-
}));
|
|
22
|
-
jest.mock("react-hook-form", () => ({
|
|
23
|
-
Controller: () => "controller",
|
|
24
|
-
useForm: () => ({
|
|
25
|
-
register: jest.fn(),
|
|
26
|
-
handleSubmit: (callback: (e: any) => void) => (e: any) => callback(e),
|
|
27
|
-
formState: {
|
|
28
|
-
errors: jest.fn(),
|
|
29
|
-
dirtyFields: {
|
|
30
|
-
has: jest.fn(),
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
setValue: jest.fn(),
|
|
34
|
-
getValues: jest.fn(),
|
|
35
|
-
control: jest.fn(),
|
|
36
|
-
watch: jest.fn(),
|
|
37
|
-
}),
|
|
38
|
-
}));
|
|
39
|
-
jest.mock("@licklist/plugins/dist/context/app/hooks/useNotification");
|
|
40
|
-
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
useTranslationMock();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterAll(() => {
|
|
46
|
-
jest.resetAllMocks();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("RegisterFormComponent", () => {
|
|
50
|
-
it("should be rendered without issues", () => {
|
|
51
|
-
const component = shallow(
|
|
52
|
-
<RegisterFormComponent
|
|
53
|
-
isLoading={false}
|
|
54
|
-
setIsLoading={() => false}
|
|
55
|
-
invitation={null}
|
|
56
|
-
/>
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
expect(component.exists()).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should be disabled if it is loading", () => {
|
|
63
|
-
const component = mount(
|
|
64
|
-
<RegisterFormComponent
|
|
65
|
-
isLoading
|
|
66
|
-
setIsLoading={() => false}
|
|
67
|
-
invitation={null}
|
|
68
|
-
/>
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
expect(component.exists()).toBeTruthy();
|
|
72
|
-
expect(
|
|
73
|
-
component.find({ name: "first_name" }).at(0).prop("disabled")
|
|
74
|
-
).toBeTruthy();
|
|
75
|
-
expect(
|
|
76
|
-
component.find({ name: "last_name" }).at(0).prop("disabled")
|
|
77
|
-
).toBeTruthy();
|
|
78
|
-
expect(
|
|
79
|
-
component.find({ name: "email" }).at(0).prop("disabled")
|
|
80
|
-
).toBeTruthy();
|
|
81
|
-
expect(
|
|
82
|
-
component.find({ name: "password" }).at(0).prop("disabled")
|
|
83
|
-
).toBeTruthy();
|
|
84
|
-
expect(
|
|
85
|
-
component.find({ name: "post_code" }).at(0).prop("disabled")
|
|
86
|
-
).toBeTruthy();
|
|
87
|
-
expect(
|
|
88
|
-
component.find({ name: "gender" }).at(0).prop("disabled")
|
|
89
|
-
).toBeTruthy();
|
|
90
|
-
expect(
|
|
91
|
-
component.find({ name: "gender" }).at(1).prop("disabled")
|
|
92
|
-
).toBeTruthy();
|
|
93
|
-
expect(
|
|
94
|
-
component.find({ name: "receive_promo" }).at(0).prop("disabled")
|
|
95
|
-
).toBeTruthy();
|
|
96
|
-
expect(
|
|
97
|
-
component.find({ name: "receive_partner_promo" }).at(0).prop("disabled")
|
|
98
|
-
).toBeTruthy();
|
|
99
|
-
expect(
|
|
100
|
-
component.find({ type: "submit" }).at(0).prop("disabled")
|
|
101
|
-
).toBeTruthy();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("should handle submit action", async () => {
|
|
105
|
-
const onSubmitMock = jest.fn();
|
|
106
|
-
|
|
107
|
-
const { container } = render(
|
|
108
|
-
<RegisterFormComponent
|
|
109
|
-
isLoading={false}
|
|
110
|
-
setIsLoading={() => false}
|
|
111
|
-
onSubmit={onSubmitMock}
|
|
112
|
-
invitation={null}
|
|
113
|
-
/>
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const firstNameEvent = {
|
|
117
|
-
target: {
|
|
118
|
-
name: "first_name",
|
|
119
|
-
value: "first_name",
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const lastNameEvent = {
|
|
124
|
-
target: {
|
|
125
|
-
name: "last_name",
|
|
126
|
-
value: "last_name",
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const emailEvent = {
|
|
131
|
-
target: {
|
|
132
|
-
name: "email",
|
|
133
|
-
value: "email",
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const passwordEvent = {
|
|
138
|
-
target: {
|
|
139
|
-
name: "password",
|
|
140
|
-
value: "password",
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const postCodeEvent = {
|
|
145
|
-
target: {
|
|
146
|
-
name: "post_code",
|
|
147
|
-
value: "post_code",
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const firstName = container.querySelector('input[name="first_name"]');
|
|
152
|
-
const lastName = container.querySelector('input[name="last_name"]');
|
|
153
|
-
const email = container.querySelector('input[name="email"]');
|
|
154
|
-
const password = container.querySelector('input[name="password"]');
|
|
155
|
-
const postCode = container.querySelector('input[name="post_code"]');
|
|
156
|
-
const submit = container.querySelector('button[type="submit"]');
|
|
157
|
-
|
|
158
|
-
fireEvent.input(firstName!, firstNameEvent);
|
|
159
|
-
fireEvent.input(lastName!, lastNameEvent);
|
|
160
|
-
fireEvent.input(email!, emailEvent);
|
|
161
|
-
fireEvent.input(password!, passwordEvent);
|
|
162
|
-
fireEvent.input(postCode!, postCodeEvent);
|
|
163
|
-
|
|
164
|
-
await act(async () => {
|
|
165
|
-
fireEvent.submit(submit!);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
expect(onSubmitMock).toHaveBeenCalledTimes(1);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/* eslint-disable testing-library/no-node-access */
|
|
2
|
-
/* eslint-disable testing-library/no-render-in-setup */
|
|
3
|
-
/* eslint-disable testing-library/no-unnecessary-act */
|
|
4
|
-
/* eslint-disable react/function-component-definition */
|
|
5
|
-
import React, { FunctionComponent } from "react";
|
|
6
|
-
import { FormProvider, useForm } from "react-hook-form";
|
|
7
|
-
import { render, fireEvent, act } from "@testing-library/react";
|
|
8
|
-
import { DashboardSettingFormFieldValues } from "../../../../src/setting/dashboard/DashboardSettingForm";
|
|
9
|
-
import {
|
|
10
|
-
IpInput,
|
|
11
|
-
parseIp,
|
|
12
|
-
} from "../../../../src/setting/dashboard/components/IpInput";
|
|
13
|
-
import useTranslationMock from "../../../__mock__/hooks/useTranslationMock";
|
|
14
|
-
|
|
15
|
-
const TestIpInput: FunctionComponent = () => {
|
|
16
|
-
const form = useForm<DashboardSettingFormFieldValues>();
|
|
17
|
-
return (
|
|
18
|
-
<FormProvider {...form}>
|
|
19
|
-
<IpInput onChange={() => {}} value="" />
|
|
20
|
-
</FormProvider>
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
jest.mock("react-i18next", () => ({
|
|
25
|
-
useTranslation: jest.fn(),
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
afterAll(() => {
|
|
29
|
-
jest.resetAllMocks();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
let element: HTMLElement;
|
|
33
|
-
beforeEach(async () => {
|
|
34
|
-
await act(async () => {
|
|
35
|
-
useTranslationMock();
|
|
36
|
-
const { container } = render(<TestIpInput />);
|
|
37
|
-
element = container;
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("IpInput", () => {
|
|
42
|
-
it("should switch focus on next input if ArrowRight key has been pressed", () => {
|
|
43
|
-
const inputs = element.getElementsByTagName("input");
|
|
44
|
-
const firstInput = inputs[0];
|
|
45
|
-
const secondInput = inputs[1];
|
|
46
|
-
act(() => {
|
|
47
|
-
fireEvent.keyDown(firstInput, { key: "ArrowRight" });
|
|
48
|
-
});
|
|
49
|
-
expect(secondInput).toHaveFocus();
|
|
50
|
-
});
|
|
51
|
-
it("should focus next input if 3 digits has been typed", () => {
|
|
52
|
-
const inputs = element.getElementsByTagName("input");
|
|
53
|
-
const firstInput = inputs[0];
|
|
54
|
-
const secondInput = inputs[1];
|
|
55
|
-
act(() => {
|
|
56
|
-
fireEvent.input(firstInput, { target: { value: "123" } });
|
|
57
|
-
});
|
|
58
|
-
expect(secondInput.focus).toBeTruthy();
|
|
59
|
-
});
|
|
60
|
-
it("should focus previous input if ArrowLeft key have been pressed", () => {
|
|
61
|
-
const inputs = element.getElementsByTagName("input");
|
|
62
|
-
const firstInput = inputs[0];
|
|
63
|
-
const secondInput = inputs[1];
|
|
64
|
-
act(() => {
|
|
65
|
-
fireEvent.keyDown(secondInput, { key: "ArrowLeft" });
|
|
66
|
-
});
|
|
67
|
-
expect(firstInput).toHaveFocus();
|
|
68
|
-
});
|
|
69
|
-
it("should focus previous input if Backspace key have been pressed and current input is empty", () => {
|
|
70
|
-
const inputs = element.getElementsByTagName("input");
|
|
71
|
-
const firstInput = inputs[0];
|
|
72
|
-
const secondInput = inputs[1];
|
|
73
|
-
act(() => {
|
|
74
|
-
fireEvent.keyDown(secondInput, { key: "Backspace" });
|
|
75
|
-
});
|
|
76
|
-
expect(firstInput).toHaveFocus();
|
|
77
|
-
});
|
|
78
|
-
it("should show error message if required filed has been skipped", () => {
|
|
79
|
-
const inputs = element.getElementsByTagName("input");
|
|
80
|
-
const errorDiv = element.querySelector(".invalid-feedback");
|
|
81
|
-
const firstInput = inputs[0];
|
|
82
|
-
const secondInput = inputs[1];
|
|
83
|
-
act(() => {
|
|
84
|
-
fireEvent.input(firstInput, { target: { value: "" } });
|
|
85
|
-
fireEvent.focus(secondInput);
|
|
86
|
-
});
|
|
87
|
-
expect(errorDiv).toBeVisible();
|
|
88
|
-
});
|
|
89
|
-
it("should show IP validation error if invalid value for IP field has been passed", () => {
|
|
90
|
-
const inputs = element.getElementsByTagName("input");
|
|
91
|
-
const errorDiv = element.querySelector(".invalid-feedback");
|
|
92
|
-
const firstInput = inputs[0];
|
|
93
|
-
act(() => {
|
|
94
|
-
fireEvent.input(firstInput, { target: { value: "256" } });
|
|
95
|
-
});
|
|
96
|
-
expect(errorDiv).toBeVisible();
|
|
97
|
-
});
|
|
98
|
-
it("should show Port validation error if invalid value for Port field has been passed", () => {
|
|
99
|
-
const inputs = element.getElementsByTagName("input");
|
|
100
|
-
const errorDiv = element.querySelector(".invalid-feedback");
|
|
101
|
-
const portInput = inputs[inputs.length - 1];
|
|
102
|
-
act(() => {
|
|
103
|
-
fireEvent.input(portInput, { target: { value: "999999" } });
|
|
104
|
-
});
|
|
105
|
-
expect(errorDiv).toBeVisible();
|
|
106
|
-
});
|
|
107
|
-
it("parseIp should return correct values", () => {
|
|
108
|
-
const correctIp = "192.158.1.38:2305";
|
|
109
|
-
const expectedOutput = ["192", "158", "1", "38", "2305"];
|
|
110
|
-
const output = parseIp(correctIp);
|
|
111
|
-
|
|
112
|
-
expect(output).toStrictEqual(expectedOutput);
|
|
113
|
-
});
|
|
114
|
-
it("Pasting data from the clipboard correctly", () => {
|
|
115
|
-
const inputs = element.getElementsByTagName("input");
|
|
116
|
-
const ip = "192.158.1.38:2305";
|
|
117
|
-
act(() => {
|
|
118
|
-
fireEvent.paste(inputs[0], {
|
|
119
|
-
clipboardData: {
|
|
120
|
-
getData: () => ip,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
expect(inputs[0].value).toBe("192");
|
|
125
|
-
expect(inputs[1].value).toBe("158");
|
|
126
|
-
expect(inputs[2].value).toBe("1");
|
|
127
|
-
expect(inputs[3].value).toBe("38");
|
|
128
|
-
expect(inputs[4].value).toBe("2305");
|
|
129
|
-
});
|
|
130
|
-
});
|