@tsed/react-formio 1.11.1 → 1.13.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 (152) hide show
  1. package/.env +2 -1
  2. package/craco.config.js +11 -1
  3. package/dist/components/alert/alert.component.spec.d.ts +1 -0
  4. package/dist/components/alert/alert.stories.d.ts +15 -0
  5. package/dist/components/card/card.component.d.ts +2 -1
  6. package/dist/components/form/form.component.d.ts +2 -0
  7. package/dist/components/form/form.stories.d.ts +37 -0
  8. package/dist/components/form/useForm.hook.d.ts +1 -0
  9. package/dist/components/form-action/formAction.stories.d.ts +90 -414
  10. package/dist/components/input-text/inputText.component.d.ts +1 -1
  11. package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
  12. package/dist/components/loader/loader.component.d.ts +2 -2
  13. package/dist/components/loader/loader.stories.d.ts +15 -0
  14. package/dist/components/pagination/pagination.component.spec.d.ts +1 -0
  15. package/dist/components/pagination/pagination.stories.d.ts +0 -27
  16. package/dist/components/select/select.component.spec.d.ts +1 -0
  17. package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
  18. package/dist/index.js +114 -35
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.modern.js +86 -34
  21. package/dist/index.modern.js.map +1 -1
  22. package/jest.config.js +1 -1
  23. package/package.json +5 -9
  24. package/readme.md +114 -86
  25. package/src/components/__fixtures__/form-schema.json +10 -42
  26. package/src/components/__fixtures__/form.fixture.json +1 -1
  27. package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
  28. package/src/components/actions-table/actionsTable.component.tsx +3 -11
  29. package/src/components/alert/alert.component.spec.tsx +97 -0
  30. package/src/components/alert/alert.component.tsx +2 -8
  31. package/src/components/alert/alert.stories.tsx +17 -0
  32. package/src/components/card/card.component.tsx +2 -5
  33. package/src/components/form/form.component.tsx +4 -8
  34. package/src/components/form/form.stories.tsx +66 -2
  35. package/src/components/form/useForm.hook.ts +29 -14
  36. package/src/components/form-access/formAccess.component.tsx +19 -82
  37. package/src/components/form-access/formAccess.schema.ts +7 -23
  38. package/src/components/form-access/formAccess.stories.tsx +2 -9
  39. package/src/components/form-access/formAccess.utils.spec.ts +4 -22
  40. package/src/components/form-access/formAccess.utils.ts +7 -29
  41. package/src/components/form-action/formAction.component.tsx +3 -19
  42. package/src/components/form-action/formAction.stories.tsx +251 -672
  43. package/src/components/form-builder/formBuilder.component.tsx +4 -13
  44. package/src/components/form-builder/formBuilder.stories.tsx +12 -24
  45. package/src/components/form-control/formControl.component.tsx +2 -8
  46. package/src/components/form-edit/formCtas.component.tsx +5 -23
  47. package/src/components/form-edit/formEdit.component.tsx +2 -20
  48. package/src/components/form-edit/formEdit.reducer.ts +2 -8
  49. package/src/components/form-edit/formEdit.stories.tsx +3 -15
  50. package/src/components/form-edit/formParameters.component.tsx +3 -20
  51. package/src/components/form-edit/useFormEdit.hook.ts +2 -9
  52. package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
  53. package/src/components/form-settings/formSettings.component.tsx +6 -34
  54. package/src/components/form-settings/formSettings.stories.tsx +1 -6
  55. package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
  56. package/src/components/form-settings/formSettings.utils.ts +2 -7
  57. package/src/components/forms-table/components/formCell.component.tsx +2 -6
  58. package/src/components/forms-table/formsTable.component.tsx +2 -7
  59. package/src/components/input-tags/inputTags.component.tsx +10 -34
  60. package/src/components/input-tags/inputTags.stories.tsx +4 -14
  61. package/src/components/input-text/inputText.component.spec.tsx +56 -0
  62. package/src/components/input-text/inputText.component.tsx +4 -5
  63. package/src/components/input-text/inputText.stories.tsx +6 -26
  64. package/src/components/loader/loader.component.spec.tsx +7 -6
  65. package/src/components/loader/loader.component.tsx +3 -12
  66. package/src/components/loader/loader.stories.tsx +17 -0
  67. package/src/components/modal/modal.component.spec.tsx +8 -14
  68. package/src/components/modal/modal.component.tsx +6 -27
  69. package/src/components/modal/modal.stories.tsx +1 -5
  70. package/src/components/modal/removeModal.component.tsx +4 -22
  71. package/src/components/pagination/pagination.component.spec.tsx +111 -0
  72. package/src/components/pagination/pagination.component.tsx +10 -42
  73. package/src/components/pagination/pagination.stories.tsx +9 -29
  74. package/src/components/react-component/reactComponent.component.tsx +3 -11
  75. package/src/components/select/select.component.spec.tsx +86 -0
  76. package/src/components/select/select.component.tsx +11 -15
  77. package/src/components/select/select.stories.tsx +6 -26
  78. package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
  79. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
  80. package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
  81. package/src/components/table/components/defaultCell.component.tsx +1 -4
  82. package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
  83. package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
  84. package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
  85. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
  86. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
  87. package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
  88. package/src/components/table/table.component.tsx +13 -53
  89. package/src/components/table/table.stories.tsx +1 -1
  90. package/src/components/table/utils/getPageNumbers.ts +3 -11
  91. package/src/components/table/utils/mapFormToColumns.tsx +14 -22
  92. package/src/components/table/utils/useOperations.hook.tsx +2 -12
  93. package/src/components/tabs/tabs.component.spec.tsx +86 -0
  94. package/src/components/tabs/tabs.component.stories.tsx +2 -9
  95. package/src/components/tabs/tabs.component.tsx +9 -43
  96. package/src/interfaces/Operation.ts +1 -4
  97. package/src/react-table.d.ts +9 -28
  98. package/src/stores/action/action.actions.ts +31 -33
  99. package/src/stores/action/action.reducers.spec.ts +1 -8
  100. package/src/stores/action/action.reducers.ts +1 -8
  101. package/src/stores/action/action.selectors.ts +1 -2
  102. package/src/stores/action-info/action-info.actions.spec.ts +1 -5
  103. package/src/stores/action-info/action-info.actions.ts +16 -19
  104. package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
  105. package/src/stores/action-info/action-info.reducers.ts +1 -6
  106. package/src/stores/action-info/action-info.selectors.ts +1 -4
  107. package/src/stores/actions/actions.actions.spec.ts +1 -6
  108. package/src/stores/actions/actions.actions.ts +16 -19
  109. package/src/stores/actions/actions.reducers.spec.ts +1 -6
  110. package/src/stores/actions/actions.reducers.ts +1 -6
  111. package/src/stores/actions/actions.selectors.ts +2 -4
  112. package/src/stores/auth/auth.reducers.ts +1 -4
  113. package/src/stores/auth/auth.selectors.spec.ts +1 -5
  114. package/src/stores/auth/auth.selectors.ts +3 -6
  115. package/src/stores/auth/auth.utils.tsx +2 -8
  116. package/src/stores/auth/getAccess.action.spec.ts +11 -54
  117. package/src/stores/auth/getAccess.action.ts +1 -6
  118. package/src/stores/auth/initAuth.action.ts +15 -17
  119. package/src/stores/form/form.actions.spec.ts +8 -39
  120. package/src/stores/form/form.actions.ts +55 -64
  121. package/src/stores/form/form.reducers.spec.ts +1 -7
  122. package/src/stores/form/form.reducers.ts +1 -8
  123. package/src/stores/form/form.selectors.ts +1 -2
  124. package/src/stores/forms/forms.actions.spec.ts +5 -18
  125. package/src/stores/forms/forms.actions.ts +17 -21
  126. package/src/stores/forms/forms.reducers.spec.ts +1 -6
  127. package/src/stores/forms/forms.reducers.ts +2 -13
  128. package/src/stores/forms/forms.selectors.ts +2 -4
  129. package/src/stores/index.spec.ts +6 -9
  130. package/src/stores/root/root.selectors.spec.ts +1 -6
  131. package/src/stores/root/root.selectors.ts +6 -24
  132. package/src/stores/submission/submission.actions.spec.ts +11 -33
  133. package/src/stores/submission/submission.actions.ts +57 -66
  134. package/src/stores/submission/submission.reducers.spec.ts +17 -27
  135. package/src/stores/submission/submission.reducers.ts +1 -4
  136. package/src/stores/submission/submission.selectors.ts +1 -4
  137. package/src/stores/submissions/submissions.actions.spec.ts +5 -18
  138. package/src/stores/submissions/submissions.actions.ts +17 -26
  139. package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
  140. package/src/stores/submissions/submissions.reducers.ts +3 -17
  141. package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
  142. package/src/stores/submissions/submissions.selectors.ts +2 -4
  143. package/src/utils/getEventValue.ts +1 -4
  144. package/src/utils/iconClass.ts +2 -10
  145. package/src/utils/mapPagination.ts +1 -6
  146. package/src/utils/mapRequestParams.ts +2 -12
  147. package/src/utils/url.test.ts +4 -12
  148. package/src/utils/url.ts +2 -7
  149. package/tsconfig.json +4 -12
  150. package/tsconfig.test.json +1 -1
  151. package/.eslintrc +0 -47
  152. package/.prettierrc +0 -10
@@ -3,13 +3,13 @@ import { iconClass } from "../../utils/iconClass";
3
3
  import { InputTags } from "./inputTags.component";
4
4
 
5
5
  const useValue = (args: any) => {
6
- const [value, useValue] = useState(args.value);
6
+ const [value, setValue] = useState(args.value);
7
7
 
8
8
  return {
9
9
  ...args,
10
10
  value,
11
11
  onChange(name: string, value: any) {
12
- useValue(value);
12
+ setValue(value);
13
13
  args.onChange(name, value);
14
14
  }
15
15
  };
@@ -72,12 +72,7 @@ Sandbox.args = {
72
72
  };
73
73
 
74
74
  export const WithPrefix = (args: any) => {
75
- return (
76
- <InputTags
77
- prefix={<i className={iconClass(undefined, "calendar")} />}
78
- {...useValue(args)}
79
- />
80
- );
75
+ return <InputTags prefix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
81
76
  };
82
77
 
83
78
  WithPrefix.args = {
@@ -89,12 +84,7 @@ WithPrefix.args = {
89
84
  };
90
85
 
91
86
  export const WithSuffix = (args: any) => {
92
- return (
93
- <InputTags
94
- suffix={<i className={iconClass(undefined, "calendar")} />}
95
- {...useValue(args)}
96
- />
97
- );
87
+ return <InputTags suffix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
98
88
  };
99
89
 
100
90
  WithSuffix.args = {
@@ -0,0 +1,56 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react";
3
+ import { Sandbox } from "./inputText.stories";
4
+
5
+ describe("input-text", () => {
6
+ it("should display the input-text component", () => {
7
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} />);
8
+ const input = getByTestId("input_test") as HTMLInputElement;
9
+
10
+ expect(input).toBeInTheDocument();
11
+ });
12
+
13
+ it("should display the input-text component with a different size", () => {
14
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} size='small' />);
15
+ const input = getByTestId("input_test") as HTMLInputElement;
16
+
17
+ expect(input).toBeInTheDocument();
18
+ expect(input).toHaveClass("form-control-small");
19
+ });
20
+
21
+ it("should display the input-text with placeholder", () => {
22
+ const placeholderTest = "placeholder test";
23
+
24
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
25
+ const input = getByTestId("input_test") as HTMLInputElement;
26
+
27
+ expect(input).toBeInTheDocument();
28
+ expect(input).toHaveDisplayValue(placeholderTest);
29
+ });
30
+
31
+ it("should change the value of the input-text", () => {
32
+ const placeholderTest = "placeholder test";
33
+
34
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
35
+ const input = getByTestId("input_test") as HTMLInputElement;
36
+
37
+ expect(input).toBeInTheDocument();
38
+ fireEvent.change(input, { target: { value: "newValue" } });
39
+ expect(input.value).toBe("newValue");
40
+ expect(input).not.toHaveDisplayValue(placeholderTest);
41
+ expect(input).toHaveDisplayValue("newValue");
42
+ });
43
+ it("should NOT change the value of the input-text if the value is NOT of type number", () => {
44
+ const placeholderTest = "placeholder test";
45
+
46
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} type='number' name={"test"} placeholder={placeholderTest} />);
47
+ const input = getByTestId("input_test") as HTMLInputElement;
48
+
49
+ expect(input).toBeInTheDocument();
50
+ fireEvent.change(input, { target: { value: "newValue" } });
51
+ expect(input).not.toHaveDisplayValue("newValue");
52
+ fireEvent.change(input, { target: { value: 1234 } });
53
+ expect(input.value).toBe("1234");
54
+ expect(input).toHaveDisplayValue("1234");
55
+ });
56
+ });
@@ -3,10 +3,7 @@ import PropTypes from "prop-types";
3
3
  import React, { useEffect, useMemo, useState } from "react";
4
4
  import { callLast } from "../../utils/callLast";
5
5
  import { getEventValue } from "../../utils/getEventValue";
6
- import {
7
- FormControl,
8
- FormControlProps
9
- } from "../form-control/formControl.component";
6
+ import { FormControl, FormControlProps } from "../form-control/formControl.component";
10
7
 
11
8
  export interface InputTextProps<T = any> extends FormControlProps {
12
9
  type?: string;
@@ -33,6 +30,7 @@ export function InputText<T = any>({
33
30
  suffix,
34
31
  description,
35
32
  className,
33
+ placeholder,
36
34
  ...props
37
35
  }: InputTextProps<T>) {
38
36
  const [localValue, setValue] = useState(value);
@@ -60,7 +58,8 @@ export function InputText<T = any>({
60
58
  className={classnames("form-control", size && `form-control-${size}`)}
61
59
  id={name}
62
60
  required={required}
63
- value={(localValue || "") as any}
61
+ value={(localValue || placeholder || "") as any}
62
+ placeholder={placeholder}
64
63
  onChange={(event) => {
65
64
  const value = getEventValue(event);
66
65
  setValue(value);
@@ -3,13 +3,13 @@ import { iconClass } from "../../utils/iconClass";
3
3
  import { InputText } from "./inputText.component";
4
4
 
5
5
  const useValue = (args: any) => {
6
- const [value, useValue] = useState(args.value);
6
+ const [value, setValue] = useState(args.value);
7
7
 
8
8
  return {
9
9
  ...args,
10
10
  value,
11
11
  onChange(name: string, value: any) {
12
- useValue(value);
12
+ setValue(value);
13
13
  args.onChange(name, value);
14
14
  }
15
15
  };
@@ -77,12 +77,7 @@ Sandbox.args = {
77
77
  };
78
78
 
79
79
  export const WithPrefix = (args: any) => {
80
- return (
81
- <InputText
82
- prefix={<i className={iconClass(undefined, "calendar")} />}
83
- {...useValue(args)}
84
- />
85
- );
80
+ return <InputText prefix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
86
81
  };
87
82
 
88
83
  WithPrefix.args = {
@@ -93,12 +88,7 @@ WithPrefix.args = {
93
88
  };
94
89
 
95
90
  export const WithSuffix = (args: any) => {
96
- return (
97
- <InputText
98
- suffix={<i className={iconClass(undefined, "calendar")} />}
99
- {...useValue(args)}
100
- />
101
- );
91
+ return <InputText suffix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
102
92
  };
103
93
 
104
94
  WithSuffix.args = {
@@ -109,12 +99,7 @@ WithSuffix.args = {
109
99
  };
110
100
 
111
101
  export const TypeNumber = (args: any) => {
112
- return (
113
- <InputText
114
- suffix={<i className={iconClass(undefined, "dollar")} />}
115
- {...useValue(args)}
116
- />
117
- );
102
+ return <InputText suffix={<i className={iconClass(undefined, "dollar")} />} {...useValue(args)} />;
118
103
  };
119
104
 
120
105
  TypeNumber.args = {
@@ -127,12 +112,7 @@ TypeNumber.args = {
127
112
  };
128
113
 
129
114
  export const Sizing = (args: any) => {
130
- return (
131
- <InputText
132
- suffix={<i className={iconClass(undefined, "dollar")} />}
133
- {...useValue(args)}
134
- />
135
- );
115
+ return <InputText suffix={<i className={iconClass(undefined, "dollar")} />} {...useValue(args)} />;
136
116
  };
137
117
 
138
118
  Sizing.args = {
@@ -1,21 +1,22 @@
1
1
  import { render } from "@testing-library/react";
2
2
  import React from "react";
3
- import { Loader } from "./loader.component";
4
-
3
+ import { Sandbox } from "./loader.stories";
5
4
  describe("Loader", () => {
6
- it("should render a component (with isActive = true)", () => {
7
- const { getByTestId } = render(<Loader isActive={true} />);
5
+ it("should render a component (when isActive = true)", () => {
6
+ const { getByTestId } = render(<Sandbox isActive={true} />);
8
7
 
9
8
  const icon = getByTestId("icon_radio-circle");
10
9
 
11
10
  expect(icon).toBeTruthy();
11
+ expect(icon).toBeInTheDocument();
12
12
  });
13
13
 
14
- it("should render a component (with isActive = false)", () => {
15
- const { queryByTestId } = render(<Loader isActive={false} />);
14
+ it("should render a component (when isActive = false)", () => {
15
+ const { queryByTestId } = render(<Sandbox isActive={false} />);
16
16
 
17
17
  const icon = queryByTestId("icon_radio-circle");
18
18
 
19
19
  expect(icon).toBeFalsy();
20
+ expect(icon).not.toBeInTheDocument();
20
21
  });
21
22
  });
@@ -1,6 +1,6 @@
1
1
  import classnames from "classnames";
2
2
  import PropTypes from "prop-types";
3
- import React from "react";
3
+ import React, { PropsWithChildren } from "react";
4
4
  import { iconClass } from "../../utils/iconClass";
5
5
 
6
6
  export interface LoaderProps {
@@ -10,12 +10,7 @@ export interface LoaderProps {
10
10
  className?: string;
11
11
  }
12
12
 
13
- export function Loader({
14
- isActive,
15
- color = "blue",
16
- icon = "radio-circle",
17
- className = ""
18
- }: LoaderProps) {
13
+ export function Loader({ isActive, color = "blue", icon = "radio-circle", className = "" }: PropsWithChildren<LoaderProps>) {
19
14
  if (isActive) {
20
15
  return (
21
16
  <div
@@ -24,11 +19,7 @@ export function Loader({
24
19
  className
25
20
  )}
26
21
  >
27
- <span
28
- data-testid={`icon_${icon}`}
29
- color={color}
30
- className={`text-11xl ${iconClass(undefined, icon, true)}`}
31
- />
22
+ <span data-testid={`icon_${icon}`} color={color} className={`text-11xl ${iconClass(undefined, icon, true)}`} />
32
23
  </div>
33
24
  );
34
25
  }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { Loader } from "./loader.component";
3
+
4
+ export default {
5
+ title: "ReactFormio/Loader",
6
+ component: Loader,
7
+ argTypes: {},
8
+ parameters: {}
9
+ };
10
+
11
+ export const Sandbox = (args: any) => {
12
+ return <Loader {...args} />;
13
+ };
14
+
15
+ Sandbox.args = {
16
+ isActive: true
17
+ };
@@ -1,5 +1,5 @@
1
1
  import "@testing-library/jest-dom/extend-expect";
2
- import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
3
  import React from "react";
4
4
  import { WithFooter, WithTitle } from "./modal.stories";
5
5
 
@@ -8,9 +8,7 @@ describe("Modal", () => {
8
8
  it("should display the modal when we click on the button", async () => {
9
9
  const onClose = jest.fn();
10
10
 
11
- const { queryByTestId, getByTestId } = render(
12
- <WithTitle {...WithTitle.args} onClose={onClose} />
13
- );
11
+ const { queryByTestId, getByTestId, findByTestId } = render(<WithTitle {...WithTitle.args} onClose={onClose} />);
14
12
 
15
13
  expect(queryByTestId("modalTitle")).toBeFalsy();
16
14
  expect(queryByTestId("modalBody")).toBeFalsy();
@@ -18,7 +16,7 @@ describe("Modal", () => {
18
16
 
19
17
  fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
20
18
 
21
- await waitFor(() => getByTestId("modalTitle"));
19
+ await findByTestId("modalTitle");
22
20
 
23
21
  expect(getByTestId("modalTitle")).toBeTruthy();
24
22
  expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
@@ -37,9 +35,7 @@ describe("Modal", () => {
37
35
 
38
36
  describe("WithFooter", () => {
39
37
  it("should display the modal when we click on the button", async () => {
40
- const { getByRole, queryByTestId, getByTestId } = render(
41
- <WithFooter {...WithFooter.args} />
42
- );
38
+ const { getByRole, queryByTestId, getByTestId, findByTestId } = render(<WithFooter {...WithFooter.args} />);
43
39
 
44
40
  expect(queryByTestId("modalTitle")).toBeFalsy();
45
41
  expect(queryByTestId("modalBody")).toBeFalsy();
@@ -47,13 +43,13 @@ describe("Modal", () => {
47
43
 
48
44
  fireEvent.click(getByRole("button", { name: "Open modal" }));
49
45
 
50
- await waitFor(() => getByTestId("modalTitle"));
46
+ await findByTestId("modalTitle");
51
47
 
52
48
  expect(getByTestId("modalTitle")).toBeTruthy();
53
49
  expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
54
50
  expect(getByTestId("modalBody")).toBeTruthy();
55
51
  expect(getByTestId("modalBody")).toHaveTextContent("Hello body");
56
- expect(queryByTestId("modalFooter")).toBeTruthy();
52
+ expect(getByTestId("modalFooter")).toBeTruthy();
57
53
 
58
54
  fireEvent.click(screen.getByTestId("customCloseModal"));
59
55
 
@@ -63,13 +59,11 @@ describe("Modal", () => {
63
59
  });
64
60
  it("should call the onSubmit listener", async () => {
65
61
  const onSubmit = jest.fn();
66
- const { getByRole, queryByTestId, getByTestId } = render(
67
- <WithFooter {...WithFooter.args} onSubmit={onSubmit} />
68
- );
62
+ const { getByRole, queryByTestId, findByTestId } = render(<WithFooter {...WithFooter.args} onSubmit={onSubmit} />);
69
63
 
70
64
  fireEvent.click(getByRole("button", { name: "Open modal" }));
71
65
 
72
- await waitFor(() => getByTestId("modalTitle"));
66
+ await findByTestId("modalTitle");
73
67
 
74
68
  fireEvent.click(screen.getByTestId("customSubmitModal"));
75
69
 
@@ -48,9 +48,7 @@ export function Modal({
48
48
 
49
49
  useEffect(() => {
50
50
  if (titleRef.current || footerRef.current) {
51
- const height =
52
- (titleRef?.current?.offsetHeight || 0) +
53
- (footerRef?.current?.offsetHeight || 0);
51
+ const height = (titleRef?.current?.offsetHeight || 0) + (footerRef?.current?.offsetHeight || 0);
54
52
 
55
53
  setMaxHeight(`calc(85vh - ${height}px)`);
56
54
  } else {
@@ -63,42 +61,23 @@ export function Modal({
63
61
  }
64
62
 
65
63
  return (
66
- <div
67
- role={"dialog"}
68
- className={`formio-dialog formio-dialog-theme-default ${className}`}
69
- >
64
+ <div role={"dialog"} className={`formio-dialog formio-dialog-theme-default ${className}`}>
70
65
  <div className='formio-dialog-overlay' onClick={onClickClose} />
71
66
  <div style={style} className={"formio-dialog-content"}>
72
67
  <div className={"formio-dialog-wrapper"}>
73
68
  {title ? (
74
- <div
75
- className={"formio-dialog-title"}
76
- ref={titleRef}
77
- data-testid={"modalTitle"}
78
- >
69
+ <div className={"formio-dialog-title"} ref={titleRef} data-testid={"modalTitle"}>
79
70
  {title}
80
71
  </div>
81
72
  ) : null}
82
73
 
83
- <div
84
- className='formio-dialog-body'
85
- style={{ maxHeight }}
86
- data-testid={"modalBody"}
87
- >
74
+ <div className='formio-dialog-body' style={{ maxHeight }} data-testid={"modalBody"}>
88
75
  {show && children}
89
76
  </div>
90
77
 
91
78
  {ModalFooter ? (
92
- <div
93
- className={"formio-dialog-footer"}
94
- ref={footerRef}
95
- data-testid={"modalFooter"}
96
- >
97
- <ModalFooter
98
- {...props}
99
- closeModal={closeModal}
100
- onClose={onClickClose}
101
- />
79
+ <div className={"formio-dialog-footer"} ref={footerRef} data-testid={"modalFooter"}>
80
+ <ModalFooter {...props} closeModal={closeModal} onClose={onClickClose} />
102
81
  </div>
103
82
  ) : null}
104
83
  </div>
@@ -81,11 +81,7 @@ export const WithFooter = (args: ModalProps) => {
81
81
  Save
82
82
  </button>
83
83
 
84
- <button
85
- data-testid='customCloseModal'
86
- className={"btn btn-danger mx-1"}
87
- onClick={closeModal}
88
- >
84
+ <button data-testid='customCloseModal' className={"btn btn-danger mx-1"} onClick={closeModal}>
89
85
  Close
90
86
  </button>
91
87
  </div>
@@ -5,20 +5,10 @@ import { iconClass } from "../../utils/iconClass";
5
5
  import { InputText } from "../input-text/inputText.component";
6
6
  import { Modal, ModalProps } from "./modal.component";
7
7
 
8
- function RemoveModalFooter({
9
- value,
10
- valueToCompare,
11
- onSubmit,
12
- onClose,
13
- i18n = (f: string) => f
14
- }: ModalProps) {
8
+ function RemoveModalFooter({ value, valueToCompare, onSubmit, onClose, i18n = (f: string) => f }: ModalProps) {
15
9
  return (
16
10
  <div className={"flex items-center justify-center bg-white p-2"}>
17
- <button
18
- data-testid='customCloseModal'
19
- className={"btn btn-outline-dark mx-2"}
20
- onClick={onClose}
21
- >
11
+ <button data-testid='customCloseModal' className={"btn btn-outline-dark mx-2"} onClick={onClose}>
22
12
  {i18n("Cancel")}
23
13
  </button>
24
14
  <button
@@ -45,11 +35,7 @@ export interface RemoveModalProps extends ModalProps {
45
35
  maxWidth?: string;
46
36
  }
47
37
 
48
- export function RemoveModal({
49
- maxWidth = "300px",
50
- children,
51
- ...props
52
- }: PropsWithChildren<RemoveModalProps>) {
38
+ export function RemoveModal({ maxWidth = "300px", children, ...props }: PropsWithChildren<RemoveModalProps>) {
53
39
  const { i18n = noop } = props;
54
40
  const [value, setValue] = useState();
55
41
 
@@ -70,11 +56,7 @@ export function RemoveModal({
70
56
  <strong>&quot;{props.itemType?.toLowerCase()}&quot;</strong>&nbsp;
71
57
  {i18n("name")} <strong>&quot;{props.valueToCompare}&quot;</strong>.
72
58
  </div>
73
- <InputText
74
- name='remove'
75
- value={value}
76
- onChange={(name, value) => setValue(value)}
77
- />
59
+ <InputText name='remove' value={value} onChange={(name, value) => setValue(value)} />
78
60
  </div>
79
61
  </Modal>
80
62
  );
@@ -0,0 +1,111 @@
1
+ import { render, screen, fireEvent } from "@testing-library/react";
2
+ import React from "react";
3
+ import { Sandbox } from "./pagination.stories";
4
+
5
+ describe("Pagination", () => {
6
+ it("should render the pagination component", () => {
7
+ const { container, getByTestId, queryAllByTestId } = render(<Sandbox {...Sandbox.args} />);
8
+ const paginationBtn = queryAllByTestId("pagination-button");
9
+ const allBtnBlocks = paginationBtn.map((bloc) => bloc.textContent);
10
+ const select = getByTestId("select_page");
11
+
12
+ expect(container).toBeInTheDocument();
13
+ paginationBtn.forEach((child) => expect(child).toBeInTheDocument());
14
+ expect(select).toBeInTheDocument();
15
+ expect(allBtnBlocks[0]).toBe("Previous");
16
+ expect(allBtnBlocks[allBtnBlocks.length - 1]).toBe("Next");
17
+ });
18
+
19
+ it("should call previousPage() callback", () => {
20
+ const previousPageSpy = jest.fn();
21
+ const { queryAllByTestId } = render(<Sandbox previousPage={previousPageSpy} canPreviousPage={true} />);
22
+ const paginationBtn = queryAllByTestId("pagination-button");
23
+ const btnPreviousPage = paginationBtn.find((btn) => btn.textContent === "Previous");
24
+
25
+ fireEvent.click(btnPreviousPage);
26
+
27
+ expect(previousPageSpy).toHaveBeenCalledTimes(1);
28
+ });
29
+
30
+ it("should call nextPage() callback", () => {
31
+ const nextPageSpy = jest.fn();
32
+ render(<Sandbox nextPage={nextPageSpy} canNextPage={true} />);
33
+
34
+ fireEvent.click(screen.getByText(/Next/i));
35
+
36
+ expect(nextPageSpy).toHaveBeenCalledTimes(1);
37
+ });
38
+
39
+ it("should call gotoPage() callback when cliking on a button page", () => {
40
+ const gotoPageSpy = jest.fn();
41
+ let page: number;
42
+
43
+ const { queryAllByTestId } = render(<Sandbox {...Sandbox.args} gotoPage={gotoPageSpy} />);
44
+ const paginationBtn = queryAllByTestId("pagination-button");
45
+ const buttonsPage = paginationBtn.filter((btn) => btn.textContent !== "Previous" && btn.textContent !== "Next");
46
+
47
+ buttonsPage.forEach((btn) => {
48
+ if (btn.textContent !== "...") {
49
+ page = +btn.textContent;
50
+ fireEvent.click(btn);
51
+ // eslint-disable-next-line jest/no-conditional-expect
52
+ expect(gotoPageSpy).toHaveBeenCalled();
53
+ // eslint-disable-next-line jest/no-conditional-expect
54
+ expect(gotoPageSpy).toHaveBeenCalledWith(page - 1);
55
+ }
56
+ });
57
+ });
58
+
59
+ it("should have Previous button disabled and not clickable", () => {
60
+ const previousPageSpy = jest.fn();
61
+ const { getByText } = render(<Sandbox canPreviousPage={false} previousPage={previousPageSpy} {...Sandbox.args} />);
62
+ const previousButton = getByText("Previous");
63
+
64
+ expect(previousButton).toHaveAttribute("disabled");
65
+ fireEvent.click(previousButton);
66
+ expect(previousPageSpy).not.toHaveBeenCalled();
67
+ });
68
+
69
+ it("should have Previous button NOT disabled and clickable", () => {
70
+ const previousPageSpy = jest.fn();
71
+ const { getByText } = render(<Sandbox {...Sandbox.args} canPreviousPage={true} previousPage={previousPageSpy} />);
72
+
73
+ const previousButton = getByText("Previous");
74
+
75
+ expect(previousButton).not.toHaveAttribute("disabled");
76
+ fireEvent.click(previousButton);
77
+ expect(previousPageSpy).toHaveBeenCalled();
78
+ });
79
+
80
+ it("should have Next button disabled and not clickable", () => {
81
+ const nextPageSpy = jest.fn();
82
+ const { getByText } = render(<Sandbox canNextPage={false} nextPage={nextPageSpy} {...Sandbox.args} />);
83
+
84
+ const nextButton = getByText("Next");
85
+ expect(nextButton).toHaveAttribute("disabled");
86
+ fireEvent.click(nextButton);
87
+ expect(nextPageSpy).not.toHaveBeenCalled();
88
+ });
89
+
90
+ it("should have Next button NOT disabled and clickable", () => {
91
+ const nextPageSpy = jest.fn();
92
+ const { getByText } = render(<Sandbox canNextPage={true} nextPage={nextPageSpy} {...Sandbox.args} />);
93
+ const nextButton = getByText("Next");
94
+ expect(nextButton).not.toHaveAttribute("disabled");
95
+ fireEvent.click(nextButton);
96
+ expect(nextPageSpy).toHaveBeenCalled();
97
+ });
98
+
99
+ it("should correctly render select component", () => {
100
+ const pageSizes = [10, 25, 50, 100, 200, 500];
101
+
102
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} pageSizes={pageSizes} />);
103
+ const selectComp = getByTestId("select_page");
104
+ const selectChilds = Array.prototype.map.call(selectComp, function (child) {
105
+ return +child.textContent;
106
+ });
107
+
108
+ expect(selectComp).toBeInTheDocument();
109
+ expect(selectChilds.length === pageSizes.length).toBeTruthy();
110
+ });
111
+ });