@licklist/design 0.59.0-dev.9 → 0.59.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 (201) hide show
  1. package/bitbucket-pipelines.yml +8 -0
  2. package/dist/calendar/Calendar.d.ts +1 -1
  3. package/dist/calendar/Calendar.d.ts.map +1 -1
  4. package/dist/calendar/Calendar.js +1 -1
  5. package/dist/calendar/components/CalendarDates/CalendarDates.d.ts +2 -2
  6. package/dist/calendar/components/CalendarDates/CalendarDates.d.ts.map +1 -1
  7. package/dist/calendar/components/CalendarDates/CalendarDates.js +1 -1
  8. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts +1 -3
  9. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts.map +1 -1
  10. package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.js +1 -1
  11. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts +1 -3
  12. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts.map +1 -1
  13. package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.js +1 -1
  14. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts +1 -3
  15. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts.map +1 -1
  16. package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.js +1 -1
  17. package/dist/iframe/activity-card/ActivityCard.d.ts +1 -2
  18. package/dist/iframe/activity-card/ActivityCard.d.ts.map +1 -1
  19. package/dist/iframe/activity-card/ActivityCard.js +1 -1
  20. package/dist/iframe/event/event-card/IframeEventCard.d.ts +1 -2
  21. package/dist/iframe/event/event-card/IframeEventCard.d.ts.map +1 -1
  22. package/dist/iframe/event/event-card/IframeEventCard.js +1 -1
  23. package/dist/iframe/order-process/components/CategoryProduct/components/NumberInput/NumberInput.js +1 -1
  24. package/dist/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.d.ts.map +1 -1
  25. package/dist/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.js +1 -1
  26. package/dist/iframe/page/components/PageBody/constants.d.ts +1 -1
  27. package/dist/iframe/page/components/PageBody/constants.d.ts.map +1 -1
  28. package/dist/iframe/page/components/PageBody/constants.js +1 -1
  29. package/dist/iframe/page/components/PageBody/hooks/useResizePageBody.js +1 -1
  30. package/dist/iframe/payment/order-items-table/utils/paymentSummary.js +1 -1
  31. package/dist/iframe/payment/payment-page/PaymentPage.js +1 -1
  32. package/dist/iframe/ryft/RyftPaymentForm.d.ts +1 -3
  33. package/dist/iframe/ryft/RyftPaymentForm.d.ts.map +1 -1
  34. package/dist/iframe/ryft/RyftPaymentForm.js +1 -1
  35. package/dist/iframe/ryft/utils/ryft-form.d.ts +1 -2
  36. package/dist/iframe/ryft/utils/ryft-form.d.ts.map +1 -1
  37. package/dist/iframe/ryft/utils/ryft-form.js +1 -1
  38. package/dist/product-set/control/DateAndRecurrenceInput.d.ts +1 -1
  39. package/dist/product-set/control/DateAndRecurrenceInput.d.ts.map +1 -1
  40. package/dist/product-set/control/DateAndRecurrenceInput.js +1 -1
  41. package/dist/product-set/control/DateInput.d.ts.map +1 -1
  42. package/dist/product-set/control/DateInput.js +1 -1
  43. package/dist/product-set/control/ProductSetControl.d.ts +1 -1
  44. package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
  45. package/dist/product-set/form/ProductSetForm.d.ts +1 -4
  46. package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
  47. package/dist/product-set/hooks/useSortableTreeFunctions.d.ts.map +1 -1
  48. package/dist/product-set/product/ProductControl.d.ts.map +1 -1
  49. package/dist/product-set/product/ProductControl.js +1 -1
  50. package/dist/product-set/product/fixed-duration-fields/FixedDurationOptions.d.ts.map +1 -1
  51. package/dist/product-set/product-category/ProductCategoryControl.d.ts +0 -1
  52. package/dist/product-set/product-category/ProductCategoryControl.d.ts.map +1 -1
  53. package/dist/product-set/product-category/ProductCategoryControl.js +1 -1
  54. package/dist/provider/working-hours-input/WorkingHoursInputDescription.d.ts.map +1 -1
  55. package/dist/provider/working-hours-input/WorkingHoursInputDescription.js +1 -1
  56. package/dist/recurring-date-picker-input/RecurrenceAndFrequencyInput.d.ts.map +1 -1
  57. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts +1 -3
  58. package/dist/recurring-date-picker-input/RecurringDatePickerInput.d.ts.map +1 -1
  59. package/dist/recurring-date-picker-input/RecurringDatePickerInput.js +1 -1
  60. package/dist/recurring-date-picker-input/utils.d.ts +0 -12
  61. package/dist/recurring-date-picker-input/utils.d.ts.map +1 -1
  62. package/dist/recurring-date-picker-input/utils.js +1 -1
  63. package/dist/sales/booking/results/components/ResultCard.d.ts.map +1 -1
  64. package/dist/sales/booking/results/components/ResultCard.js +1 -1
  65. package/dist/sales/coupon/control/CouponFormControl.d.ts +1 -2
  66. package/dist/sales/coupon/control/CouponFormControl.d.ts.map +1 -1
  67. package/dist/sales/coupon/control/CouponFormControl.js +1 -1
  68. package/dist/sales/coupon/form/CouponFrom.d.ts +2 -2
  69. package/dist/sales/coupon/form/CouponFrom.d.ts.map +1 -1
  70. package/dist/setting/admin/AdminSettingForm.d.ts +2 -2
  71. package/dist/setting/admin/AdminSettingForm.d.ts.map +1 -1
  72. package/dist/setting/dashboard/DashboardSettingForm.d.ts +0 -1
  73. package/dist/setting/dashboard/DashboardSettingForm.d.ts.map +1 -1
  74. package/dist/setting/dashboard/DashboardSettingForm.js +1 -1
  75. package/dist/static/manual-date-picker/ManualDatePicker.js +1 -1
  76. package/dist/static/manual-date-picker/constants/index.d.ts +1 -4
  77. package/dist/static/manual-date-picker/constants/index.d.ts.map +1 -1
  78. package/dist/static/manual-date-picker/constants/index.js +1 -1
  79. package/dist/static/manual-date-picker/utils/index.d.ts +0 -4
  80. package/dist/static/manual-date-picker/utils/index.d.ts.map +1 -1
  81. package/dist/static/manual-date-picker/utils/index.js +1 -1
  82. package/dist/styles/activity-card/ListActivitiesCard.scss +1 -1
  83. package/dist/styles/iframe-events/Card.scss +8 -24
  84. package/dist/styles/iframe-events/PoweredBy.scss +2 -2
  85. package/dist/styles/iframe-external-modal/IframeExternalModal.scss +2 -5
  86. package/dist/styles/iframe-order-process/IframeOrderProcess.scss +2 -0
  87. package/dist/styles/iframe-page/Page.scss +0 -1
  88. package/dist/styles/iframe-page/PageBody.scss +9 -32
  89. package/dist/styles/iframe-page/PageHeader.scss +39 -41
  90. package/dist/styles/ryft-payment-form/RyftPaymentForm.scss +113 -99
  91. package/dist/styles/sales/BookingResults.scss +1 -1
  92. package/dist/typeahead/Typeahead.d.ts +1 -2
  93. package/dist/typeahead/Typeahead.d.ts.map +1 -1
  94. package/dist/typeahead/Typeahead.js +1 -1
  95. package/dist/zone/form/ZoneForm.d.ts +2 -2
  96. package/dist/zone/form/ZoneForm.d.ts.map +1 -1
  97. package/dist/zone/form/ZoneForm.js +1 -1
  98. package/dist/zone/form/components/ZoneControl.d.ts +2 -2
  99. package/dist/zone/form/components/ZoneControl.d.ts.map +1 -1
  100. package/dist/zone/form/components/ZoneControl.js +1 -1
  101. package/dist/zone/form/components/ZoneRecurrencesControl.d.ts +4 -4
  102. package/dist/zone/form/components/ZoneRecurrencesControl.d.ts.map +1 -1
  103. package/dist/zone/form/components/ZoneRecurrencesControl.js +1 -1
  104. package/dist/zone/form/utils/dates.d.ts.map +1 -1
  105. package/jest.config.js +29 -0
  106. package/package.json +35 -10
  107. package/src/calendar/Calendar.stories.tsx +0 -23
  108. package/src/calendar/Calendar.tsx +5 -5
  109. package/src/calendar/components/CalendarDates/CalendarDates.tsx +5 -0
  110. package/src/events/edit-event-modal/component/EditEventForm/EditEventForm.tsx +0 -4
  111. package/src/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.tsx +8 -10
  112. package/src/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.tsx +0 -4
  113. package/src/iframe/activity-card/ActivityCard.tsx +2 -4
  114. package/src/iframe/event/event-card/IframeEventCard.stories.tsx +0 -1
  115. package/src/iframe/event/event-card/IframeEventCard.tsx +8 -7
  116. package/src/iframe/order-process/components/CategoryProduct/components/NumberInput/NumberInput.tsx +1 -1
  117. package/src/iframe/page/components/PageBody/components/LeftBlock/LeftBlock.tsx +1 -3
  118. package/src/iframe/page/components/PageBody/constants.ts +1 -1
  119. package/src/iframe/page/components/PageBody/hooks/useResizePageBody.ts +3 -3
  120. package/src/iframe/payment/order-items-table/utils/paymentSummary.tsx +6 -6
  121. package/src/iframe/payment/payment-page/PaymentPage.tsx +2 -2
  122. package/src/iframe/ryft/RyftPaymentForm.tsx +3 -20
  123. package/src/iframe/ryft/utils/ryft-form.ts +5 -11
  124. package/src/product-set/control/DateAndRecurrenceInput.tsx +2 -3
  125. package/src/product-set/control/DateInput.tsx +5 -4
  126. package/src/product-set/control/ProductSetControl.tsx +1 -1
  127. package/src/product-set/form/ProductCategoriesControl.tsx +1 -1
  128. package/src/product-set/form/ProductSetForm.tsx +1 -5
  129. package/src/product-set/hooks/useSortableTreeFunctions.ts +0 -2
  130. package/src/product-set/product/ProductControl.tsx +38 -38
  131. package/src/product-set/product/fixed-duration-fields/FixedDurationOptions.tsx +2 -0
  132. package/src/product-set/product-category/ProductCategoryControl.tsx +27 -89
  133. package/src/provider/working-hours-input/WorkingHoursInputDescription.tsx +18 -4
  134. package/src/recurring-date-picker-input/RecurrenceAndFrequencyInput.tsx +1 -0
  135. package/src/recurring-date-picker-input/RecurringDatePickerInput.tsx +1 -11
  136. package/src/recurring-date-picker-input/utils.ts +0 -77
  137. package/src/sales/booking/results/BookingResults.stories.tsx +2 -3
  138. package/src/sales/booking/results/components/ResultCard.tsx +5 -2
  139. package/src/sales/coupon/control/CouponFormControl.tsx +50 -29
  140. package/src/sales/coupon/form/CouponFrom.tsx +15 -5
  141. package/src/setting/admin/AdminSettingForm.tsx +2 -2
  142. package/src/setting/dashboard/DashboardSettingForm.tsx +0 -13
  143. package/src/sortable-tree/SortableTreeItem.tsx +1 -1
  144. package/src/static/manual-date-picker/ManualDatePicker.tsx +3 -3
  145. package/src/static/manual-date-picker/constants/index.ts +2 -6
  146. package/src/static/manual-date-picker/utils/index.ts +0 -11
  147. package/src/static/switch/BooleanSwitch.tsx +1 -1
  148. package/src/styles/activity-card/ListActivitiesCard.scss +1 -1
  149. package/src/styles/iframe-events/Card.scss +8 -24
  150. package/src/styles/iframe-events/PoweredBy.scss +2 -2
  151. package/src/styles/iframe-external-modal/IframeExternalModal.scss +2 -5
  152. package/src/styles/iframe-order-process/IframeOrderProcess.scss +2 -0
  153. package/src/styles/iframe-page/Page.scss +0 -1
  154. package/src/styles/iframe-page/PageBody.scss +9 -32
  155. package/src/styles/iframe-page/PageHeader.scss +39 -41
  156. package/src/styles/ryft-payment-form/RyftPaymentForm.scss +113 -99
  157. package/src/styles/sales/BookingResults.scss +1 -1
  158. package/src/typeahead/Typeahead.tsx +3 -16
  159. package/src/zone/form/ZoneForm.tsx +2 -3
  160. package/src/zone/form/components/ZoneControl.tsx +3 -3
  161. package/src/zone/form/components/ZoneRecurrencesControl.tsx +5 -7
  162. package/src/zone/form/utils/dates.ts +10 -9
  163. package/tests/Auth/Authorizer.test.tsx +194 -0
  164. package/tests/Auth/Layout/UserNavDropDown.test.tsx +43 -0
  165. package/tests/Auth/Layout/UserNavDropDownToggle.test.tsx +33 -0
  166. package/tests/Auth/Login/LoginComponent.test.tsx +246 -0
  167. package/tests/Auth/Login/LoginFormComponent.test.tsx +182 -0
  168. package/tests/Auth/Register/RegisterComponent.test.tsx +285 -0
  169. package/tests/Auth/Register/RegisterFormComponent.test.tsx +170 -0
  170. package/tests/Auth/Settings/Dashboard/IpInput.test.tsx +130 -0
  171. package/tests/Auth/Social/SocialCallbackComponent.test.tsx +133 -0
  172. package/tests/Auth/Social/SocialFormComponent.test.tsx +118 -0
  173. package/tests/FileUpload/FileUpload.test.tsx +42 -0
  174. package/tests/Notification/EmailTemplate.test.tsx +82 -0
  175. package/tests/ProductSet/ProductSetPopover.test.tsx +40 -0
  176. package/tests/Report/Report.test.tsx +48 -0
  177. package/tests/Sales/Coupon.test.tsx +51 -0
  178. package/tests/Sales/SalesAndVIews.test.tsx +63 -0
  179. package/tests/SnippetTemplates/SnippetTemplates.test.tsx +56 -0
  180. package/tests/Table/FilterHelperComponent.test.tsx +88 -0
  181. package/tests/Table/PaginationHelperComponent.test.tsx +109 -0
  182. package/tests/Table/PerPageHelperComponent.test.tsx +34 -0
  183. package/tests/Table/TableHelperComponent.test.tsx +295 -0
  184. package/tests/TipTapEditor/TipTapEditor.test.tsx +28 -0
  185. package/tests/__mock__/hooks/useAuthApi.ts +13 -0
  186. package/tests/__mock__/hooks/useAuthMock.ts +13 -0
  187. package/tests/__mock__/hooks/useFormMock.ts +27 -0
  188. package/tests/__mock__/hooks/useNotificationMock.ts +13 -0
  189. package/tests/__mock__/hooks/useQueryMock.ts +16 -0
  190. package/tests/__mock__/hooks/useSocialApiMock.ts +20 -0
  191. package/tests/__mock__/hooks/useTranslationMock.ts +17 -0
  192. package/tests/__mock__/hooks/useUserApiMock.ts +18 -0
  193. package/tests/__mock__/hooks/useUserMock.ts +13 -0
  194. package/tests/__mock__/styleMock.js +1 -0
  195. package/tests/__mock__/windowMock.ts +5 -0
  196. package/tests/packages/react-query.tsx +28 -0
  197. package/tests/setupTests.ts +10 -0
  198. package/dist/sales/coupon/utils/index.d.ts +0 -7
  199. package/dist/sales/coupon/utils/index.d.ts.map +0 -1
  200. package/dist/sales/coupon/utils/index.js +0 -1
  201. package/src/sales/coupon/utils/index.ts +0 -13
@@ -0,0 +1,63 @@
1
+ /* eslint-disable testing-library/render-result-naming-convention */
2
+ import * as React from "react";
3
+ import { render } from "@testing-library/react";
4
+ import moment from "moment";
5
+ import { IntlProvider } from "react-intl";
6
+ import useTranslationMock from "../__mock__/hooks/useTranslationMock";
7
+
8
+ import {
9
+ ChartData,
10
+ SalesAndViewsChart,
11
+ } from "../../src/sales/sales-and-views/SalesAndViewsChart";
12
+
13
+ jest.mock("react-i18next", () => ({
14
+ Trans: jest.fn().mockReturnValue("test"),
15
+ useTranslation: jest.fn(),
16
+ }));
17
+
18
+ beforeEach(() => {
19
+ useTranslationMock();
20
+ });
21
+
22
+ afterAll(() => {
23
+ jest.resetAllMocks();
24
+ });
25
+
26
+ function generateRandom() {
27
+ return Math.floor(Math.random() * 100);
28
+ }
29
+
30
+ const genarateChartData = (): ChartData[] => {
31
+ const chartData = [];
32
+ const date = moment().subtract(90, "d");
33
+
34
+ for (let i = 0; i < 90; i += 1) {
35
+ chartData.push({
36
+ id: i,
37
+ sales: generateRandom(),
38
+ views: generateRandom(),
39
+ date: date.add(i, "d").format("YYYY-MM-DD"),
40
+ });
41
+ }
42
+ return chartData;
43
+ };
44
+
45
+ describe("SalesAndViewsChart", () => {
46
+ it("SalesAndViewsChart should be rendered without issues", () => {
47
+ const data = genarateChartData();
48
+
49
+ const screen = render(
50
+ <IntlProvider locale="en" timeZone="Europe/London">
51
+ <div style={{ height: "500px", width: "700px" }}>
52
+ <SalesAndViewsChart
53
+ data={data}
54
+ handleFilter={() => {}}
55
+ activePeriod="week"
56
+ />
57
+ </div>
58
+ </IntlProvider>
59
+ );
60
+ const salesHeaderContainer = screen.getAllByText("test");
61
+ expect(salesHeaderContainer[0]).toBeInTheDocument();
62
+ });
63
+ });
@@ -0,0 +1,56 @@
1
+ /* eslint-disable testing-library/render-result-naming-convention */
2
+ import * as React from "react";
3
+ import { createMemoryHistory } from "history";
4
+ import { Router } from "react-router-dom";
5
+ import { render } from "@testing-library/react";
6
+ import { SnippetTemplateCard } from "../../src/setting/dashboard/snippet-templates/card";
7
+ import useTranslationMock from "../__mock__/hooks/useTranslationMock";
8
+
9
+ const history = createMemoryHistory();
10
+
11
+ jest.mock("react-i18next", () => ({
12
+ Trans: jest.fn().mockReturnValue("test"),
13
+ useTranslation: jest.fn(),
14
+ }));
15
+
16
+ beforeEach(() => {
17
+ useTranslationMock();
18
+ });
19
+
20
+ afterAll(() => {
21
+ jest.resetAllMocks();
22
+ });
23
+
24
+ describe("SnippetTemplates", () => {
25
+ it("SnippetTemplate should be rendered without issues", () => {
26
+ const screen = render(
27
+ <Router history={history as any}>
28
+ <SnippetTemplateCard
29
+ hasPermission
30
+ name="testSnippet"
31
+ onRemove={() => {}}
32
+ colors={["blue", "yellow"]}
33
+ href="/"
34
+ />
35
+ </Router>
36
+ );
37
+
38
+ expect(screen.getByRole("button")).toBeTruthy();
39
+ });
40
+
41
+ it("SnippetTemplate without permission", async () => {
42
+ const screen = render(
43
+ <Router history={history as any}>
44
+ <SnippetTemplateCard
45
+ hasPermission={false}
46
+ name="testSnippet"
47
+ onRemove={() => {}}
48
+ colors={["blue", "yellow"]}
49
+ href="/"
50
+ />
51
+ </Router>
52
+ );
53
+
54
+ expect(screen.queryByRole("button")).toBeFalsy();
55
+ });
56
+ });
@@ -0,0 +1,88 @@
1
+ import { mount, shallow } from "enzyme";
2
+ import * as React from "react";
3
+ import { act } from "react-dom/test-utils";
4
+ import FormControl from "react-bootstrap/FormControl";
5
+ import Button from "react-bootstrap/Button";
6
+ import { FilterHelperComponent } from "../../src/table/FilterHelperComponent";
7
+
8
+ describe("FilterHelperComponent", () => {
9
+ it("should be rendered without issues", () => {
10
+ const component = shallow(<FilterHelperComponent />);
11
+
12
+ expect(component.exists()).toBeTruthy();
13
+ });
14
+
15
+ it("should be mount without issues", () => {
16
+ const component = mount(
17
+ <FilterHelperComponent defaultValue="defaultValue" />
18
+ );
19
+
20
+ expect(component.exists()).toBeTruthy();
21
+ });
22
+
23
+ it("should act on change", () => {
24
+ const component = mount(<FilterHelperComponent />);
25
+
26
+ act(() => {
27
+ component.find(FormControl).first().prop("onChange")?.({
28
+ target: {
29
+ value: "onChange",
30
+ },
31
+ } as React.ChangeEvent<HTMLInputElement>);
32
+ });
33
+
34
+ component.update();
35
+ expect(component.find(FormControl).first().prop("value")).toBe("onChange");
36
+ });
37
+
38
+ it("should act on clear", () => {
39
+ const onClickFn = jest.fn();
40
+ const component = mount(<FilterHelperComponent onClickFn={onClickFn} />);
41
+
42
+ act(() => {
43
+ component.find(Button).first().prop("onClick")?.(
44
+ {} as React.MouseEvent<HTMLButtonElement>
45
+ );
46
+ });
47
+
48
+ component.update();
49
+ expect(onClickFn).toHaveBeenCalledTimes(1);
50
+ });
51
+
52
+ it("should act on search", () => {
53
+ const onClickFn = jest.fn();
54
+ const component = mount(<FilterHelperComponent onClickFn={onClickFn} />);
55
+
56
+ act(() => {
57
+ component.find(Button).last().prop("onClick")?.(
58
+ {} as React.MouseEvent<HTMLButtonElement>
59
+ );
60
+ });
61
+
62
+ component.update();
63
+ expect(onClickFn).toHaveBeenCalledTimes(1);
64
+ });
65
+
66
+ it("should act on enter", () => {
67
+ const onClickFn = jest.fn();
68
+ const component = mount(<FilterHelperComponent onClickFn={onClickFn} />);
69
+
70
+ act(() => {
71
+ component.find(FormControl).last().prop("onKeyDown")?.({
72
+ key: "Space",
73
+ } as React.KeyboardEvent);
74
+ });
75
+
76
+ component.update();
77
+ expect(onClickFn).toHaveBeenCalledTimes(0);
78
+
79
+ act(() => {
80
+ component.find(FormControl).last().prop("onKeyDown")?.({
81
+ key: "Enter",
82
+ } as React.KeyboardEvent);
83
+ });
84
+
85
+ component.update();
86
+ expect(onClickFn).toHaveBeenCalledTimes(1);
87
+ });
88
+ });
@@ -0,0 +1,109 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ import ILengthAwarePaginator from "@licklist/plugins/dist/types/services/Table/ILengthAwarePaginator";
3
+ import { mount, shallow } from "enzyme";
4
+ import * as React from "react";
5
+ import PageItem from "react-bootstrap/PageItem";
6
+ import { act } from "react-dom/test-utils";
7
+ import { PaginationHelperComponent } from "../../src/table/PaginationHelperComponent";
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
+
15
+ beforeEach(() => {
16
+ useTranslationMock();
17
+ });
18
+
19
+ afterAll(() => {
20
+ jest.resetAllMocks();
21
+ });
22
+
23
+ describe("PaginationHelperComponent", () => {
24
+ const getPaginator = (): ILengthAwarePaginator<{}> => ({
25
+ current_page: 1,
26
+ last_page: 1,
27
+ first_page_url: "first_page_url",
28
+ last_page_url: "last_page_url",
29
+ next_page_url: "next_page_url",
30
+ prev_page_url: "prev_page_url",
31
+ path: "path",
32
+ per_page: 1,
33
+ from: 0,
34
+ to: 1,
35
+ total: 1,
36
+ data: [
37
+ {
38
+ test: "data",
39
+ },
40
+ ],
41
+ });
42
+
43
+ it("should be rendered without issues", () => {
44
+ const component = shallow(<PaginationHelperComponent />);
45
+
46
+ expect(component.exists()).toBeTruthy();
47
+ });
48
+
49
+ it("should be mount without issues", () => {
50
+ const component = mount(
51
+ <PaginationHelperComponent paginator={getPaginator()} />
52
+ );
53
+
54
+ expect(component.exists()).toBeTruthy();
55
+ });
56
+
57
+ it("should render pagination section if there are more pages", () => {
58
+ const paginator = getPaginator();
59
+ paginator.last_page = 2;
60
+ const component = mount(
61
+ <PaginationHelperComponent paginator={paginator} />
62
+ );
63
+
64
+ expect(component.exists()).toBeTruthy();
65
+ });
66
+
67
+ it("should act on page change", () => {
68
+ const paginator = getPaginator();
69
+ const onPageChangeFn = jest.fn();
70
+ paginator.last_page = 2;
71
+ const component = mount(
72
+ <PaginationHelperComponent
73
+ paginator={paginator}
74
+ onPageChangeFn={onPageChangeFn}
75
+ />
76
+ );
77
+
78
+ act(() => {
79
+ component.find("button").first().prop("onClick")?.(
80
+ {} as React.MouseEvent<HTMLElement>
81
+ );
82
+ });
83
+
84
+ component.update();
85
+ expect(onPageChangeFn).toHaveBeenCalledTimes(1);
86
+ });
87
+
88
+ it("should act on page change by click on a specific page", () => {
89
+ const paginator = getPaginator();
90
+ const onPageChangeFn = jest.fn();
91
+ paginator.last_page = 2;
92
+ const component = mount(
93
+ <PaginationHelperComponent
94
+ paginator={paginator}
95
+ onPageChangeFn={onPageChangeFn}
96
+ />
97
+ );
98
+
99
+ act(() => {
100
+ component.find(PageItem).at(1).prop("onClick")?.(
101
+ {} as React.MouseEvent<HTMLElement>
102
+ );
103
+ });
104
+
105
+ component.update();
106
+ expect(onPageChangeFn).toHaveBeenCalledTimes(1);
107
+ expect(onPageChangeFn).toHaveBeenCalledWith(2);
108
+ });
109
+ });
@@ -0,0 +1,34 @@
1
+ import { mount, shallow } from "enzyme";
2
+ import * as React from "react";
3
+ import { act } from "react-dom/test-utils";
4
+ import { PerPageHelperComponent } from "../../src/table/PerPageHelperComponent";
5
+
6
+ describe("PerPageHelperComponent", () => {
7
+ it("should be rendered without issues", () => {
8
+ const component = shallow(<PerPageHelperComponent />);
9
+
10
+ expect(component.exists()).toBeTruthy();
11
+ });
12
+
13
+ it("should be mount without issues", () => {
14
+ const component = mount(<PerPageHelperComponent defaultValue={10} />);
15
+
16
+ expect(component.exists()).toBeTruthy();
17
+ });
18
+
19
+ it("should act on change", () => {
20
+ const onChangeFn = jest.fn();
21
+ const component = mount(<PerPageHelperComponent onChangeFn={onChangeFn} />);
22
+
23
+ act(() => {
24
+ component.find("select").first().prop("onChange")?.({
25
+ target: {
26
+ value: "100",
27
+ },
28
+ } as React.ChangeEvent<HTMLSelectElement>);
29
+ });
30
+
31
+ component.update();
32
+ expect(onChangeFn).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
@@ -0,0 +1,295 @@
1
+ import TableService from "@licklist/plugins/dist/services/Table/TableService";
2
+ import ILengthAwarePaginator from "@licklist/plugins/dist/types/services/Table/ILengthAwarePaginator";
3
+ import ITableHeader from "@licklist/plugins/dist/types/services/Table/ITableHeader";
4
+ import { mount, shallow } from "enzyme";
5
+ import * as React from "react";
6
+ import { act } from "react-dom/test-utils";
7
+ import {
8
+ FilterHelperComponent,
9
+ PaginationHelperComponent,
10
+ PerPageHelperComponent,
11
+ TableHelperComponent,
12
+ } from "../../src/table";
13
+ import { getFilterOptionsValue } from "../../src/table/utils";
14
+ import useQueryMock from "../__mock__/hooks/useQueryMock";
15
+
16
+ jest.mock("@licklist/plugins/dist/hooks/Query/useQuery");
17
+ jest.mock("react-router-dom", () => ({
18
+ useLocation: () => ({
19
+ pathname: "/",
20
+ }),
21
+ }));
22
+
23
+ beforeEach(() => {
24
+ useQueryMock();
25
+ });
26
+
27
+ afterAll(() => {
28
+ jest.resetAllMocks();
29
+ });
30
+
31
+ describe("TableHelperComponent", () => {
32
+ const getPaginator = (): ILengthAwarePaginator<any> => ({
33
+ current_page: 1,
34
+ last_page: 1,
35
+ first_page_url: "first_page_url",
36
+ last_page_url: "last_page_url",
37
+ next_page_url: "next_page_url",
38
+ prev_page_url: "prev_page_url",
39
+ path: "path",
40
+ per_page: 1,
41
+ from: 0,
42
+ to: 1,
43
+ total: 1,
44
+ data: [
45
+ {
46
+ id: 1,
47
+ },
48
+ ],
49
+ });
50
+ const defaultHeaders = (): ITableHeader[] => [
51
+ {
52
+ title: "ID",
53
+ isSortable: false,
54
+ },
55
+ ];
56
+ const defaultItemRenderer = (item: any) => (
57
+ <tr key={item.id}>
58
+ <td>{item.id}</td>
59
+ </tr>
60
+ );
61
+
62
+ it("should be rendered without issues", () => {
63
+ const component = shallow(
64
+ <TableHelperComponent
65
+ headers={defaultHeaders()}
66
+ renderItemFn={defaultItemRenderer}
67
+ isLoading
68
+ />
69
+ );
70
+
71
+ expect(component.exists()).toBeTruthy();
72
+ });
73
+
74
+ it("should be mount without issues", () => {
75
+ const component = mount(
76
+ <TableHelperComponent
77
+ headers={defaultHeaders()}
78
+ renderItemFn={defaultItemRenderer}
79
+ paginator={getPaginator()}
80
+ isLoading={false}
81
+ />
82
+ );
83
+
84
+ expect(component.exists()).toBeTruthy();
85
+ });
86
+
87
+ it("should act on refresh", () => {
88
+ const onRefreshFn = jest.fn();
89
+
90
+ mount(
91
+ <TableHelperComponent
92
+ headers={defaultHeaders()}
93
+ renderItemFn={defaultItemRenderer}
94
+ paginator={getPaginator()}
95
+ isLoading={false}
96
+ onRefreshFn={onRefreshFn}
97
+ />
98
+ );
99
+
100
+ expect(onRefreshFn).toHaveBeenCalledTimes(2);
101
+ });
102
+
103
+ it("should act on manual refresh trigger", () => {
104
+ const onRefreshFn = jest.fn();
105
+ let refreshAt = 0;
106
+
107
+ const component = mount(
108
+ <TableHelperComponent
109
+ headers={defaultHeaders()}
110
+ renderItemFn={defaultItemRenderer}
111
+ paginator={getPaginator()}
112
+ isLoading={false}
113
+ onRefreshFn={onRefreshFn}
114
+ refreshAt={refreshAt}
115
+ />
116
+ );
117
+
118
+ component.update();
119
+
120
+ act(() => {
121
+ refreshAt = 100;
122
+ });
123
+
124
+ component.update();
125
+
126
+ expect(onRefreshFn).toHaveBeenCalledTimes(1);
127
+ });
128
+
129
+ it("should act on sort by header", () => {
130
+ const headers = defaultHeaders();
131
+ headers.push({
132
+ title: "Name",
133
+ key: "sortKey",
134
+ isSortable: true,
135
+ });
136
+ headers.push({
137
+ title: "E-mail",
138
+ isSortable: true,
139
+ });
140
+
141
+ TableService.getHeaderClasses = jest.fn();
142
+ TableService.getSortDirection = jest.fn();
143
+
144
+ const component = mount(
145
+ <TableHelperComponent
146
+ headers={headers}
147
+ renderItemFn={defaultItemRenderer}
148
+ paginator={getPaginator()}
149
+ isLoading={false}
150
+ />
151
+ );
152
+
153
+ act(() => {
154
+ component.find("th").at(1).prop("onClick")?.(
155
+ {} as React.MouseEvent<HTMLElement>
156
+ );
157
+ component.find("th").at(2).prop("onClick")?.(
158
+ {} as React.MouseEvent<HTMLElement>
159
+ );
160
+ });
161
+
162
+ component.update();
163
+
164
+ expect(TableService.getHeaderClasses).toHaveBeenCalled();
165
+ expect(TableService.getSortDirection).toHaveBeenCalled();
166
+ });
167
+
168
+ it("should act on per page change", () => {
169
+ const onRefreshFn = jest.fn();
170
+ const component = mount(
171
+ <TableHelperComponent
172
+ headers={defaultHeaders()}
173
+ renderItemFn={defaultItemRenderer}
174
+ paginator={getPaginator()}
175
+ isLoading={false}
176
+ onRefreshFn={onRefreshFn}
177
+ />
178
+ );
179
+
180
+ component.update();
181
+
182
+ act(() => {
183
+ component.find(PerPageHelperComponent).at(0).prop("onChangeFn")?.(2);
184
+ });
185
+
186
+ component.update();
187
+
188
+ expect(onRefreshFn).toHaveBeenCalled();
189
+ });
190
+
191
+ it("should act on filter change", () => {
192
+ const onRefreshFn = jest.fn();
193
+ const component = mount(
194
+ <TableHelperComponent
195
+ headers={defaultHeaders()}
196
+ renderItemFn={defaultItemRenderer}
197
+ paginator={getPaginator()}
198
+ isLoading={false}
199
+ onRefreshFn={onRefreshFn}
200
+ />
201
+ );
202
+
203
+ component.update();
204
+
205
+ act(() => {
206
+ component.find(FilterHelperComponent).at(0).prop("onClickFn")?.(
207
+ "next-filter"
208
+ );
209
+ });
210
+
211
+ component.update();
212
+
213
+ expect(onRefreshFn).toHaveBeenCalled();
214
+ });
215
+
216
+ it("should act on paginator's page change", () => {
217
+ const onRefreshFn = jest.fn();
218
+ const component = mount(
219
+ <TableHelperComponent
220
+ headers={defaultHeaders()}
221
+ renderItemFn={defaultItemRenderer}
222
+ paginator={getPaginator()}
223
+ isLoading={false}
224
+ onRefreshFn={onRefreshFn}
225
+ />
226
+ );
227
+
228
+ component.update();
229
+
230
+ act(() => {
231
+ component.find(PaginationHelperComponent).at(0).prop("onPageChangeFn")?.(
232
+ 2
233
+ );
234
+ });
235
+
236
+ component.update();
237
+
238
+ expect(onRefreshFn).toHaveBeenCalled();
239
+ });
240
+
241
+ it("should redirect with external parameters", () => {
242
+ const onRefreshFn = jest.fn();
243
+ const component = mount(
244
+ <TableHelperComponent
245
+ headers={defaultHeaders()}
246
+ renderItemFn={defaultItemRenderer}
247
+ paginator={getPaginator()}
248
+ isLoading={false}
249
+ onRefreshFn={onRefreshFn}
250
+ />
251
+ );
252
+
253
+ component.setProps({ externalFilters: { test: 1 } });
254
+
255
+ component.update();
256
+
257
+ expect(window.location.search.includes("&test=1")).toBeTruthy();
258
+
259
+ component.setProps({ externalFilters: { test: "test" } });
260
+
261
+ component.update();
262
+
263
+ expect(window.location.search.includes("&test=test")).toBeTruthy();
264
+
265
+ component.setProps({ externalFilters: {} });
266
+
267
+ component.update();
268
+
269
+ expect(window.location.search.includes("&test=test")).toBeFalsy();
270
+ });
271
+
272
+ describe("getFilterOptionsValue util", () => {
273
+ it("not change query value", () => {
274
+ const query = new URLSearchParams("&page=1");
275
+
276
+ expect(getFilterOptionsValue(query, { page: 2 }, "page")).toBe("1");
277
+ });
278
+
279
+ it("not apply initial values", () => {
280
+ const query = new URLSearchParams("");
281
+
282
+ expect(getFilterOptionsValue(query, { page: 2 }, "page")).toBe(2);
283
+ });
284
+
285
+ it("return default values for standard keys", () => {
286
+ const query = new URLSearchParams("");
287
+
288
+ expect(getFilterOptionsValue(query, {}, "page")).toBe(1);
289
+ expect(getFilterOptionsValue(query, {}, "perPage")).toBe(24);
290
+ expect(getFilterOptionsValue(query, {}, "filter")).toBe("");
291
+ expect(getFilterOptionsValue(query, {}, "sortKey")).toBe("id");
292
+ expect(getFilterOptionsValue(query, {}, "sortDirection")).toBe("asc");
293
+ });
294
+ });
295
+ });
@@ -0,0 +1,28 @@
1
+ import { shallow, mount } from "enzyme";
2
+ import * as React from "react";
3
+ import { TipTapEditor } from "../../src/tiptap-editor/TipTapEditor";
4
+
5
+ describe("TipTapEditorComponent", () => {
6
+ it("should be rendered without issues", () => {
7
+ const component = shallow(<TipTapEditor viewMode={false} />);
8
+
9
+ expect(component.exists()).toBeTruthy();
10
+ });
11
+
12
+ it("should be mount without issues", () => {
13
+ const component = mount(
14
+ <TipTapEditor viewMode content="<p>Test Content</p>" />
15
+ );
16
+
17
+ expect(component.exists()).toBeTruthy();
18
+ });
19
+
20
+ it("should be disabled if it is disabled", () => {
21
+ const component = shallow(
22
+ <TipTapEditor disabled viewMode={false} content="<p>Test Content</p>" />
23
+ );
24
+
25
+ expect(component.exists()).toBeTruthy();
26
+ expect(component.children().at(1).hasClass("editor-disabled")).toBeTruthy();
27
+ });
28
+ });
@@ -0,0 +1,13 @@
1
+ import * as useAuthApi from "@licklist/plugins/dist/hooks/Api/useAuthApi";
2
+
3
+ /**
4
+ * Mocks custom hook
5
+ * @param mockReturn
6
+ */
7
+ const useAuthApiMock = (mockReturn: any = null) => {
8
+ const authApiMock = useAuthApi as jest.Mocked<typeof useAuthApi>;
9
+
10
+ return authApiMock.default.mockReturnValue(mockReturn);
11
+ };
12
+
13
+ export default useAuthApiMock;
@@ -0,0 +1,13 @@
1
+ import * as useAuthHook from "@licklist/plugins/dist/context/user/hooks/useAuth";
2
+
3
+ /**
4
+ * Mocks custom hook
5
+ * @param mockReturn
6
+ */
7
+ const useAuthMock = (mockReturn: any = null) => {
8
+ const useAuthHookMock = useAuthHook as jest.Mocked<typeof useAuthHook>;
9
+
10
+ return useAuthHookMock.default.mockReturnValue(mockReturn);
11
+ };
12
+
13
+ export default useAuthMock;