@licklist/design 0.63.0 → 0.63.1-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.
Files changed (163) hide show
  1. package/bitbucket-pipelines.yml +0 -8
  2. package/dist/date-time-button/DateTimeButton.js +1 -1
  3. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts +3 -1
  4. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts.map +1 -1
  5. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.js +1 -1
  6. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts +3 -1
  7. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts.map +1 -1
  8. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.js +1 -1
  9. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts +3 -1
  10. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts.map +1 -1
  11. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.js +1 -1
  12. package/dist/iframe/payment/order-items-table/utils/paymentSummary.js +1 -1
  13. package/dist/product-set/control/DateAndRecurrenceInput.d.ts +1 -5
  14. package/dist/product-set/control/DateAndRecurrenceInput.d.ts.map +1 -1
  15. package/dist/product-set/control/DateAndRecurrenceInput.js +1 -1
  16. package/dist/product-set/control/DateInput.d.ts.map +1 -1
  17. package/dist/product-set/control/DateInput.js +1 -1
  18. package/dist/product-set/control/ProductSetControl.d.ts +4 -3
  19. package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
  20. package/dist/product-set/control/ProductSetControl.js +1 -1
  21. package/dist/product-set/control/utils.d.ts +5 -0
  22. package/dist/product-set/control/utils.d.ts.map +1 -0
  23. package/dist/product-set/control/utils.js +1 -0
  24. package/dist/product-set/form/ProductCategoriesControl.d.ts +2 -1
  25. package/dist/product-set/form/ProductCategoriesControl.d.ts.map +1 -1
  26. package/dist/product-set/form/ProductCategoriesControl.js +1 -1
  27. package/dist/product-set/form/ProductSetForm.d.ts +4 -1
  28. package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
  29. package/dist/product-set/form/ProductsControl.d.ts +2 -1
  30. package/dist/product-set/form/ProductsControl.d.ts.map +1 -1
  31. package/dist/product-set/form/ProductsControl.js +1 -1
  32. package/dist/product-set/form/StepsControl.d.ts +2 -1
  33. package/dist/product-set/form/StepsControl.d.ts.map +1 -1
  34. package/dist/product-set/form/StepsControl.js +1 -1
  35. package/dist/product-set/hooks/useSortableTreeFunctions.d.ts.map +1 -1
  36. package/dist/product-set/product/ProductControl.d.ts +1 -0
  37. package/dist/product-set/product/ProductControl.d.ts.map +1 -1
  38. package/dist/product-set/product/ProductControl.js +1 -1
  39. package/dist/product-set/product/fixed-duration-fields/FixedDurationOptions.d.ts.map +1 -1
  40. package/dist/product-set/step/StepControl.d.ts +2 -1
  41. package/dist/product-set/step/StepControl.d.ts.map +1 -1
  42. package/dist/product-set/step/StepControl.js +1 -1
  43. package/dist/provider/working-hours-input/WorkingHoursInputDescription.d.ts.map +1 -1
  44. package/dist/provider/working-hours-input/WorkingHoursInputDescription.js +1 -1
  45. package/dist/recurring-date-picker-input/RecurrenceAndFrequencyInput.d.ts.map +1 -1
  46. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts +3 -1
  47. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts.map +1 -1
  48. package/dist/recurring-date-picker-input/RecurringDatePickerInput.js +1 -1
  49. package/dist/recurring-date-picker-input/utils.d.ts +6 -0
  50. package/dist/recurring-date-picker-input/utils.d.ts.map +1 -1
  51. package/dist/recurring-date-picker-input/utils.js +1 -1
  52. package/dist/sales/booking/results/components/ResultCard.d.ts.map +1 -1
  53. package/dist/sales/booking/results/components/ResultCard.js +1 -1
  54. package/dist/sales/coupon/control/CouponFormControl.d.ts +2 -1
  55. package/dist/sales/coupon/control/CouponFormControl.d.ts.map +1 -1
  56. package/dist/sales/coupon/control/CouponFormControl.js +1 -1
  57. package/dist/sales/coupon/form/CouponFrom.d.ts +2 -2
  58. package/dist/sales/coupon/form/CouponFrom.d.ts.map +1 -1
  59. package/dist/sales/coupon/utils/index.d.ts +7 -0
  60. package/dist/sales/coupon/utils/index.d.ts.map +1 -0
  61. package/dist/sales/coupon/utils/index.js +1 -0
  62. package/dist/setting/admin/AdminSettingForm.d.ts +2 -2
  63. package/dist/setting/admin/AdminSettingForm.d.ts.map +1 -1
  64. package/dist/setting/dashboard/DashboardSettingForm.d.ts +1 -0
  65. package/dist/setting/dashboard/DashboardSettingForm.d.ts.map +1 -1
  66. package/dist/setting/dashboard/DashboardSettingForm.js +1 -1
  67. package/dist/sortable-tree/SortableTreeItem.d.ts +1 -2
  68. package/dist/sortable-tree/SortableTreeItem.d.ts.map +1 -1
  69. package/dist/sortable-tree/SortableTreeItem.js +1 -1
  70. package/dist/styles/sales/BookingResults.scss +1 -1
  71. package/dist/typeahead/Typeahead.d.ts +2 -1
  72. package/dist/typeahead/Typeahead.d.ts.map +1 -1
  73. package/dist/typeahead/Typeahead.js +1 -1
  74. package/dist/zone/form/ZoneForm.d.ts +2 -2
  75. package/dist/zone/form/ZoneForm.d.ts.map +1 -1
  76. package/dist/zone/form/ZoneForm.js +1 -1
  77. package/dist/zone/form/components/AvailableTimesControl.d.ts +0 -2
  78. package/dist/zone/form/components/AvailableTimesControl.d.ts.map +1 -1
  79. package/dist/zone/form/components/ZoneControl.d.ts +2 -2
  80. package/dist/zone/form/components/ZoneControl.d.ts.map +1 -1
  81. package/dist/zone/form/components/ZoneControl.js +1 -1
  82. package/dist/zone/form/components/ZoneRecurrencesControl.d.ts +4 -4
  83. package/dist/zone/form/components/ZoneRecurrencesControl.d.ts.map +1 -1
  84. package/dist/zone/form/components/ZoneRecurrencesControl.js +1 -1
  85. package/dist/zone/form/utils/dates.d.ts.map +1 -1
  86. package/package.json +10 -35
  87. package/src/date-time-button/DateTimeButton.stories.tsx +2 -1
  88. package/src/date-time-button/DateTimeButton.tsx +7 -5
  89. package/src/events/edit-event-modal/component/EditEventForm/EditEventForm.tsx +4 -0
  90. package/src/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.tsx +18 -9
  91. package/src/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.tsx +5 -0
  92. package/src/iframe/payment/order-items-table/utils/paymentSummary.tsx +6 -6
  93. package/src/product-set/control/DateAndRecurrenceInput.tsx +48 -14
  94. package/src/product-set/control/DateInput.tsx +2 -4
  95. package/src/product-set/control/ProductSetControl.stories.tsx +1 -1
  96. package/src/product-set/control/ProductSetControl.tsx +12 -11
  97. package/src/product-set/control/utils.ts +25 -0
  98. package/src/product-set/form/ProductCategoriesControl.tsx +8 -4
  99. package/src/product-set/form/ProductSetForm.stories.tsx +1 -2
  100. package/src/product-set/form/ProductSetForm.tsx +5 -1
  101. package/src/product-set/form/ProductsControl.tsx +87 -77
  102. package/src/product-set/form/StepsControl.tsx +11 -6
  103. package/src/product-set/hooks/useSortableTreeFunctions.ts +2 -0
  104. package/src/product-set/product/ProductControl.tsx +39 -39
  105. package/src/product-set/product/fixed-duration-fields/FixedDurationOptions.tsx +0 -2
  106. package/src/product-set/step/StepControl.tsx +4 -3
  107. package/src/provider/working-hours-input/WorkingHoursInputDescription.tsx +4 -18
  108. package/src/recurring-date-picker-input/RecurrenceAndFrequencyInput.tsx +0 -1
  109. package/src/recurring-date-picker-input/RecurringDatePickerInput.stories.tsx +13 -7
  110. package/src/recurring-date-picker-input/RecurringDatePickerInput.tsx +12 -1
  111. package/src/recurring-date-picker-input/utils.ts +82 -1
  112. package/src/sales/booking/results/BookingResults.stories.tsx +3 -2
  113. package/src/sales/booking/results/components/ResultCard.tsx +2 -5
  114. package/src/sales/coupon/control/CouponFormControl.tsx +28 -51
  115. package/src/sales/coupon/form/CouponFrom.tsx +5 -15
  116. package/src/sales/coupon/utils/index.ts +13 -0
  117. package/src/setting/admin/AdminSettingForm.tsx +2 -2
  118. package/src/setting/dashboard/DashboardSettingForm.tsx +13 -0
  119. package/src/sortable-tree/SortableTreeItem.tsx +1 -4
  120. package/src/static/switch/BooleanSwitch.tsx +1 -1
  121. package/src/styles/sales/BookingResults.scss +1 -1
  122. package/src/typeahead/Typeahead.tsx +16 -3
  123. package/src/zone/form/ZoneForm.tsx +3 -2
  124. package/src/zone/form/components/AvailableTimesControl.tsx +0 -2
  125. package/src/zone/form/components/ZoneControl.tsx +3 -3
  126. package/src/zone/form/components/ZoneRecurrencesControl.tsx +7 -5
  127. package/src/zone/form/utils/dates.ts +9 -10
  128. package/jest.config.js +0 -29
  129. package/tests/Auth/Authorizer.test.tsx +0 -194
  130. package/tests/Auth/Layout/UserNavDropDown.test.tsx +0 -43
  131. package/tests/Auth/Layout/UserNavDropDownToggle.test.tsx +0 -33
  132. package/tests/Auth/Login/LoginComponent.test.tsx +0 -246
  133. package/tests/Auth/Login/LoginFormComponent.test.tsx +0 -182
  134. package/tests/Auth/Register/RegisterComponent.test.tsx +0 -285
  135. package/tests/Auth/Register/RegisterFormComponent.test.tsx +0 -170
  136. package/tests/Auth/Settings/Dashboard/IpInput.test.tsx +0 -130
  137. package/tests/Auth/Social/SocialCallbackComponent.test.tsx +0 -133
  138. package/tests/Auth/Social/SocialFormComponent.test.tsx +0 -118
  139. package/tests/FileUpload/FileUpload.test.tsx +0 -42
  140. package/tests/Notification/EmailTemplate.test.tsx +0 -82
  141. package/tests/ProductSet/ProductSetPopover.test.tsx +0 -40
  142. package/tests/Report/Report.test.tsx +0 -48
  143. package/tests/Sales/Coupon.test.tsx +0 -51
  144. package/tests/Sales/SalesAndVIews.test.tsx +0 -63
  145. package/tests/SnippetTemplates/SnippetTemplates.test.tsx +0 -56
  146. package/tests/Table/FilterHelperComponent.test.tsx +0 -88
  147. package/tests/Table/PaginationHelperComponent.test.tsx +0 -109
  148. package/tests/Table/PerPageHelperComponent.test.tsx +0 -34
  149. package/tests/Table/TableHelperComponent.test.tsx +0 -295
  150. package/tests/TipTapEditor/TipTapEditor.test.tsx +0 -28
  151. package/tests/__mock__/hooks/useAuthApi.ts +0 -13
  152. package/tests/__mock__/hooks/useAuthMock.ts +0 -13
  153. package/tests/__mock__/hooks/useFormMock.ts +0 -27
  154. package/tests/__mock__/hooks/useNotificationMock.ts +0 -13
  155. package/tests/__mock__/hooks/useQueryMock.ts +0 -16
  156. package/tests/__mock__/hooks/useSocialApiMock.ts +0 -20
  157. package/tests/__mock__/hooks/useTranslationMock.ts +0 -17
  158. package/tests/__mock__/hooks/useUserApiMock.ts +0 -18
  159. package/tests/__mock__/hooks/useUserMock.ts +0 -13
  160. package/tests/__mock__/styleMock.js +0 -1
  161. package/tests/__mock__/windowMock.ts +0 -5
  162. package/tests/packages/react-query.tsx +0 -28
  163. package/tests/setupTests.ts +0 -10
@@ -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
- });
@@ -1,133 +0,0 @@
1
- import RouteService from "@licklist/plugins/dist/services/Route/RouteService";
2
- import { mount, shallow } from "enzyme";
3
- import * as React from "react";
4
- import { SocialCallbackComponent } from "../../../src/auth/Social/SocialCallbackComponent";
5
- import useAuthMock from "../../__mock__/hooks/useAuthMock";
6
- import useNotificationMock from "../../__mock__/hooks/useNotificationMock";
7
- import useQueryMock from "../../__mock__/hooks/useQueryMock";
8
- import useSocialApiMock from "../../__mock__/hooks/useSocialApiMock";
9
- import useTranslationMock from "../../__mock__/hooks/useTranslationMock";
10
- import useUserApiMock from "../../__mock__/hooks/useUserApiMock";
11
- import useUserMock from "../../__mock__/hooks/useUserMock";
12
-
13
- jest.mock("react-i18next", () => ({
14
- Trans: jest.fn().mockReturnValue("test"),
15
- useTranslation: jest.fn(),
16
- }));
17
- jest.mock("react-router-dom", () => ({
18
- useParams: () => ({
19
- provider: "facebook",
20
- }),
21
- }));
22
- jest.mock("@licklist/plugins/dist/context/app/hooks/useNotification");
23
- jest.mock("@licklist/plugins/dist/context/user/hooks/useAuth");
24
- jest.mock("@licklist/plugins/dist/context/user/hooks/useUser");
25
- jest.mock("@licklist/plugins/dist/hooks/Api/useSocialApi");
26
- jest.mock("@licklist/plugins/dist/hooks/Api/useUserApi");
27
- jest.mock("@licklist/plugins/dist/hooks/Query/useQuery");
28
-
29
- beforeEach(() => {
30
- useQueryMock();
31
- useTranslationMock();
32
- useNotificationMock({
33
- danger: jest.fn(),
34
- success: jest.fn(),
35
- });
36
- useAuthMock({
37
- setSecrets: jest.fn(),
38
- });
39
- useUserMock({
40
- login: jest.fn(),
41
- });
42
- });
43
-
44
- afterAll(() => {
45
- jest.resetAllMocks();
46
- });
47
-
48
- describe("SocialCallbackComponent", () => {
49
- it("should be rendered without issues", () => {
50
- const component = shallow(<SocialCallbackComponent />);
51
-
52
- expect(component.exists()).toBeTruthy();
53
- });
54
-
55
- it("should fail on facebook callback", async () => {
56
- const getSocialProviderMock = jest.fn().mockReturnValue("facebook");
57
- const registerCallbackMock = jest
58
- .fn()
59
- .mockReturnValue(Promise.reject(new Error("test")));
60
- const notificationDangerMock = jest.fn();
61
- const notificationSuccessMock = jest.fn();
62
-
63
- useNotificationMock({
64
- danger: notificationDangerMock,
65
- success: notificationSuccessMock,
66
- });
67
-
68
- useSocialApiMock({
69
- getSocialProvider: getSocialProviderMock,
70
- registerCallback: registerCallbackMock,
71
- });
72
-
73
- mount(<SocialCallbackComponent />);
74
-
75
- expect(getSocialProviderMock).toHaveBeenCalledTimes(1);
76
- expect(registerCallbackMock).toHaveBeenCalledTimes(1);
77
- expect(notificationSuccessMock).toHaveBeenCalledTimes(0);
78
- });
79
-
80
- it("should succeed on facebook callback", async () => {
81
- const authResponse = {
82
- access_token: "access_token",
83
- refresh_token: "refresh_token",
84
- token_type: "token_type",
85
- expires_in: null,
86
- };
87
- const profileResponse = {
88
- id: 1,
89
- first_name: "first_name",
90
- last_name: "last_name",
91
- email: "email",
92
- role: null,
93
- };
94
-
95
- const getSocialProviderMock = jest.fn().mockReturnValue("facebook");
96
- const registerCallbackMock = jest
97
- .fn()
98
- .mockReturnValue(Promise.resolve(authResponse));
99
- const notificationDangerMock = jest.fn();
100
- const notificationSuccessMock = jest.fn();
101
- const profileMock = jest.fn(() =>
102
- Promise.resolve({
103
- error: false,
104
- message: profileResponse,
105
- })
106
- );
107
- const setAuthorizationTokenMock = jest.fn();
108
- const setSecretsMock = jest.fn();
109
-
110
- RouteService.redirectTo = jest.fn();
111
-
112
- useNotificationMock({
113
- danger: notificationDangerMock,
114
- success: notificationSuccessMock,
115
- });
116
- useSocialApiMock({
117
- getSocialProvider: getSocialProviderMock,
118
- registerCallback: registerCallbackMock,
119
- });
120
- useUserApiMock({
121
- profile: profileMock,
122
- setAuthorizationToken: setAuthorizationTokenMock,
123
- });
124
- useAuthMock({
125
- setSecrets: setSecretsMock,
126
- });
127
-
128
- mount(<SocialCallbackComponent />);
129
-
130
- expect(getSocialProviderMock).toHaveBeenCalledTimes(1);
131
- expect(registerCallbackMock).toHaveBeenCalledTimes(1);
132
- });
133
- });
@@ -1,118 +0,0 @@
1
- import RouteService from "@licklist/plugins/dist/services/Route/RouteService";
2
- import { mount, shallow } from "enzyme";
3
- import * as React from "react";
4
- import { act } from "react-dom/test-utils";
5
- import { SocialFormComponent } from "../../../src/auth/Social/SocialFormComponent";
6
- import useNotificationMock from "../../__mock__/hooks/useNotificationMock";
7
- import useSocialApiMock from "../../__mock__/hooks/useSocialApiMock";
8
- import useTranslationMock from "../../__mock__/hooks/useTranslationMock";
9
-
10
- jest.mock("react-i18next", () => ({
11
- Trans: jest.fn().mockReturnValue("test"),
12
- useTranslation: jest.fn(),
13
- }));
14
- jest.mock("@licklist/plugins/dist/context/app/hooks/useNotification");
15
- jest.mock("@licklist/plugins/dist/hooks/Api/useSocialApi");
16
-
17
- beforeEach(() => {
18
- useTranslationMock();
19
- useNotificationMock({
20
- danger: jest.fn(),
21
- success: jest.fn(),
22
- });
23
- });
24
-
25
- afterAll(() => {
26
- jest.resetAllMocks();
27
- });
28
-
29
- describe("SocialFormComponent", () => {
30
- it("should be rendered without issues", () => {
31
- const component = shallow(
32
- <SocialFormComponent isLoading={false} setIsLoading={() => false} />
33
- );
34
-
35
- expect(component.exists()).toBeTruthy();
36
- });
37
-
38
- it("should be disabled if it is loading", () => {
39
- const component = mount(
40
- <SocialFormComponent isLoading setIsLoading={() => false} />
41
- );
42
-
43
- expect(component.exists()).toBeTruthy();
44
- expect(component.find("SocialButton").at(0).prop("disabled")).toBeTruthy();
45
- expect(component.find("SocialButton").at(1).prop("disabled")).toBeTruthy();
46
- });
47
-
48
- it("should fail on facebook click action", async () => {
49
- const redirectToProviderMock = jest
50
- .fn()
51
- .mockReturnValue(Promise.reject(new Error("test")));
52
- const notificationDangerMock = jest.fn();
53
- const notificationSuccessMock = jest.fn();
54
-
55
- useNotificationMock({
56
- danger: notificationDangerMock,
57
- success: notificationSuccessMock,
58
- });
59
-
60
- useSocialApiMock({
61
- redirectToProvider: redirectToProviderMock,
62
- });
63
-
64
- const component = mount(
65
- <SocialFormComponent isLoading={false} setIsLoading={() => false} />
66
- );
67
-
68
- const facebook = component.find("SocialButton").at(0);
69
-
70
- await act(async () => {
71
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72
- // @ts-ignore
73
- facebook.prop("onClick")!();
74
- });
75
-
76
- expect(redirectToProviderMock).toHaveBeenCalledTimes(1);
77
- expect(notificationDangerMock).toHaveBeenCalledTimes(2);
78
- expect(notificationSuccessMock).toHaveBeenCalledTimes(0);
79
- });
80
-
81
- it("should fail on twitter click action", async () => {
82
- const redirectTo = "/test";
83
- const redirectToProviderMock = jest.fn().mockReturnValue(
84
- Promise.resolve({
85
- redirect: redirectTo,
86
- })
87
- );
88
- const notificationDangerMock = jest.fn();
89
-
90
- RouteService.cleanRedirect = jest.fn();
91
-
92
- useNotificationMock({
93
- danger: notificationDangerMock,
94
- success: jest.fn(),
95
- });
96
-
97
- useSocialApiMock({
98
- redirectToProvider: redirectToProviderMock,
99
- });
100
-
101
- const component = mount(
102
- <SocialFormComponent isLoading={false} setIsLoading={() => false} />
103
- );
104
-
105
- const twitter = component.find("SocialButton").at(1);
106
-
107
- await act(async () => {
108
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
109
- // @ts-ignore
110
- twitter.prop("onClick")!();
111
- });
112
-
113
- expect(redirectToProviderMock).toHaveBeenCalledTimes(1);
114
- expect(notificationDangerMock).toHaveBeenCalledTimes(0);
115
- expect(RouteService.cleanRedirect).toHaveBeenCalledTimes(1);
116
- expect(RouteService.cleanRedirect).toHaveBeenCalledWith(redirectTo);
117
- });
118
- });
@@ -1,42 +0,0 @@
1
- import { render, screen } from "@testing-library/react";
2
- import userEvent from "@testing-library/user-event";
3
- import React from "react";
4
- import { FileUpload } from "../../src/file-upload/FileUpload";
5
-
6
- describe("FileUpload", () => {
7
- const file = new File(["(⌐□_□)"], "foo.png", { type: "image/png" });
8
-
9
- it("upload files", () => {
10
- render(<FileUpload allowedExtensions={["png"]} onFilesChange={() => {}} />);
11
- const uploader = screen.getByTitle("Upload Files") as HTMLInputElement;
12
- userEvent.upload(uploader, file);
13
-
14
- expect(uploader.files[0]).toStrictEqual(file);
15
- expect(uploader.files.item(0)).toStrictEqual(file);
16
- expect(uploader.files).toHaveLength(1);
17
- });
18
-
19
- it("should not upload file if its extension is not allowed", () => {
20
- render(<FileUpload allowedExtensions={["jpg"]} onFilesChange={() => {}} />);
21
- const uploader = screen.getByTitle("Upload Files") as HTMLInputElement;
22
- userEvent.upload(uploader, file, undefined, { applyAccept: true });
23
- expect(uploader.files[0]).not.toStrictEqual(file);
24
- expect(uploader.files).toHaveLength(0);
25
- });
26
-
27
- it("should display preview if it's enabled", () => {
28
- render(
29
- <FileUpload
30
- allowedExtensions={["png"]}
31
- onFilesChange={() => {}}
32
- enablePreview
33
- />
34
- );
35
- global.URL.createObjectURL = jest.fn();
36
- const uploader = screen.getByTitle("Upload Files") as HTMLInputElement;
37
- userEvent.upload(uploader, file);
38
- const imagePreview = screen.getByTestId("preview-image");
39
-
40
- expect(imagePreview).toBeInTheDocument();
41
- });
42
- });
@@ -1,82 +0,0 @@
1
- /* eslint-disable testing-library/render-result-naming-convention */
2
- import * as React from "react";
3
- import { render } from "@testing-library/react";
4
- import { createMemoryHistory } from "history";
5
- import { Router } from "react-router-dom";
6
- import { EmailTemplateCard } from "../../src/notification/email-template/card/EmailTemplateCard";
7
- import { EmailTemplateForm } from "../../src/notification/email-template/form/EmailTemplateForm";
8
- import useTranslationMock from "../__mock__/hooks/useTranslationMock";
9
-
10
- const history = createMemoryHistory();
11
-
12
- jest.mock("react-i18next", () => ({
13
- Trans: jest.fn().mockReturnValue("test"),
14
- useTranslation: jest.fn(),
15
- }));
16
-
17
- beforeEach(() => {
18
- useTranslationMock();
19
- });
20
-
21
- afterAll(() => {
22
- jest.resetAllMocks();
23
- });
24
-
25
- describe("EmailTemplate", () => {
26
- it("EmailTemplateCard should be rendered without issues", () => {
27
- const screen = render(
28
- <Router history={history as any}>
29
- <EmailTemplateCard
30
- hasPermission
31
- name="Email Template"
32
- subject="New Subject"
33
- href=""
34
- onRemove={() => {}}
35
- isDefault
36
- />
37
- </Router>
38
- );
39
- expect(screen.getByRole("button")).toBeInTheDocument();
40
- expect(screen.getByText("Email Template")).toBeInTheDocument();
41
- });
42
-
43
- it("EmailTemplateCard should not rendered button without valid permission", () => {
44
- const screen = render(
45
- <Router history={history as any}>
46
- <EmailTemplateCard
47
- hasPermission={false}
48
- name="Email Template"
49
- subject="New Subject"
50
- href=""
51
- onRemove={() => {}}
52
- isDefault
53
- />
54
- </Router>
55
- );
56
- expect(screen.queryByRole("button")).not.toBeInTheDocument();
57
- });
58
-
59
- it("EmailTemplateForm should be rendered without issues", () => {
60
- const screen = render(
61
- <EmailTemplateForm
62
- hasPermission
63
- isLoading={false}
64
- onSubmitSave={() => {}}
65
- placeholders={[]}
66
- />
67
- );
68
- expect(screen.getByRole("button")).toBeTruthy();
69
- });
70
-
71
- it("EmailTemplateForm should not rendered button without valid permission", () => {
72
- const screen = render(
73
- <EmailTemplateForm
74
- hasPermission={false}
75
- isLoading={false}
76
- onSubmitSave={() => {}}
77
- placeholders={[]}
78
- />
79
- );
80
- expect(screen.queryByRole("button")).not.toBeInTheDocument();
81
- });
82
- });