@licklist/design 0.58.6-dev.9 → 0.58.6

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.
Files changed (243) hide show
  1. package/bitbucket-pipelines.yml +8 -0
  2. package/dist/assets/iframe/calendar.svg +2 -2
  3. package/dist/assets/iframe/calendar.svg.js +1 -1
  4. package/dist/assets/iframe/ticket.svg +2 -2
  5. package/dist/assets/iframe/ticket.svg.js +1 -1
  6. package/dist/calendar/Calendar.d.ts +1 -1
  7. package/dist/calendar/Calendar.d.ts.map +1 -1
  8. package/dist/calendar/Calendar.js +1 -1
  9. package/dist/calendar/components/CalendarButtons/CalendarButtons.js +1 -1
  10. package/dist/calendar/components/CalendarDates/CalendarDates.d.ts +2 -2
  11. package/dist/calendar/components/CalendarDates/CalendarDates.d.ts.map +1 -1
  12. package/dist/calendar/components/CalendarDates/CalendarDates.js +1 -1
  13. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.js +1 -1
  14. package/dist/events/event-statistic-modal/EventStatisticModal.js +1 -1
  15. package/dist/iframe/event/event-card/IframeEventCard.d.ts +1 -2
  16. package/dist/iframe/event/event-card/IframeEventCard.d.ts.map +1 -1
  17. package/dist/iframe/event/event-card/IframeEventCard.js +1 -1
  18. package/dist/iframe/event/event-venue-map/IframeEventVenueMap.js +1 -1
  19. package/dist/iframe/order-process/components/BookingSummary/BookingSummary.d.ts +2 -2
  20. package/dist/iframe/order-process/components/BookingSummary/BookingSummary.d.ts.map +1 -1
  21. package/dist/iframe/order-process/components/BookingSummary/BookingSummary.js +1 -1
  22. package/dist/iframe/order-process/components/BookingSummary/components/BookingSummaryAccordion/BookingSummaryAccordion.d.ts +2 -4
  23. package/dist/iframe/order-process/components/BookingSummary/components/BookingSummaryAccordion/BookingSummaryAccordion.d.ts.map +1 -1
  24. package/dist/iframe/order-process/components/BookingSummary/components/BookingSummaryAccordion/BookingSummaryAccordion.js +1 -1
  25. package/dist/iframe/order-process/components/BookingSummary/components/SummaryTotal/components/SummaryTotalBlock.d.ts +1 -1
  26. package/dist/iframe/order-process/components/BookingSummary/components/SummaryTotal/components/SummaryTotalBlock.d.ts.map +1 -1
  27. package/dist/iframe/order-process/components/BookingSummary/components/SummaryTotal/components/SummaryTotalBlock.js +1 -1
  28. package/dist/iframe/order-process/components/BookingSummary/components/ToggleHeader/ToggleHeader.d.ts +2 -4
  29. package/dist/iframe/order-process/components/BookingSummary/components/ToggleHeader/ToggleHeader.d.ts.map +1 -1
  30. package/dist/iframe/order-process/components/BookingSummary/components/ToggleHeader/ToggleHeader.js +1 -1
  31. package/dist/iframe/order-process/components/BookingSummary/types/index.d.ts +0 -4
  32. package/dist/iframe/order-process/components/BookingSummary/types/index.d.ts.map +1 -1
  33. package/dist/iframe/order-process/components/CalendarStepsForm/CalendarStepsForm.js +1 -1
  34. package/dist/iframe/order-process/components/CategoryProduct/components/NumberInput/NumberInput.js +1 -1
  35. package/dist/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.d.ts.map +1 -1
  36. package/dist/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.js +1 -1
  37. package/dist/iframe/page/components/PageBody/constants.d.ts +0 -1
  38. package/dist/iframe/page/components/PageBody/constants.d.ts.map +1 -1
  39. package/dist/iframe/page/components/PageBody/constants.js +1 -1
  40. package/dist/iframe/page/components/PageBody/hooks/useResizePageBody.d.ts.map +1 -1
  41. package/dist/iframe/page/components/PageBody/hooks/useResizePageBody.js +1 -1
  42. package/dist/iframe/payment/order-items-table/OrderItemsTable.js +1 -1
  43. package/dist/iframe/payment/order-items-table/utils/paymentSummary.js +1 -1
  44. package/dist/iframe/payment/payment-form/PaymentForm.js +1 -1
  45. package/dist/iframe/payment/payment-page/PaymentPage.d.ts.map +1 -1
  46. package/dist/iframe/payment/payment-page/PaymentPage.js +1 -1
  47. package/dist/iframe/payment/payment-page/PaymentTimer.js +1 -1
  48. package/dist/iframe/payment/payment-status-page/PaymentStatusPage.js +1 -1
  49. package/dist/iframe/ryft/RyftPaymentForm.d.ts.map +1 -1
  50. package/dist/iframe/ryft/RyftPaymentForm.js +1 -1
  51. package/dist/index.js +1 -1
  52. package/dist/product-set/card/ProductSetCard.d.ts +1 -2
  53. package/dist/product-set/card/ProductSetCard.d.ts.map +1 -1
  54. package/dist/product-set/card/ProductSetCard.js +1 -1
  55. package/dist/product-set/control/ProductSetControl.d.ts +1 -2
  56. package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
  57. package/dist/product-set/control/ProductSetControl.js +1 -1
  58. package/dist/product-set/control/TutorialGifCard.d.ts +1 -2
  59. package/dist/product-set/control/TutorialGifCard.d.ts.map +1 -1
  60. package/dist/product-set/control/TutorialGifCard.js +1 -1
  61. package/dist/product-set/form/ProductCategoriesControl.d.ts +1 -2
  62. package/dist/product-set/form/ProductCategoriesControl.d.ts.map +1 -1
  63. package/dist/product-set/form/ProductCategoriesControl.js +1 -1
  64. package/dist/product-set/form/ProductSetForm.d.ts +2 -7
  65. package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
  66. package/dist/product-set/form/ProductSetForm.js +1 -1
  67. package/dist/product-set/form/ProductsControl.d.ts +1 -2
  68. package/dist/product-set/form/ProductsControl.d.ts.map +1 -1
  69. package/dist/product-set/form/ProductsControl.js +1 -1
  70. package/dist/product-set/form/StepsControl.d.ts +1 -2
  71. package/dist/product-set/form/StepsControl.d.ts.map +1 -1
  72. package/dist/product-set/form/StepsControl.js +1 -1
  73. package/dist/product-set/form/SubProductsControl.d.ts +1 -2
  74. package/dist/product-set/form/SubProductsControl.d.ts.map +1 -1
  75. package/dist/product-set/form/SubProductsControl.js +1 -1
  76. package/dist/product-set/form/VenueMapsControl.js +1 -1
  77. package/dist/product-set/hooks/useSortableTreeFunctions.d.ts +1 -2
  78. package/dist/product-set/hooks/useSortableTreeFunctions.d.ts.map +1 -1
  79. package/dist/product-set/hooks/useSortableTreeFunctions.js +1 -1
  80. package/dist/product-set/item/CreateProductSetItem.d.ts +1 -2
  81. package/dist/product-set/item/CreateProductSetItem.d.ts.map +1 -1
  82. package/dist/product-set/item/CreateProductSetItem.js +1 -1
  83. package/dist/product-set/product/ProductControl.d.ts +1 -3
  84. package/dist/product-set/product/ProductControl.d.ts.map +1 -1
  85. package/dist/product-set/product/ProductControl.js +1 -1
  86. package/dist/product-set/product/fixed-duration-fields/FixedDurationOptions.d.ts +2 -4
  87. package/dist/product-set/product/fixed-duration-fields/FixedDurationOptions.d.ts.map +1 -1
  88. package/dist/product-set/product/fixed-duration-fields/FixedDurationOptions.js +1 -1
  89. package/dist/product-set/product/quantity/ProductQuantityControl.d.ts +0 -1
  90. package/dist/product-set/product/quantity/ProductQuantityControl.d.ts.map +1 -1
  91. package/dist/product-set/product/quantity/ProductQuantityControl.js +1 -1
  92. package/dist/product-set/product-category/ProductCategoryControl.d.ts +1 -3
  93. package/dist/product-set/product-category/ProductCategoryControl.d.ts.map +1 -1
  94. package/dist/product-set/product-category/ProductCategoryControl.js +1 -1
  95. package/dist/provider/working-hours-input/WorkingHoursInputDescription.d.ts.map +1 -1
  96. package/dist/provider/working-hours-input/WorkingHoursInputDescription.js +1 -1
  97. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts +0 -2
  98. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts.map +1 -1
  99. package/dist/recurring-date-picker-input/RecurringDatePickerInput.js +1 -1
  100. package/dist/sales/booking/results/components/ResultCard.d.ts.map +1 -1
  101. package/dist/sales/booking/results/components/ResultCard.js +1 -1
  102. package/dist/sales/notes/NotesTableRow.js +1 -1
  103. package/dist/setting/dashboard/snippets/card/SnippetCard.js +1 -1
  104. package/dist/snippet/snippet-template/control/PropertyControl.d.ts +1 -3
  105. package/dist/snippet/snippet-template/control/PropertyControl.d.ts.map +1 -1
  106. package/dist/snippet/snippet-template/control/PropertyControl.js +1 -1
  107. package/dist/snippet/snippet-template/preview/Preview.js +1 -1
  108. package/dist/sortable-list/SortableList.d.ts +1 -2
  109. package/dist/sortable-list/SortableList.d.ts.map +1 -1
  110. package/dist/sortable-list/SortableList.js +1 -1
  111. package/dist/sortable-tree/SortableTreeItem.d.ts +1 -3
  112. package/dist/sortable-tree/SortableTreeItem.d.ts.map +1 -1
  113. package/dist/sortable-tree/SortableTreeItem.js +1 -1
  114. package/dist/static/manual-date-picker/ManualDatePicker.js +1 -1
  115. package/dist/static/manual-date-picker/constants/index.d.ts +1 -4
  116. package/dist/static/manual-date-picker/constants/index.d.ts.map +1 -1
  117. package/dist/static/manual-date-picker/constants/index.js +1 -1
  118. package/dist/static/manual-date-picker/utils/index.d.ts +0 -4
  119. package/dist/static/manual-date-picker/utils/index.d.ts.map +1 -1
  120. package/dist/static/manual-date-picker/utils/index.js +1 -1
  121. package/dist/striped-static-table/StripedStaticTable.js +1 -1
  122. package/dist/styles/iframe-events/Card.scss +8 -24
  123. package/dist/styles/iframe-events/PoweredBy.scss +2 -2
  124. package/dist/styles/iframe-order-process/IframeOrderProcess.scss +20 -57
  125. package/dist/styles/iframe-page/Page.scss +0 -1
  126. package/dist/styles/iframe-page/PageBody.scss +12 -34
  127. package/dist/styles/iframe-page/PageHeader.scss +39 -41
  128. package/dist/styles/product-set/EditVenueMapSetModal.scss +1 -1
  129. package/dist/styles/ryft-payment-form/RyftPaymentForm.scss +2 -125
  130. package/dist/styles/sales/BookingResults.scss +1 -1
  131. package/dist/venue-map-sets/form/components/VenueMapImageControl.js +1 -1
  132. package/jest.config.js +29 -0
  133. package/package.json +35 -10
  134. package/src/assets/iframe/calendar.svg +2 -2
  135. package/src/assets/iframe/ticket.svg +2 -2
  136. package/src/calendar/Calendar.stories.tsx +0 -23
  137. package/src/calendar/Calendar.tsx +5 -5
  138. package/src/calendar/components/CalendarDates/CalendarDates.tsx +5 -0
  139. package/src/iframe/event/event-card/IframeEventCard.stories.tsx +0 -1
  140. package/src/iframe/event/event-card/IframeEventCard.tsx +8 -7
  141. package/src/iframe/order-process/components/BookingSummary/BookingSummary.stories.tsx +0 -9
  142. package/src/iframe/order-process/components/BookingSummary/BookingSummary.tsx +7 -58
  143. package/src/iframe/order-process/components/BookingSummary/components/BookingSummaryAccordion/BookingSummaryAccordion.tsx +0 -8
  144. package/src/iframe/order-process/components/BookingSummary/components/SummaryTotal/components/SummaryTotalBlock.tsx +4 -4
  145. package/src/iframe/order-process/components/BookingSummary/components/ToggleHeader/ToggleHeader.tsx +10 -63
  146. package/src/iframe/order-process/components/BookingSummary/types/index.ts +0 -4
  147. package/src/iframe/order-process/components/CategoryProduct/components/NumberInput/NumberInput.tsx +1 -1
  148. package/src/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.tsx +1 -3
  149. package/src/iframe/page/components/PageBody/constants.ts +0 -2
  150. package/src/iframe/page/components/PageBody/hooks/useResizePageBody.ts +0 -10
  151. package/src/iframe/payment/order-items-table/utils/paymentSummary.tsx +6 -6
  152. package/src/iframe/payment/payment-page/PaymentPage.stories.tsx +6 -546
  153. package/src/iframe/payment/payment-page/PaymentPage.tsx +29 -38
  154. package/src/iframe/ryft/RyftPaymentForm.tsx +5 -11
  155. package/src/product-set/card/ProductSetCard.tsx +1 -12
  156. package/src/product-set/control/ProductSetControl.tsx +24 -46
  157. package/src/product-set/control/TutorialGifCard.tsx +3 -11
  158. package/src/product-set/form/ProductCategoriesControl.tsx +1 -12
  159. package/src/product-set/form/ProductSetForm.tsx +1 -10
  160. package/src/product-set/form/ProductsControl.tsx +0 -10
  161. package/src/product-set/form/StepsControl.tsx +2 -8
  162. package/src/product-set/form/SubProductsControl.tsx +0 -3
  163. package/src/product-set/hooks/useSortableTreeFunctions.ts +0 -6
  164. package/src/product-set/item/CreateProductSetItem.tsx +0 -3
  165. package/src/product-set/product/ProductControl.tsx +15 -48
  166. package/src/product-set/product/fixed-duration-fields/FixedDurationOptions.tsx +2 -8
  167. package/src/product-set/product/quantity/ProductQuantityControl.tsx +3 -4
  168. package/src/product-set/product-category/ProductCategoryControl.tsx +50 -116
  169. package/src/provider/working-hours-input/WorkingHoursInputDescription.tsx +18 -4
  170. package/src/recurring-date-picker-input/RecurringDatePickerInput.tsx +1 -4
  171. package/src/sales/booking/results/BookingResults.stories.tsx +2 -3
  172. package/src/sales/booking/results/components/ResultCard.tsx +5 -2
  173. package/src/snippet/snippet-template/control/PropertyControl.tsx +2 -6
  174. package/src/sortable-list/SortableList.tsx +0 -3
  175. package/src/sortable-tree/SortableTreeItem.tsx +0 -6
  176. package/src/static/manual-date-picker/ManualDatePicker.tsx +3 -3
  177. package/src/static/manual-date-picker/constants/index.ts +2 -6
  178. package/src/static/manual-date-picker/utils/index.ts +0 -11
  179. package/src/static/switch/BooleanSwitch.tsx +1 -1
  180. package/src/styles/iframe-events/Card.scss +8 -24
  181. package/src/styles/iframe-events/PoweredBy.scss +2 -2
  182. package/src/styles/iframe-order-process/IframeOrderProcess.scss +20 -57
  183. package/src/styles/iframe-page/Page.scss +0 -1
  184. package/src/styles/iframe-page/PageBody.scss +12 -34
  185. package/src/styles/iframe-page/PageHeader.scss +39 -41
  186. package/src/styles/product-set/EditVenueMapSetModal.scss +1 -1
  187. package/src/styles/ryft-payment-form/RyftPaymentForm.scss +2 -125
  188. package/src/styles/sales/BookingResults.scss +1 -1
  189. package/tests/Auth/Authorizer.test.tsx +194 -0
  190. package/tests/Auth/Layout/UserNavDropDown.test.tsx +43 -0
  191. package/tests/Auth/Layout/UserNavDropDownToggle.test.tsx +33 -0
  192. package/tests/Auth/Login/LoginComponent.test.tsx +246 -0
  193. package/tests/Auth/Login/LoginFormComponent.test.tsx +182 -0
  194. package/tests/Auth/Register/RegisterComponent.test.tsx +285 -0
  195. package/tests/Auth/Register/RegisterFormComponent.test.tsx +170 -0
  196. package/tests/Auth/Settings/Dashboard/IpInput.test.tsx +130 -0
  197. package/tests/Auth/Social/SocialCallbackComponent.test.tsx +133 -0
  198. package/tests/Auth/Social/SocialFormComponent.test.tsx +118 -0
  199. package/tests/FileUpload/FileUpload.test.tsx +42 -0
  200. package/tests/Notification/EmailTemplate.test.tsx +82 -0
  201. package/tests/ProductSet/ProductSetPopover.test.tsx +40 -0
  202. package/tests/Report/Report.test.tsx +48 -0
  203. package/tests/Sales/Coupon.test.tsx +51 -0
  204. package/tests/Sales/SalesAndVIews.test.tsx +63 -0
  205. package/tests/SnippetTemplates/SnippetTemplates.test.tsx +56 -0
  206. package/tests/Table/FilterHelperComponent.test.tsx +88 -0
  207. package/tests/Table/PaginationHelperComponent.test.tsx +109 -0
  208. package/tests/Table/PerPageHelperComponent.test.tsx +34 -0
  209. package/tests/Table/TableHelperComponent.test.tsx +295 -0
  210. package/tests/TipTapEditor/TipTapEditor.test.tsx +28 -0
  211. package/tests/__mock__/hooks/useAuthApi.ts +13 -0
  212. package/tests/__mock__/hooks/useAuthMock.ts +13 -0
  213. package/tests/__mock__/hooks/useFormMock.ts +27 -0
  214. package/tests/__mock__/hooks/useNotificationMock.ts +13 -0
  215. package/tests/__mock__/hooks/useQueryMock.ts +16 -0
  216. package/tests/__mock__/hooks/useSocialApiMock.ts +20 -0
  217. package/tests/__mock__/hooks/useTranslationMock.ts +17 -0
  218. package/tests/__mock__/hooks/useUserApiMock.ts +18 -0
  219. package/tests/__mock__/hooks/useUserMock.ts +13 -0
  220. package/tests/__mock__/styleMock.js +1 -0
  221. package/tests/__mock__/windowMock.ts +5 -0
  222. package/tests/packages/react-query.tsx +28 -0
  223. package/tests/setupTests.ts +10 -0
  224. package/dist/iframe/ryft/utils/ryft-form.d.ts +0 -5
  225. package/dist/iframe/ryft/utils/ryft-form.d.ts.map +0 -1
  226. package/dist/iframe/ryft/utils/ryft-form.js +0 -1
  227. package/dist/product-set/control/DateInput.d.ts +0 -17
  228. package/dist/product-set/control/DateInput.d.ts.map +0 -1
  229. package/dist/product-set/control/DateInput.js +0 -1
  230. package/dist/product-set/control/ProductSetRecurrenceOverridesControl.d.ts +0 -11
  231. package/dist/product-set/control/ProductSetRecurrenceOverridesControl.d.ts.map +0 -1
  232. package/dist/product-set/control/ProductSetRecurrenceOverridesControl.js +0 -1
  233. package/dist/recurring-date-picker-input/DatePickerInput.d.ts +0 -19
  234. package/dist/recurring-date-picker-input/DatePickerInput.d.ts.map +0 -1
  235. package/dist/recurring-date-picker-input/DatePickerInput.js +0 -1
  236. package/dist/recurring-date-picker-input/RecurrenceAndFrequencyInput.d.ts +0 -15
  237. package/dist/recurring-date-picker-input/RecurrenceAndFrequencyInput.d.ts.map +0 -1
  238. package/dist/recurring-date-picker-input/RecurrenceAndFrequencyInput.js +0 -1
  239. package/src/iframe/ryft/utils/ryft-form.ts +0 -47
  240. package/src/product-set/control/DateInput.tsx +0 -313
  241. package/src/product-set/control/ProductSetRecurrenceOverridesControl.tsx +0 -63
  242. package/src/recurring-date-picker-input/DatePickerInput.tsx +0 -93
  243. package/src/recurring-date-picker-input/RecurrenceAndFrequencyInput.tsx +0 -136
@@ -0,0 +1,182 @@
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 { LoginFormComponent } from "../../../src/auth/Login/LoginFormComponent";
9
+ import useFormMock from "../../__mock__/hooks/useFormMock";
10
+ import useTranslationMock from "../../__mock__/hooks/useTranslationMock";
11
+
12
+ jest.mock("react-i18next", () => ({
13
+ Trans: jest.fn().mockReturnValue("test"),
14
+ useTranslation: jest.fn(),
15
+ }));
16
+ jest.mock("react-hook-form");
17
+ jest.mock("@licklist/plugins/dist/context/app/hooks/useNotification");
18
+
19
+ beforeEach(() => {
20
+ useTranslationMock();
21
+ useFormMock();
22
+ });
23
+
24
+ afterAll(() => {
25
+ jest.resetAllMocks();
26
+ });
27
+
28
+ describe("LoginFormComponent", () => {
29
+ it("should be rendered without issues", () => {
30
+ const component = shallow(
31
+ <LoginFormComponent
32
+ isLoading={false}
33
+ setIsLoading={() => false}
34
+ invitation={null}
35
+ />
36
+ );
37
+
38
+ expect(component.exists()).toBeTruthy();
39
+ });
40
+
41
+ it("should be disabled if it is loading", () => {
42
+ const component = mount(
43
+ <LoginFormComponent
44
+ isLoading
45
+ setIsLoading={() => false}
46
+ invitation={null}
47
+ />
48
+ );
49
+
50
+ expect(component.exists()).toBeTruthy();
51
+ expect(
52
+ component.find({ name: "email" }).at(0).prop("disabled")
53
+ ).toBeTruthy();
54
+ expect(
55
+ component.find({ name: "password" }).at(0).prop("disabled")
56
+ ).toBeTruthy();
57
+ });
58
+
59
+ it("should be disabled if invitation exist", () => {
60
+ const component = mount(
61
+ <LoginFormComponent
62
+ isLoading={false}
63
+ setIsLoading={() => false}
64
+ invitation={{
65
+ email: "test@test.test",
66
+ user_exists: false,
67
+ invitation_hash: "test",
68
+ }}
69
+ />
70
+ );
71
+
72
+ expect(component.exists()).toBeTruthy();
73
+ expect(
74
+ component.find({ name: "email" }).at(0).prop("disabled")
75
+ ).toBeTruthy();
76
+ expect(
77
+ component.find({ name: "password" }).at(0).prop("disabled")
78
+ ).toBeFalsy();
79
+ });
80
+
81
+ it("should set value on input change", () => {
82
+ const setValueMock = jest.fn();
83
+
84
+ useFormMock({
85
+ setValue: setValueMock,
86
+ });
87
+
88
+ const component = mount(
89
+ <LoginFormComponent
90
+ isLoading={false}
91
+ setIsLoading={() => false}
92
+ invitation={null}
93
+ />
94
+ );
95
+
96
+ const emailEvent = {
97
+ currentTarget: {
98
+ name: "email",
99
+ value: "test",
100
+ },
101
+ };
102
+
103
+ const passwordEvent = {
104
+ currentTarget: {
105
+ name: "password",
106
+ value: "test",
107
+ },
108
+ };
109
+
110
+ act(() => {
111
+ component.find({ name: "email" }).at(1).prop("onChange")(emailEvent);
112
+ });
113
+
114
+ expect(setValueMock).toHaveBeenCalledTimes(1);
115
+ expect(setValueMock).toHaveBeenCalledWith(
116
+ emailEvent.currentTarget.name,
117
+ emailEvent.currentTarget.value
118
+ );
119
+
120
+ act(() => {
121
+ component.find({ name: "password" }).at(1).prop("onChange")(
122
+ passwordEvent
123
+ );
124
+ });
125
+
126
+ expect(setValueMock).toHaveBeenCalledTimes(2);
127
+ expect(setValueMock).toHaveBeenLastCalledWith(
128
+ passwordEvent.currentTarget.name,
129
+ passwordEvent.currentTarget.value
130
+ );
131
+ });
132
+
133
+ it("should handle submit action", async () => {
134
+ const onSubmitMock = jest.fn();
135
+ const handleSubmitMock = jest
136
+ .fn()
137
+ .mockImplementation(
138
+ (callback: (e: any) => void) => (e: any) => callback(e)
139
+ );
140
+
141
+ useFormMock({
142
+ handleSubmit: handleSubmitMock,
143
+ });
144
+
145
+ const { container } = render(
146
+ <LoginFormComponent
147
+ isLoading={false}
148
+ setIsLoading={() => false}
149
+ onSubmit={onSubmitMock}
150
+ invitation={null}
151
+ />
152
+ );
153
+
154
+ const emailEvent = {
155
+ currentTarget: {
156
+ name: "email",
157
+ value: "email",
158
+ },
159
+ };
160
+
161
+ const passwordEvent = {
162
+ currentTarget: {
163
+ name: "password",
164
+ value: "password",
165
+ },
166
+ };
167
+
168
+ const email = container.querySelector('input[name="email"]');
169
+ const password = container.querySelector('input[name="password"]');
170
+ const submit = container.querySelector('button[type="submit"]');
171
+
172
+ fireEvent.input(email!, emailEvent);
173
+ fireEvent.input(password!, passwordEvent);
174
+
175
+ await act(async () => {
176
+ fireEvent.submit(submit!);
177
+ });
178
+
179
+ expect(handleSubmitMock).toHaveBeenCalledTimes(1);
180
+ expect(onSubmitMock).toHaveBeenCalledTimes(1);
181
+ });
182
+ });
@@ -0,0 +1,285 @@
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
+ });
@@ -0,0 +1,170 @@
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
+ });