@griddo/ax 1.65.10 → 1.65.13

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.
@@ -0,0 +1,277 @@
1
+ import React from "react";
2
+ import ArrayFieldGroup from "./index";
3
+ import { ThemeProvider } from "styled-components";
4
+ import { parseTheme } from "@griddo/core";
5
+ import globalTheme from "../../../themes/theme.json";
6
+ import { render, screen, fireEvent, cleanup, act } from "@testing-library/react";
7
+ import { mock } from "jest-mock-extended";
8
+ import FieldsBehavior from "@ax/components/FieldsBehavior";
9
+
10
+ afterEach(cleanup);
11
+
12
+ const defaultProps = mock<IProps>();
13
+
14
+ describe("ArrayFieldGroup component rendering", () => {
15
+ it("should render the component with no items and button", async () => {
16
+ await act(async () => {
17
+ render(
18
+ <ThemeProvider theme={parseTheme(globalTheme)}>
19
+ <ArrayFieldGroup {...defaultProps} />
20
+ </ThemeProvider>
21
+ );
22
+ });
23
+
24
+ expect(screen.getByTestId("buttonLineInverse")).toBeTruthy();
25
+ });
26
+
27
+ it("should render the component with ArrayFieldInline", async () => {
28
+ defaultProps.value = [
29
+ {
30
+ id: "b71c3180-1cf2-4f69-8248-5fcb6e579377",
31
+ semTitle: "dsa",
32
+ subjects: [
33
+ {
34
+ id: "3ae4be00-9216-422d-a841-0448e305af08",
35
+ subjTeachers: {
36
+ mode: "manual",
37
+ fixed: [4476, 4425],
38
+ },
39
+ subjTitle: "as",
40
+ subjType: "das",
41
+ },
42
+ ],
43
+ },
44
+ ];
45
+ const fieldProps = {
46
+ objKey: "semTitle",
47
+ fieldType: "TextField",
48
+ innerFields: [],
49
+ field: {
50
+ title: "Title",
51
+ type: "TextField",
52
+ key: "semTitle",
53
+ mandatory: "true",
54
+ isTitle: true,
55
+ },
56
+ title: "Title",
57
+ type: "TextField",
58
+ mandatory: "true",
59
+ isTitle: true,
60
+ theme: "default-theme",
61
+ };
62
+ defaultProps.innerFields = [<FieldsBehavior {...fieldProps} key={1} />];
63
+ defaultProps.arrayType = "inline";
64
+
65
+ // rendering with innerFields in props
66
+ await act(async () => {
67
+ render(
68
+ <ThemeProvider theme={parseTheme(globalTheme)}>
69
+ <ArrayFieldGroup {...defaultProps} />
70
+ </ThemeProvider>
71
+ );
72
+ });
73
+
74
+ expect(screen.getByTestId("buttonLineInverse")).toBeTruthy();
75
+ expect(screen.getByTestId("arrayFieldInline")).toBeTruthy();
76
+
77
+ const fieldProps2 = {
78
+ objKey: "semTitle",
79
+ fieldType: "TextField",
80
+ field: {
81
+ title: "Title",
82
+ type: "TextField",
83
+ key: "semTitle",
84
+ mandatory: "true",
85
+ isTitle: true,
86
+ },
87
+ title: "Title",
88
+ type: "TextField",
89
+ mandatory: "true",
90
+ isTitle: true,
91
+ theme: "default-theme",
92
+ };
93
+ defaultProps.innerFields = [<FieldsBehavior {...fieldProps2} key={1} />];
94
+
95
+ // rendering without innerFields in props
96
+ render(
97
+ <ThemeProvider theme={parseTheme(globalTheme)}>
98
+ <ArrayFieldGroup {...defaultProps} />
99
+ </ThemeProvider>
100
+ );
101
+ });
102
+
103
+ it("should render the component with ArrayFieldItem", async () => {
104
+ defaultProps.value = [
105
+ {
106
+ id: "b71c3180-1cf2-4f69-8248-5fcb6e579377",
107
+ semTitle: "dsa",
108
+ subjects: [
109
+ {
110
+ id: "3ae4be00-9216-422d-a841-0448e305af08",
111
+ subjTeachers: {
112
+ mode: "manual",
113
+ fixed: [4476, 4425],
114
+ },
115
+ subjTitle: "as",
116
+ subjType: "das",
117
+ },
118
+ ],
119
+ },
120
+ ];
121
+ const fieldProps = {
122
+ objKey: "semTitle",
123
+ fieldType: "TextField",
124
+ innerFields: [],
125
+ field: {
126
+ title: "Title",
127
+ type: "TextField",
128
+ key: "semTitle",
129
+ mandatory: "true",
130
+ isTitle: false,
131
+ },
132
+ title: "Title",
133
+ type: "TextField",
134
+ mandatory: "true",
135
+ isTitle: false,
136
+ theme: "default-theme",
137
+ };
138
+
139
+ defaultProps.innerFields = [<FieldsBehavior {...fieldProps} key={1} />];
140
+ defaultProps.arrayType = "item";
141
+
142
+ await act(async () => {
143
+ render(
144
+ <ThemeProvider theme={parseTheme(globalTheme)}>
145
+ <ArrayFieldGroup {...defaultProps} />
146
+ </ThemeProvider>
147
+ );
148
+ });
149
+
150
+ expect(screen.getByTestId("buttonLineInverse")).toBeTruthy();
151
+ expect(screen.getByTestId("arrayFieldItem")).toBeTruthy();
152
+
153
+ const fieldProps2 = {
154
+ objKey: "semTitle",
155
+ fieldType: "TextField",
156
+ field: {
157
+ title: "A Title",
158
+ type: "TextField",
159
+ key: "semTitle",
160
+ mandatory: "true",
161
+ isTitle: true,
162
+ },
163
+ title: "A Title",
164
+ type: "TextField",
165
+ mandatory: "true",
166
+ isTitle: true,
167
+ theme: "default-theme",
168
+ };
169
+ defaultProps.innerFields = [<FieldsBehavior {...fieldProps2} key={1} />];
170
+
171
+ // rendering with isTitle true
172
+ render(
173
+ <ThemeProvider theme={parseTheme(globalTheme)}>
174
+ <ArrayFieldGroup {...defaultProps} />
175
+ </ThemeProvider>
176
+ );
177
+
178
+ expect(screen.getByText("A Title")).toBeTruthy();
179
+ });
180
+ });
181
+
182
+ describe("ArrayFieldGroup component events", () => {
183
+ it("should call the onclick of the button", async () => {
184
+ defaultProps.value = [
185
+ {
186
+ id: "b71c3180-1cf2-4f69-8248-5fcb6e579377",
187
+ semTitle: "dsa",
188
+ subjects: [
189
+ {
190
+ id: "3ae4be00-9216-422d-a841-0448e305af08",
191
+ subjTeachers: {
192
+ mode: "manual",
193
+ fixed: [4476, 4425],
194
+ },
195
+ subjTitle: "as",
196
+ subjType: "das",
197
+ },
198
+ ],
199
+ },
200
+ ];
201
+
202
+ const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: Record<string, unknown>[]) => void>;
203
+
204
+ await act(async () => {
205
+ render(
206
+ <ThemeProvider theme={parseTheme(globalTheme)}>
207
+ <ArrayFieldGroup {...defaultProps} />
208
+ </ThemeProvider>
209
+ );
210
+ });
211
+
212
+ expect(screen.getByTestId("buttonLineInverse")).toBeTruthy();
213
+ fireEvent.click(screen.getByTestId("buttonLineInverse"));
214
+ expect(onChangeMock).toHaveBeenCalled();
215
+ });
216
+
217
+ it("should call the handleDelete with the button", async () => {
218
+ defaultProps.value = [
219
+ {
220
+ id: "b71c3180-1cf2-4f69-8248-5fcb6e579377",
221
+ semTitle: "dsa",
222
+ subjects: [
223
+ {
224
+ id: "3ae4be00-9216-422d-a841-0448e305af08",
225
+ subjTeachers: {
226
+ mode: "manual",
227
+ fixed: [4476, 4425],
228
+ },
229
+ subjTitle: "as",
230
+ subjType: "das",
231
+ },
232
+ ],
233
+ },
234
+ ];
235
+ const fieldProps = {
236
+ objKey: "semTitle",
237
+ fieldType: "TextField",
238
+ innerFields: [],
239
+ field: {
240
+ title: "Title",
241
+ type: "TextField",
242
+ key: "semTitle",
243
+ mandatory: "true",
244
+ isTitle: true,
245
+ },
246
+ title: "Title",
247
+ type: "TextField",
248
+ mandatory: "true",
249
+ isTitle: true,
250
+ theme: "default-theme",
251
+ };
252
+ defaultProps.innerFields = [<FieldsBehavior {...fieldProps} key={1} />];
253
+ defaultProps.arrayType = "inline";
254
+ const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: Record<string, unknown>[]) => void>;
255
+
256
+ await act(async () => {
257
+ render(
258
+ <ThemeProvider theme={parseTheme(globalTheme)}>
259
+ <ArrayFieldGroup {...defaultProps} />
260
+ </ThemeProvider>
261
+ );
262
+ });
263
+
264
+ expect(screen.getByTestId("arrayFieldInline")).toBeTruthy();
265
+ fireEvent.click(screen.getByTestId("iconActionComponent"));
266
+ expect(onChangeMock).toHaveBeenCalled();
267
+ });
268
+ });
269
+
270
+ interface IProps {
271
+ value: Record<string, unknown>[];
272
+ name: string;
273
+ onChange: (value: Record<string, unknown>[]) => void;
274
+ innerFields: any[];
275
+ divider: { title: string; text: string };
276
+ arrayType: string;
277
+ }
@@ -49,7 +49,6 @@ const ArrayFieldGroup = (props: IProps): JSX.Element => {
49
49
  {items &&
50
50
  items.map((item: any, index: number) => {
51
51
  const handleFieldChange = (newValue: Record<string, unknown>) => handleChange(newValue, index);
52
-
53
52
  return arrayType === "inline" ? (
54
53
  <ArrayFieldInline
55
54
  key={item.id}
@@ -0,0 +1,108 @@
1
+ import React from "react";
2
+ import axios from "axios";
3
+ import AsyncCheckGroup from "./index";
4
+ import { ThemeProvider } from "styled-components";
5
+ import { parseTheme } from "@griddo/core";
6
+ import globalTheme from "../../../themes/theme.json";
7
+ import { render, screen, cleanup, act } from "@testing-library/react";
8
+ import { ISite } from "@ax/types";
9
+ import { mock } from "jest-mock-extended";
10
+
11
+ afterEach(cleanup);
12
+
13
+ const defaultProps = mock<IAsyncCheckGroup>();
14
+
15
+ jest.mock("axios");
16
+ const mockedAxios = axios as jest.MockedFunction<typeof axios>;
17
+
18
+ describe("AsyncCheckGroup component rendering", () => {
19
+ afterEach(() => {
20
+ jest.resetAllMocks();
21
+ });
22
+ it("should render the component with 6 options", async () => {
23
+ const defaultSite = mock<ISite>();
24
+ defaultSite.id = 113;
25
+ defaultProps.site = defaultSite;
26
+ defaultProps.value = [3622];
27
+ const data = {
28
+ data: [
29
+ {
30
+ value: 3622,
31
+ name: "Home",
32
+ },
33
+ {
34
+ value: 3731,
35
+ name: "English child",
36
+ },
37
+ {
38
+ value: 3730,
39
+ name: "English Parent",
40
+ },
41
+ {
42
+ value: 3787,
43
+ name: "English test",
44
+ },
45
+ {
46
+ value: 3745,
47
+ name: "New Page",
48
+ },
49
+ {
50
+ value: 3784,
51
+ name: "Prueba",
52
+ },
53
+ ],
54
+ status: 200,
55
+ statusText: "Ok",
56
+ headers: {},
57
+ config: {},
58
+ };
59
+
60
+ mockedAxios.mockResolvedValue(data);
61
+
62
+ await act(async () => {
63
+ render(
64
+ <ThemeProvider theme={parseTheme(globalTheme)}>
65
+ <AsyncCheckGroup {...defaultProps} />
66
+ </ThemeProvider>
67
+ );
68
+ });
69
+
70
+ expect(screen.getAllByTestId("checkFieldLabel")).toHaveLength(6);
71
+ });
72
+
73
+ it("should render the component with no options", async () => {
74
+ defaultProps.source = "source";
75
+ defaultProps.value = [];
76
+
77
+ const data = {
78
+ data: [],
79
+ status: 500,
80
+ statusText: "Internal Server Error",
81
+ headers: {},
82
+ config: {},
83
+ };
84
+
85
+ mockedAxios.mockResolvedValue(data);
86
+
87
+ await act(async () => {
88
+ render(
89
+ <ThemeProvider theme={parseTheme(globalTheme)}>
90
+ <AsyncCheckGroup {...defaultProps} />
91
+ </ThemeProvider>
92
+ );
93
+ });
94
+ expect(screen.queryByTestId("checkFieldLabel")).not.toBeTruthy();
95
+ });
96
+ });
97
+
98
+ interface IAsyncCheckGroup {
99
+ value: any[];
100
+ site?: ISite | null;
101
+ source: string;
102
+ onChange: (value: any) => void;
103
+ disabled?: boolean;
104
+ error?: boolean;
105
+ handleValidation?: (value: string | any[]) => void;
106
+ validators?: Record<string, unknown>;
107
+ fullHeight?: boolean;
108
+ }
@@ -22,7 +22,6 @@ const AsyncCheckGroup = (props: IAsyncCheckGroup): JSX.Element => {
22
22
  let result = null;
23
23
  const siteID = site ? site.id : null;
24
24
  result = await checkgroups.getCheckGroupItems(siteID, source);
25
-
26
25
  if (result && isReqOk(result.status)) {
27
26
  return result.data;
28
27
  }
@@ -59,7 +58,8 @@ const AsyncCheckGroup = (props: IAsyncCheckGroup): JSX.Element => {
59
58
  error && handleValidation && handleValidation(newArrayObject);
60
59
  };
61
60
 
62
- const isChecked = (id: number) => safeValue.find((e: any) => (typeof e === "number" ? e === id : e.value === id));
61
+ const isChecked = (id: number) =>
62
+ safeValue.find((e: any) => (typeof e === "number" ? e === id : (e.value || e.id) === id));
63
63
 
64
64
  const checks =
65
65
  options &&
@@ -80,7 +80,7 @@ const AsyncCheckGroup = (props: IAsyncCheckGroup): JSX.Element => {
80
80
  };
81
81
 
82
82
  interface IAsyncCheckGroup {
83
- value: any[];
83
+ value: any[] | null;
84
84
  site?: ISite | null;
85
85
  source: string;
86
86
  onChange: (value: any) => void;