@griddo/ax 1.65.12 → 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.
- package/package.json +3 -2
- package/src/components/Button/index.tsx +15 -2
- package/src/components/Fields/AnalyticsField/PageAnalytics/index.test.tsx +204 -0
- package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/atoms.tsx +1 -0
- package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/index.test.tsx +146 -0
- package/src/components/Fields/ArrayFieldGroup/ArrayFieldInline/index.tsx +2 -1
- package/src/components/Fields/ArrayFieldGroup/ArrayFieldItem/index.tsx +1 -1
- package/src/components/Fields/ArrayFieldGroup/index.test.tsx +277 -0
- package/src/components/Fields/ArrayFieldGroup/index.tsx +0 -1
- package/src/components/Fields/AsyncCheckGroup/index.test.tsx +108 -0
- package/src/components/Fields/AsyncCheckGroup/index.tsx +1 -2
- package/src/components/Fields/AsyncSelect/index.test.tsx +306 -0
- package/src/components/Fields/AsyncSelect/index.tsx +18 -17
- package/src/components/Fields/HeadingField/index.test.tsx +71 -0
- package/src/components/Fields/HeadingField/index.tsx +1 -1
- package/src/components/Fields/Select/index.tsx +39 -24
- package/src/components/Fields/UrlField/index.tsx +38 -4
- package/src/components/Fields/UrlField/utils.tsx +74 -14
- package/src/components/FieldsBehavior/index.tsx +1 -1
- package/src/types/index.tsx +6 -5
|
@@ -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
|
}
|
|
@@ -81,7 +80,7 @@ const AsyncCheckGroup = (props: IAsyncCheckGroup): JSX.Element => {
|
|
|
81
80
|
};
|
|
82
81
|
|
|
83
82
|
interface IAsyncCheckGroup {
|
|
84
|
-
value: any[];
|
|
83
|
+
value: any[] | null;
|
|
85
84
|
site?: ISite | null;
|
|
86
85
|
source: string;
|
|
87
86
|
onChange: (value: any) => void;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
import AsyncSelect from "./index";
|
|
5
|
+
import { ThemeProvider } from "styled-components";
|
|
6
|
+
import { parseTheme } from "@griddo/core";
|
|
7
|
+
import globalTheme from "../../../themes/theme.json";
|
|
8
|
+
import { render, screen, cleanup, act } from "@testing-library/react";
|
|
9
|
+
import { ISite } from "@ax/types";
|
|
10
|
+
import { mock } from "jest-mock-extended";
|
|
11
|
+
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
|
|
14
|
+
const defaultProps = mock<IAsyncSelectProps>();
|
|
15
|
+
|
|
16
|
+
const defaultSite = mock<ISite>();
|
|
17
|
+
defaultSite.id = 113;
|
|
18
|
+
|
|
19
|
+
jest.mock("axios");
|
|
20
|
+
const mockedAxios = axios as jest.MockedFunction<typeof axios>;
|
|
21
|
+
|
|
22
|
+
describe("AsyncSelect component rendering", () => {
|
|
23
|
+
test("should render the component AsyncSelect", async () => {
|
|
24
|
+
defaultProps.name = "texto de prueba";
|
|
25
|
+
await act(async () => {
|
|
26
|
+
render(
|
|
27
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
28
|
+
<AsyncSelect {...defaultProps} />
|
|
29
|
+
</ThemeProvider>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
expect(screen.getByTestId("asyncSelect")).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("AsyncSelect component events", () => {
|
|
37
|
+
test("should call the api and receive data in pages", async () => {
|
|
38
|
+
defaultProps.site = defaultSite;
|
|
39
|
+
defaultProps.entity = "pages";
|
|
40
|
+
defaultProps.options = {
|
|
41
|
+
excludeDetailPages: true,
|
|
42
|
+
};
|
|
43
|
+
defaultProps.lang = "en_GB";
|
|
44
|
+
defaultProps.selectedContent = { id: 1 };
|
|
45
|
+
defaultProps.value = [3622, 3621];
|
|
46
|
+
|
|
47
|
+
const data = {
|
|
48
|
+
data: [
|
|
49
|
+
{
|
|
50
|
+
value: 3622,
|
|
51
|
+
label: "Home",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: 3731,
|
|
55
|
+
label: "English child",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: 3730,
|
|
59
|
+
label: "English Parent",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
value: 3787,
|
|
63
|
+
label: "English test",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
value: 3745,
|
|
67
|
+
label: "New Page",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
value: 3784,
|
|
71
|
+
label: "Prueba",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
status: 200,
|
|
75
|
+
statusText: "Ok",
|
|
76
|
+
headers: {},
|
|
77
|
+
config: {},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
mockedAxios.mockResolvedValue(data);
|
|
81
|
+
|
|
82
|
+
await act(async () => {
|
|
83
|
+
render(
|
|
84
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
85
|
+
<AsyncSelect {...defaultProps} />
|
|
86
|
+
</ThemeProvider>
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(screen.getByTestId("asyncSelect")).toHaveTextContent("Home");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("should call the api and receive data in pages with no selectedContent", async () => {
|
|
94
|
+
defaultProps.site = defaultSite;
|
|
95
|
+
defaultProps.entity = "pages";
|
|
96
|
+
defaultProps.options = {
|
|
97
|
+
excludeDetailPages: true,
|
|
98
|
+
};
|
|
99
|
+
defaultProps.lang = "en_GB";
|
|
100
|
+
defaultProps.selectedContent = null;
|
|
101
|
+
defaultProps.value = 3622;
|
|
102
|
+
|
|
103
|
+
const data = {
|
|
104
|
+
data: [
|
|
105
|
+
{
|
|
106
|
+
value: 3622,
|
|
107
|
+
label: "Home",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
value: 3731,
|
|
111
|
+
label: "English child",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: 3730,
|
|
115
|
+
label: "English Parent",
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
value: 3787,
|
|
119
|
+
label: "English test",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
value: 3745,
|
|
123
|
+
label: "New Page",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
value: 3784,
|
|
127
|
+
label: "Prueba",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
status: 200,
|
|
131
|
+
statusText: "Ok",
|
|
132
|
+
headers: {},
|
|
133
|
+
config: {},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
mockedAxios.mockResolvedValue(data);
|
|
137
|
+
|
|
138
|
+
await act(async () => {
|
|
139
|
+
render(
|
|
140
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
141
|
+
<AsyncSelect {...defaultProps} />
|
|
142
|
+
</ThemeProvider>
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(screen.getByTestId("asyncSelect")).toHaveTextContent("Home");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("should call the api and receive data in categories", async () => {
|
|
150
|
+
defaultProps.site = defaultSite;
|
|
151
|
+
defaultProps.entity = "categories";
|
|
152
|
+
defaultProps.options = {
|
|
153
|
+
excludeDetailPages: true,
|
|
154
|
+
};
|
|
155
|
+
defaultProps.lang = "en_GB";
|
|
156
|
+
defaultProps.value = 3622;
|
|
157
|
+
|
|
158
|
+
const data = {
|
|
159
|
+
data: [
|
|
160
|
+
{
|
|
161
|
+
value: 3622,
|
|
162
|
+
label: "Home",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
value: 3731,
|
|
166
|
+
label: "English child",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
value: 3730,
|
|
170
|
+
label: "English Parent",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
value: 3787,
|
|
174
|
+
label: "English test",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
value: 3745,
|
|
178
|
+
label: "New Page",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
value: 3784,
|
|
182
|
+
label: "Prueba",
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
status: 200,
|
|
186
|
+
statusText: "Ok",
|
|
187
|
+
headers: {},
|
|
188
|
+
config: {},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
mockedAxios.mockResolvedValue(data);
|
|
192
|
+
|
|
193
|
+
await act(async () => {
|
|
194
|
+
render(
|
|
195
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
196
|
+
<AsyncSelect {...defaultProps} />
|
|
197
|
+
</ThemeProvider>
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
expect(screen.getByTestId("asyncSelect")).toHaveTextContent("Home");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("should call the api and not receiving data", async () => {
|
|
205
|
+
defaultProps.site = defaultSite;
|
|
206
|
+
defaultProps.entity = "categories";
|
|
207
|
+
defaultProps.options = {
|
|
208
|
+
excludeDetailPages: true,
|
|
209
|
+
};
|
|
210
|
+
defaultProps.lang = "en_GB";
|
|
211
|
+
|
|
212
|
+
const data = {
|
|
213
|
+
data: [],
|
|
214
|
+
status: 500,
|
|
215
|
+
statusText: "Ok",
|
|
216
|
+
headers: {},
|
|
217
|
+
config: {},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
mockedAxios.mockResolvedValue(data);
|
|
221
|
+
|
|
222
|
+
await act(async () => {
|
|
223
|
+
render(
|
|
224
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
225
|
+
<AsyncSelect {...defaultProps} />
|
|
226
|
+
</ThemeProvider>
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(screen.getByTestId("asyncSelect")).not.toHaveTextContent("Home");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("should call the api with source", async () => {
|
|
234
|
+
defaultProps.site = defaultSite;
|
|
235
|
+
defaultProps.entity = "categories";
|
|
236
|
+
defaultProps.source = "source";
|
|
237
|
+
defaultProps.options = {
|
|
238
|
+
excludeDetailPages: true,
|
|
239
|
+
};
|
|
240
|
+
defaultProps.lang = "en_GB";
|
|
241
|
+
defaultProps.value = 3787;
|
|
242
|
+
|
|
243
|
+
const data = {
|
|
244
|
+
data: [
|
|
245
|
+
{
|
|
246
|
+
value: 3622,
|
|
247
|
+
title: "Home",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
value: 3731,
|
|
251
|
+
title: "English child",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
value: 3730,
|
|
255
|
+
title: "English Parent",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
value: 3787,
|
|
259
|
+
title: "English test",
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
value: 3745,
|
|
263
|
+
title: "New Page",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
value: 3784,
|
|
267
|
+
title: "Prueba",
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
status: 200,
|
|
271
|
+
statusText: "Ok",
|
|
272
|
+
headers: {},
|
|
273
|
+
config: {},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
mockedAxios.mockResolvedValue(data);
|
|
277
|
+
|
|
278
|
+
await act(async () => {
|
|
279
|
+
render(
|
|
280
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
281
|
+
<AsyncSelect {...defaultProps} />
|
|
282
|
+
</ThemeProvider>
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
expect(screen.getByTestId("asyncSelect")).toHaveTextContent("English test");
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
interface IAsyncSelectProps {
|
|
291
|
+
name: string;
|
|
292
|
+
value: any;
|
|
293
|
+
entity?: string;
|
|
294
|
+
entityId?: string | number;
|
|
295
|
+
error?: boolean;
|
|
296
|
+
disabled?: boolean;
|
|
297
|
+
onChange: (value: string) => void;
|
|
298
|
+
site: ISite;
|
|
299
|
+
lang: string;
|
|
300
|
+
selectedContent: any;
|
|
301
|
+
mandatory?: boolean;
|
|
302
|
+
placeholder?: string;
|
|
303
|
+
filter?: any[];
|
|
304
|
+
options?: any;
|
|
305
|
+
source?: string;
|
|
306
|
+
}
|