@griddo/ax 1.67.9 → 1.68.1
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/config/jest/componentsMock.js +1528 -27
- package/package.json +2 -2
- package/src/__mocks__/reducers/app.tsx +10 -0
- package/src/__mocks__/reducers/sites.tsx +10 -0
- package/src/__tests__/{AnalyticsField.test.tsx → components/Fields/AnalyticsField/AnalyticsField.test.tsx} +5 -5
- package/src/__tests__/{PageAnalytics.test.tsx → components/Fields/AnalyticsField/PageAnalytics/PageAnalytics.test.tsx} +2 -2
- package/src/__tests__/{StructuredDataAnalytics.test.tsx → components/Fields/AnalyticsField/StructuredDataAnalytics/StructuredDataAnalytics.test.tsx} +2 -2
- package/src/__tests__/{ArrayFieldGroup.test.tsx → components/Fields/ArrayFieldGroup/ArrayFieldGroup.test.tsx} +2 -2
- package/src/__tests__/{AsyncCheckGroup.test.tsx → components/Fields/AsyncCheckGroup/AsyncCheckGroup.test.tsx} +2 -2
- package/src/__tests__/{AsyncSelect.test.tsx → components/Fields/AsyncSelect/AsyncSelect.test.tsx} +2 -2
- package/src/__tests__/{CheckField.test.tsx → components/Fields/CheckField/CheckField.test.tsx} +2 -2
- package/src/__tests__/{CheckGroup.test.tsx → components/Fields/CheckGroup/CheckGroup.test.tsx} +2 -2
- package/src/__tests__/components/Fields/ColorPicker/ColorPicker.test.tsx +195 -0
- package/src/__tests__/components/Fields/ComponentArray/ComponentArray.test.tsx +184 -0
- package/src/__tests__/components/Fields/ComponentArray/MixableComponentArray/MixableComponentArray.test.tsx +315 -0
- package/src/__tests__/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton/PasteModuleButton.test.tsx +95 -0
- package/src/__tests__/components/Fields/ComponentArray/SameComponentArray/SameComponentArray.test.tsx +225 -0
- package/src/__tests__/{FieldGroup.test.tsx → components/Fields/FieldGroup/FieldGroup.test.tsx} +2 -2
- package/src/__tests__/components/Fields/FieldsDivider/FieldsDivider.test.tsx +24 -0
- package/src/__tests__/components/Fields/FileField/FileField.test.tsx +135 -0
- package/src/__tests__/{HeadingField.test.tsx → components/Fields/HeadingField/HeadingField.test.tsx} +2 -2
- package/src/__tests__/components/Fields/HiddenField/HiddenField.test.tsx +76 -0
- package/src/__tests__/components/Fields/MultiCheckSelect/MultiCheckSelect.test.tsx +70 -0
- package/src/__tests__/components/Fields/NoteField/NoteField.test.tsx +67 -0
- package/src/__tests__/components/Fields/NumberField/NumberField.test.tsx +109 -0
- package/src/__tests__/components/Fields/RadioField/RadioField.test.tsx +106 -0
- package/src/__tests__/components/Fields/RichText/RichText.test.tsx +52 -0
- package/src/__tests__/components/Fields/Select/Select.test.tsx +75 -0
- package/src/__tests__/components/Fields/SliderField/SliderField.test.tsx +82 -0
- package/src/__tests__/{TagField.test.tsx → components/Fields/TagField/TagField.test.tsx} +2 -2
- package/src/__tests__/{TextArea.test.tsx → components/Fields/TextArea/TextArea.test.tsx} +2 -2
- package/src/__tests__/{TextField.test.tsx → components/Fields/TextField/TextField.test.tsx} +2 -2
- package/src/__tests__/components/Fields/ToggleField/ToggleField.test.tsx +100 -0
- package/src/__tests__/{UniqueCheck.test.tsx → components/Fields/UniqueCheck/UniqueCheck.test.tsx} +2 -2
- package/src/__tests__/components/Fields/UrlField/UrlField.test.tsx +446 -0
- package/src/__tests__/components/Fields/UrlField/mockedAxios.ts +2214 -0
- package/src/__tests__/components/Fields/VisualUniqueSelection/ImageSelection/ImageSelection.test.tsx +99 -0
- package/src/__tests__/components/Fields/VisualUniqueSelection/ScrollableSelection/ScrollableSelection.test.tsx +176 -0
- package/src/__tests__/components/Fields/VisualUniqueSelection/VisualUniqueSelection.test.tsx +78 -0
- package/src/components/ActionMenu/index.tsx +1 -0
- package/src/components/Browser/index.tsx +39 -47
- package/src/components/Browser/style.tsx +15 -15
- package/src/components/BrowserContent/index.tsx +78 -0
- package/src/components/ConfigPanel/Form/ConnectedField/NavConnectedField/index.tsx +3 -5
- package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/index.tsx +2 -6
- package/src/components/ConfigPanel/Header/index.tsx +28 -11
- package/src/components/ConfigPanel/index.tsx +2 -2
- package/src/components/ErrorCenter/index.tsx +11 -4
- package/src/components/Fields/ArrayFieldGroup/index.tsx +4 -2
- package/src/components/Fields/ArrayFieldGroup/style.tsx +7 -0
- package/src/components/Fields/AsyncCheckGroup/index.tsx +1 -1
- package/src/components/Fields/CheckField/index.tsx +1 -1
- package/src/components/Fields/ColorPicker/Picker/index.tsx +9 -3
- package/src/components/Fields/ColorPicker/index.tsx +4 -9
- package/src/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton/index.tsx +2 -1
- package/src/components/Fields/ComponentArray/MixableComponentArray/index.tsx +27 -22
- package/src/components/Fields/ComponentArray/MixableComponentArray/style.tsx +3 -38
- package/src/components/Fields/ComponentArray/SameComponentArray/index.tsx +3 -2
- package/src/components/Fields/ComponentArray/SameComponentArray/style.tsx +1 -28
- package/src/components/Fields/ComponentArray/helpers.tsx +1 -1
- package/src/components/Fields/ComponentContainer/index.tsx +3 -1
- package/src/components/Fields/FileField/FileDragAndDrop/index.tsx +1 -1
- package/src/components/Fields/FileField/FileDragAndDrop/style.tsx +2 -3
- package/src/components/Fields/FileField/index.tsx +6 -6
- package/src/components/Fields/HiddenField/index.tsx +3 -3
- package/src/components/Fields/MultiCheckSelect/index.tsx +8 -27
- package/src/components/Fields/NoteField/index.tsx +3 -3
- package/src/components/Fields/NumberField/index.tsx +6 -3
- package/src/components/Fields/RadioField/index.tsx +10 -2
- package/src/components/Fields/ReferenceField/index.tsx +8 -1
- package/src/components/Fields/ReferenceField/style.tsx +5 -0
- package/src/components/Fields/RichText/index.tsx +1 -1
- package/src/components/Fields/SliderField/index.tsx +11 -7
- package/src/components/Fields/ToggleField/index.tsx +12 -3
- package/src/components/Fields/UrlField/PageFinder/SelectionListItem/index.tsx +1 -1
- package/src/components/Fields/UrlField/index.tsx +6 -4
- package/src/components/Fields/UrlField/style.tsx +4 -2
- package/src/components/Fields/VisualOption/index.tsx +10 -2
- package/src/components/Fields/VisualUniqueSelection/ImageSelection/index.tsx +2 -2
- package/src/components/Fields/VisualUniqueSelection/ScrollableSelection/index.tsx +4 -3
- package/src/components/Fields/VisualUniqueSelection/ScrollableSelection/style.tsx +1 -1
- package/src/components/Fields/VisualUniqueSelection/index.tsx +3 -3
- package/src/components/FieldsBehavior/index.tsx +4 -4
- package/src/components/FieldsBehavior/style.tsx +5 -12
- package/src/components/FloatingMenu/index.tsx +8 -4
- package/src/components/Loader/index.tsx +12 -8
- package/src/components/MainWrapper/AppBar/index.tsx +1 -0
- package/src/components/MainWrapper/index.tsx +1 -0
- package/src/components/Modal/index.tsx +3 -2
- package/src/components/Modal/style.tsx +2 -1
- package/src/components/Toast/index.tsx +1 -1
- package/src/components/Tooltip/index.tsx +1 -1
- package/src/components/index.tsx +2 -0
- package/src/containers/App/actions.tsx +3 -7
- package/src/containers/PageEditor/actions.tsx +36 -5
- package/src/forms/editor.tsx +35 -1
- package/src/forms/fields.tsx +6 -2
- package/src/forms/index.tsx +2 -0
- package/src/forms/validators.tsx +29 -8
- package/src/guards/error/index.tsx +1 -1
- package/src/helpers/containerEvaluations.tsx +32 -4
- package/src/helpers/index.tsx +2 -0
- package/src/helpers/structuredData.tsx +2 -2
- package/src/hooks/forms.tsx +1 -28
- package/src/hooks/index.tsx +1 -2
- package/src/modules/Content/atoms.tsx +1 -0
- package/src/modules/FramePreview/index.tsx +70 -36
- package/src/modules/FramePreview/style.tsx +3 -0
- package/src/modules/GlobalEditor/PageBrowser/index.tsx +2 -7
- package/src/modules/GlobalEditor/index.tsx +8 -6
- package/src/modules/GlobalEditor/style.tsx +1 -1
- package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/DefaultsBrowser/index.tsx +0 -4
- package/src/modules/Navigation/Defaults/DefaultsEditor/index.tsx +3 -2
- package/src/modules/PageEditor/PageBrowser/index.tsx +1 -4
- package/src/modules/PageEditor/index.tsx +6 -6
- package/src/modules/PublicPreview/index.tsx +17 -34
- package/src/modules/PublicPreview/style.tsx +0 -2
- package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/TemplateConfig/TemplateEditor/Editor/TemplateBrowser/index.tsx +0 -4
- package/src/modules/Sites/index.tsx +1 -1
- package/src/modules/StructuredData/Form/ConnectedField/index.tsx +1 -1
- package/src/modules/StructuredData/Form/index.tsx +3 -1
- package/src/modules/StructuredData/StructuredDataList/index.tsx +1 -0
- package/src/schemas/pages/GlobalPage.tsx +1 -0
- package/src/types/index.tsx +1 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import MixableComponentArray from "@ax/components/Fields/ComponentArray/MixableComponentArray";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseTheme } from "@griddo/core";
|
|
5
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
6
|
+
import { IModule } from "@ax/types";
|
|
7
|
+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
8
|
+
import { mock } from "jest-mock-extended";
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
|
|
12
|
+
const mixableProps = mock<IMixableComponentArrayProps>();
|
|
13
|
+
const mixableModule = mock<IModule>();
|
|
14
|
+
const otherMixableModule = mock<IModule>();
|
|
15
|
+
// default values for MixableComponentArray
|
|
16
|
+
mixableModule.editorID = 1;
|
|
17
|
+
mixableModule.component = "HeroCard";
|
|
18
|
+
mixableModule.title = "Cards";
|
|
19
|
+
mixableModule.modules = [];
|
|
20
|
+
otherMixableModule.editorID = 2;
|
|
21
|
+
otherMixableModule.component = "HeroCard";
|
|
22
|
+
otherMixableModule.title = "Hero Section";
|
|
23
|
+
otherMixableModule.modules = [];
|
|
24
|
+
mixableProps.field = { type: "components" };
|
|
25
|
+
const testModule = {
|
|
26
|
+
value: {
|
|
27
|
+
editorID: 1,
|
|
28
|
+
component: "HeroCard",
|
|
29
|
+
title: "Cards",
|
|
30
|
+
modules: [],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
// test for old value prop (it wasn't an array)
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
mixableProps.value = testModule;
|
|
37
|
+
mixableProps.activatedModules = ["HeroSection"];
|
|
38
|
+
mixableProps.whiteList = [];
|
|
39
|
+
mixableProps.moduleCopy = null;
|
|
40
|
+
|
|
41
|
+
describe("ComponentArraySelector component rendering", () => {
|
|
42
|
+
test("should render the component with MixableComponentArray", () => {
|
|
43
|
+
mixableProps.disabled = true;
|
|
44
|
+
mixableProps.editorID = 1;
|
|
45
|
+
render(
|
|
46
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
47
|
+
<MixableComponentArray {...mixableProps} />
|
|
48
|
+
</ThemeProvider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(screen.getAllByTestId("mixableComponentWrapper")).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("should render the AddItemButton", () => {
|
|
55
|
+
otherMixableModule.editorID = 5;
|
|
56
|
+
otherMixableModule.component = "HeroCard";
|
|
57
|
+
otherMixableModule.title = "Hero Section";
|
|
58
|
+
otherMixableModule.modules = [];
|
|
59
|
+
mixableProps.value = [mixableModule, otherMixableModule];
|
|
60
|
+
mixableProps.field = { contentType: "modules" };
|
|
61
|
+
mixableProps.objKey = "elements";
|
|
62
|
+
mixableProps.disabled = false;
|
|
63
|
+
mixableProps.maxItems = 10;
|
|
64
|
+
mixableProps.actions = {
|
|
65
|
+
addModuleAction: jest.fn(),
|
|
66
|
+
addComponentAction: jest.fn(),
|
|
67
|
+
deleteModuleAction: jest.fn(),
|
|
68
|
+
replaceElementsInCollectionAction: jest.fn(),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
render(
|
|
72
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
73
|
+
<MixableComponentArray {...mixableProps} />
|
|
74
|
+
</ThemeProvider>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect(screen.getAllByTestId("iconActionComponent")).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Test incompleto. Lo dejo por si lo podemos reaprovechar más adelante
|
|
81
|
+
/*
|
|
82
|
+
test("should render the SideModal", () => {
|
|
83
|
+
otherMixableModule.editorID = 5;
|
|
84
|
+
otherMixableModule.component = "HeroCard";
|
|
85
|
+
otherMixableModule.title = "Hero Section";
|
|
86
|
+
otherMixableModule.modules = [];
|
|
87
|
+
mixableProps.value = [];
|
|
88
|
+
mixableProps.field = { contentType: "modules" };
|
|
89
|
+
mixableProps.objKey = "elements";
|
|
90
|
+
mixableProps.disabled = false;
|
|
91
|
+
mixableProps.maxItems = 1;
|
|
92
|
+
mixableProps.actions = {
|
|
93
|
+
addModuleAction: jest.fn(),
|
|
94
|
+
addComponentAction: jest.fn(),
|
|
95
|
+
deleteModuleAction: jest.fn(),
|
|
96
|
+
replaceElementsInCollectionAction: jest.fn(),
|
|
97
|
+
};
|
|
98
|
+
mixableProps.whiteList = ["BasicContent", "CardCollection"];
|
|
99
|
+
|
|
100
|
+
const Component = (
|
|
101
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
102
|
+
<MixableComponentArray {...mixableProps} />
|
|
103
|
+
</ThemeProvider>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const { rerender } = render(Component);
|
|
107
|
+
const addItemButton = screen.getAllByTestId<HTMLElement>("iconActionComponent");
|
|
108
|
+
expect(addItemButton).toBeTruthy();
|
|
109
|
+
fireEvent.click(addItemButton[0]);
|
|
110
|
+
rerender(Component);
|
|
111
|
+
});
|
|
112
|
+
*/
|
|
113
|
+
test("should render with moduleCopy available", () => {
|
|
114
|
+
otherMixableModule.editorID = 5;
|
|
115
|
+
otherMixableModule.component = "HeroCard";
|
|
116
|
+
otherMixableModule.title = "Hero Section";
|
|
117
|
+
otherMixableModule.modules = [];
|
|
118
|
+
mixableProps.whiteList = [];
|
|
119
|
+
mixableProps.value = [mixableModule, otherMixableModule];
|
|
120
|
+
mixableProps.field = {
|
|
121
|
+
contentType: "modules",
|
|
122
|
+
key: "mainContent",
|
|
123
|
+
};
|
|
124
|
+
mixableProps.objKey = "elements";
|
|
125
|
+
mixableProps.disabled = false;
|
|
126
|
+
mixableProps.maxItems = 10;
|
|
127
|
+
mixableProps.actions = {
|
|
128
|
+
addModuleAction: jest.fn(),
|
|
129
|
+
addComponentAction: jest.fn(),
|
|
130
|
+
deleteModuleAction: jest.fn(),
|
|
131
|
+
replaceElementsInCollectionAction: jest.fn(),
|
|
132
|
+
};
|
|
133
|
+
mixableProps.template = { component: "BasicTemplate" };
|
|
134
|
+
mixableProps.availableDataPacks = [
|
|
135
|
+
{
|
|
136
|
+
id: "ARTICLES",
|
|
137
|
+
title: "Articles",
|
|
138
|
+
category: {
|
|
139
|
+
id: "ARTICLES",
|
|
140
|
+
label: "Articles",
|
|
141
|
+
},
|
|
142
|
+
description: "Allows you to hightlight articles",
|
|
143
|
+
image:
|
|
144
|
+
"https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/data-packs-thumbnails/articles.png",
|
|
145
|
+
templates: [
|
|
146
|
+
{
|
|
147
|
+
id: "ArticlesList",
|
|
148
|
+
title: "Articles List",
|
|
149
|
+
thumbnails: {
|
|
150
|
+
"1x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesList",
|
|
151
|
+
"2x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesList@2x",
|
|
152
|
+
},
|
|
153
|
+
dataPacks: ["ARTICLES"],
|
|
154
|
+
type: {
|
|
155
|
+
label: "Articles",
|
|
156
|
+
value: "articles",
|
|
157
|
+
mode: "list",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
modules: [
|
|
162
|
+
{
|
|
163
|
+
id: "ArticlesDistributor",
|
|
164
|
+
title: "Articles Distributor",
|
|
165
|
+
category: "articlesAndEvents",
|
|
166
|
+
thumbnails: {
|
|
167
|
+
"1x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesDistributor",
|
|
168
|
+
"2x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesDistributor@2x",
|
|
169
|
+
},
|
|
170
|
+
dataPacks: ["ARTICLES"],
|
|
171
|
+
type: {},
|
|
172
|
+
sectionList: {
|
|
173
|
+
BasicTemplate: ["mainContent"],
|
|
174
|
+
NewsDetail: ["closureContent"],
|
|
175
|
+
NewsList: ["relatedContent"],
|
|
176
|
+
SitemapTemplate: ["relatedContent", "closureContent"],
|
|
177
|
+
StoryDetail: ["mainContent", "relatedContent"],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
categories: [],
|
|
182
|
+
structuredData: [
|
|
183
|
+
{
|
|
184
|
+
id: "ARTICLES",
|
|
185
|
+
title: "Articles",
|
|
186
|
+
dataPacks: ["ARTICLES"],
|
|
187
|
+
local: false,
|
|
188
|
+
fromPage: false,
|
|
189
|
+
relatedCategories: [],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
activated: false,
|
|
193
|
+
config: null,
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
const actualDate = new Date();
|
|
197
|
+
mixableProps.moduleCopy = {
|
|
198
|
+
date: actualDate.toISOString(),
|
|
199
|
+
element: {
|
|
200
|
+
component: "ArticlesDistributor",
|
|
201
|
+
anchorID: null,
|
|
202
|
+
verticalSpacing: "medium",
|
|
203
|
+
hasDistributorData: true,
|
|
204
|
+
data: {
|
|
205
|
+
mode: "auto",
|
|
206
|
+
source: ["ARTICLES"],
|
|
207
|
+
order: "alpha",
|
|
208
|
+
quantity: 2,
|
|
209
|
+
},
|
|
210
|
+
layout: "L001",
|
|
211
|
+
title: {
|
|
212
|
+
content: "Title",
|
|
213
|
+
tag: "h2",
|
|
214
|
+
},
|
|
215
|
+
subtitle: "subtitle",
|
|
216
|
+
detail: "detail",
|
|
217
|
+
primaryLinkStyle: "primary",
|
|
218
|
+
groupingLink: {
|
|
219
|
+
component: "Link",
|
|
220
|
+
text: "View all",
|
|
221
|
+
style: "secondary",
|
|
222
|
+
editorID: 40,
|
|
223
|
+
parentEditorID: 39,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
mixableProps.mandatory = true;
|
|
228
|
+
|
|
229
|
+
render(
|
|
230
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
231
|
+
<MixableComponentArray {...mixableProps} />
|
|
232
|
+
</ThemeProvider>
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(screen.getAllByTestId("tooltipComponent")).toBeTruthy();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("ComponentArraySelector component events trigger", () => {
|
|
240
|
+
test("should handle the AddItemButton onClick", () => {
|
|
241
|
+
otherMixableModule.editorID = 5;
|
|
242
|
+
otherMixableModule.component = "HeroCard";
|
|
243
|
+
otherMixableModule.title = "Hero Section";
|
|
244
|
+
otherMixableModule.modules = [];
|
|
245
|
+
mixableProps.value = [mixableModule, otherMixableModule];
|
|
246
|
+
mixableProps.field = { contentType: "modules" };
|
|
247
|
+
mixableProps.objKey = "elements";
|
|
248
|
+
mixableProps.disabled = false;
|
|
249
|
+
mixableProps.maxItems = 10;
|
|
250
|
+
mixableProps.actions = {
|
|
251
|
+
addModuleAction: jest.fn(),
|
|
252
|
+
addComponentAction: jest.fn(),
|
|
253
|
+
deleteModuleAction: jest.fn(),
|
|
254
|
+
replaceElementsInCollectionAction: jest.fn(),
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
render(
|
|
258
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
259
|
+
<MixableComponentArray {...mixableProps} />
|
|
260
|
+
</ThemeProvider>
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
expect(screen.getAllByTestId("iconActionComponent")).toBeTruthy();
|
|
264
|
+
fireEvent.click(screen.getAllByTestId("iconActionComponent")[0]);
|
|
265
|
+
expect(mixableProps.actions.addModuleAction).toBeCalled();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("should handle the PasteModuleButton onClick", () => {
|
|
269
|
+
mixableModule.editorID = 1;
|
|
270
|
+
mixableModule.component = "HeroCard";
|
|
271
|
+
mixableModule.title = "Cards";
|
|
272
|
+
mixableModule.modules = [];
|
|
273
|
+
otherMixableModule.editorID = 2;
|
|
274
|
+
otherMixableModule.component = "HeroCard";
|
|
275
|
+
otherMixableModule.title = "Hero Section";
|
|
276
|
+
otherMixableModule.modules = [];
|
|
277
|
+
mixableProps.field = { type: "components" };
|
|
278
|
+
mixableProps.value = [mixableModule];
|
|
279
|
+
mixableProps.activatedModules = ["HeroSection"];
|
|
280
|
+
mixableProps.whiteList = [];
|
|
281
|
+
mixableProps.moduleCopy = null;
|
|
282
|
+
|
|
283
|
+
render(
|
|
284
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
285
|
+
<MixableComponentArray {...mixableProps} />
|
|
286
|
+
</ThemeProvider>
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
expect(screen.getAllByTestId("iconActionComponent")).toBeTruthy();
|
|
290
|
+
fireEvent.click(screen.getAllByTestId("iconActionComponent")[0]);
|
|
291
|
+
expect(mixableProps.actions.addComponentAction).toBeCalled();
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
export interface IMixableComponentArrayProps {
|
|
296
|
+
maxItems: number;
|
|
297
|
+
title: string;
|
|
298
|
+
whiteList: any[];
|
|
299
|
+
value: IModule[];
|
|
300
|
+
selectedContent: any;
|
|
301
|
+
editorID: number;
|
|
302
|
+
goTo: (editorID: string) => void;
|
|
303
|
+
actions: any;
|
|
304
|
+
categories?: any;
|
|
305
|
+
disabled?: boolean;
|
|
306
|
+
activatedModules: string[];
|
|
307
|
+
objKey: string;
|
|
308
|
+
field: any;
|
|
309
|
+
mandatory?: boolean;
|
|
310
|
+
theme: string;
|
|
311
|
+
moduleCopy: { date: string; element: Record<string, any> } | null;
|
|
312
|
+
availableDataPacks: Record<string, any>[];
|
|
313
|
+
template: any;
|
|
314
|
+
setHistoryPush?: (path: string, isEditor: boolean) => void;
|
|
315
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import PasteModuleButton from "@ax/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseTheme } from "@griddo/core";
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
7
|
+
import { INotification } from "@ax/types";
|
|
8
|
+
import { render, screen, cleanup, fireEvent, act } from "@testing-library/react";
|
|
9
|
+
import { mock } from "jest-mock-extended";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
const defaultProps = mock<IProps>();
|
|
14
|
+
|
|
15
|
+
const mockedFunction = defaultProps.pasteModule as jest.MockedFunction<
|
|
16
|
+
(value: number) => Promise<{ error?: INotification }>
|
|
17
|
+
>;
|
|
18
|
+
const mockedNotification = defaultProps.setNotification as jest.MockedFunction<(notification: INotification) => void>;
|
|
19
|
+
defaultProps.editorID = 1;
|
|
20
|
+
|
|
21
|
+
describe("ComponentArraySelector component rendering", () => {
|
|
22
|
+
test("should render the component", async () => {
|
|
23
|
+
defaultProps.isModuleCopyUnavailable = true;
|
|
24
|
+
defaultProps.setHistoryPush = jest.fn();
|
|
25
|
+
render(
|
|
26
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
27
|
+
<PasteModuleButton {...defaultProps} />
|
|
28
|
+
</ThemeProvider>
|
|
29
|
+
);
|
|
30
|
+
const iconButton = screen.getByTestId("iconActionComponent");
|
|
31
|
+
expect(iconButton).toBeTruthy();
|
|
32
|
+
await act(async () => {
|
|
33
|
+
fireEvent.click(iconButton);
|
|
34
|
+
});
|
|
35
|
+
expect(mockedNotification).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("ComponentArraySelector trigger events", () => {
|
|
40
|
+
test("should trigger the onClick and resolve promise", async () => {
|
|
41
|
+
defaultProps.isModuleCopyUnavailable = false;
|
|
42
|
+
mockedFunction.mockResolvedValue({
|
|
43
|
+
error: {
|
|
44
|
+
type: "warning",
|
|
45
|
+
text: "This is a warning",
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
render(
|
|
50
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
51
|
+
<PasteModuleButton {...defaultProps} />
|
|
52
|
+
</ThemeProvider>
|
|
53
|
+
);
|
|
54
|
+
const iconButton = screen.getByTestId("iconActionComponent");
|
|
55
|
+
expect(iconButton).toBeTruthy();
|
|
56
|
+
await act(async () => {
|
|
57
|
+
fireEvent.click(iconButton);
|
|
58
|
+
});
|
|
59
|
+
await expect(mockedFunction).toHaveBeenCalled();
|
|
60
|
+
await expect(mockedFunction(1)).resolves.toEqual({
|
|
61
|
+
error: {
|
|
62
|
+
type: "warning",
|
|
63
|
+
text: "This is a warning",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
expect(screen.getByTestId("toastMessage")).toHaveTextContent("Module pasted from clipboard");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("should trigger the onClick and resolve promise without error", async () => {
|
|
70
|
+
defaultProps.isModuleCopyUnavailable = false;
|
|
71
|
+
mockedFunction.mockResolvedValue({ error: undefined });
|
|
72
|
+
|
|
73
|
+
render(
|
|
74
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
75
|
+
<PasteModuleButton {...defaultProps} />
|
|
76
|
+
</ThemeProvider>
|
|
77
|
+
);
|
|
78
|
+
const iconButton = screen.getByTestId("iconActionComponent");
|
|
79
|
+
expect(iconButton).toBeTruthy();
|
|
80
|
+
await act(async () => {
|
|
81
|
+
fireEvent.click(iconButton);
|
|
82
|
+
});
|
|
83
|
+
await expect(mockedFunction).toHaveBeenCalled();
|
|
84
|
+
await expect(mockedFunction(1)).resolves.toEqual({ error: undefined });
|
|
85
|
+
expect(screen.getByTestId("toastMessage")).toHaveTextContent("Module pasted from clipboard");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
interface IProps {
|
|
90
|
+
pasteModule: (editorID: number) => Promise<{ error?: INotification }>;
|
|
91
|
+
setNotification?: (notification: INotification) => void;
|
|
92
|
+
setHistoryPush?: (path: string, isEditor: boolean) => void;
|
|
93
|
+
editorID: number;
|
|
94
|
+
isModuleCopyUnavailable: boolean;
|
|
95
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import SameComponentArray from "@ax/components/Fields/ComponentArray/SameComponentArray";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseTheme } from "@griddo/core";
|
|
5
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
6
|
+
import { IModule } from "@ax/types";
|
|
7
|
+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
8
|
+
import { mock } from "jest-mock-extended";
|
|
9
|
+
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
|
|
12
|
+
const sameProps = mock<ISameComponentArrayProps>();
|
|
13
|
+
const sameModule = mock<IModule>();
|
|
14
|
+
const otherSameModule = mock<IModule>();
|
|
15
|
+
// default values for SameComponentArray
|
|
16
|
+
sameModule.editorID = 4;
|
|
17
|
+
sameModule.component = "HeroCard";
|
|
18
|
+
sameModule.title = "Hero Section";
|
|
19
|
+
sameModule.modules = [
|
|
20
|
+
{
|
|
21
|
+
id: "ArticlesDistributor",
|
|
22
|
+
title: "Articles Distributor",
|
|
23
|
+
category: "articlesAndEvents",
|
|
24
|
+
thumbnails: {
|
|
25
|
+
"1x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesDistributor",
|
|
26
|
+
"2x": "https://res.cloudinary.com/thesaurus-cms/image/upload/griddo-components/thumbnails/ArticlesDistributor@2x",
|
|
27
|
+
},
|
|
28
|
+
dataPacks: ["ARTICLES"],
|
|
29
|
+
type: {},
|
|
30
|
+
sectionList: {
|
|
31
|
+
BasicTemplate: ["mainContent"],
|
|
32
|
+
NewsDetail: ["closureContent"],
|
|
33
|
+
NewsList: ["relatedContent"],
|
|
34
|
+
SitemapTemplate: ["relatedContent", "closureContent"],
|
|
35
|
+
StoryDetail: ["mainContent", "relatedContent"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
sameProps.value = [sameModule];
|
|
40
|
+
sameProps.activatedModules = ["HeroSection"];
|
|
41
|
+
sameProps.whiteList = [];
|
|
42
|
+
sameProps.selectedContent = {
|
|
43
|
+
anchorID: null,
|
|
44
|
+
verticalSpacing: "medium",
|
|
45
|
+
component: "CardCollection",
|
|
46
|
+
kind: "BasicCard",
|
|
47
|
+
title: {
|
|
48
|
+
content: "Title",
|
|
49
|
+
tag: "h2",
|
|
50
|
+
},
|
|
51
|
+
subtitle: "Subtitle",
|
|
52
|
+
detail: "Detail",
|
|
53
|
+
elements: [
|
|
54
|
+
{
|
|
55
|
+
component: "BasicCard",
|
|
56
|
+
title: {
|
|
57
|
+
content: "Title",
|
|
58
|
+
tag: "h4",
|
|
59
|
+
},
|
|
60
|
+
subtitle: "Lorem Ipsum",
|
|
61
|
+
description:
|
|
62
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dignissim ut nibh eget porttitor. Nunc eleifend mollis arcu. ",
|
|
63
|
+
auxInfo: "Auxiliar Information",
|
|
64
|
+
link: {
|
|
65
|
+
component: "Link",
|
|
66
|
+
text: "Link",
|
|
67
|
+
url: {
|
|
68
|
+
url: "",
|
|
69
|
+
linkTo: null,
|
|
70
|
+
newTab: false,
|
|
71
|
+
noFollow: false,
|
|
72
|
+
size: null,
|
|
73
|
+
icon: null,
|
|
74
|
+
linkContainer: null,
|
|
75
|
+
},
|
|
76
|
+
style: "link",
|
|
77
|
+
editorID: 6,
|
|
78
|
+
parentEditorID: 5,
|
|
79
|
+
},
|
|
80
|
+
link2: {
|
|
81
|
+
component: "Link",
|
|
82
|
+
editorID: 7,
|
|
83
|
+
parentEditorID: 5,
|
|
84
|
+
},
|
|
85
|
+
media: {
|
|
86
|
+
image: {
|
|
87
|
+
component: "LinkableImage",
|
|
88
|
+
editorID: 8,
|
|
89
|
+
parentEditorID: 5,
|
|
90
|
+
},
|
|
91
|
+
video: {
|
|
92
|
+
component: "Video",
|
|
93
|
+
editorID: 9,
|
|
94
|
+
parentEditorID: 5,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
editorID: 5,
|
|
98
|
+
parentEditorID: 4,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
groupingLink: {
|
|
102
|
+
component: "Link",
|
|
103
|
+
editorID: 20,
|
|
104
|
+
parentEditorID: 4,
|
|
105
|
+
},
|
|
106
|
+
layout: "L002",
|
|
107
|
+
theme: "default",
|
|
108
|
+
editorID: 4,
|
|
109
|
+
parentEditorID: 3,
|
|
110
|
+
};
|
|
111
|
+
sameProps.elementUniqueSelection = true;
|
|
112
|
+
sameProps.mandatory = true;
|
|
113
|
+
|
|
114
|
+
describe("ComponentArraySelector component rendering", () => {
|
|
115
|
+
test("should render the component with SameComponentArray", () => {
|
|
116
|
+
sameProps.field = { type: "components" };
|
|
117
|
+
sameProps.objKey = "elements";
|
|
118
|
+
sameProps.disabled = false;
|
|
119
|
+
sameProps.maxItems = 10;
|
|
120
|
+
|
|
121
|
+
render(
|
|
122
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
123
|
+
<SameComponentArray {...sameProps} />
|
|
124
|
+
</ThemeProvider>
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(screen.getAllByTestId("sameComponentWrapper")).toBeTruthy();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("should render the AddItemButton in the SameComponentArray", () => {
|
|
131
|
+
otherSameModule.editorID = 5;
|
|
132
|
+
otherSameModule.component = "HeroCard";
|
|
133
|
+
otherSameModule.title = "Hero Section";
|
|
134
|
+
otherSameModule.modules = [];
|
|
135
|
+
sameProps.value = [sameModule, otherSameModule];
|
|
136
|
+
sameProps.field = { contentType: "modules" };
|
|
137
|
+
sameProps.objKey = "elements";
|
|
138
|
+
sameProps.disabled = false;
|
|
139
|
+
sameProps.maxItems = 10;
|
|
140
|
+
sameProps.actions = {
|
|
141
|
+
addModuleAction: jest.fn(),
|
|
142
|
+
addComponentAction: jest.fn(),
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
render(
|
|
146
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
147
|
+
<SameComponentArray {...sameProps} />
|
|
148
|
+
</ThemeProvider>
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(screen.getAllByTestId("sameComponentWrapper")).toBeTruthy();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe("ComponentArraySelector component events trigger", () => {
|
|
155
|
+
test("should trigger the onClick button with addModuleAction", () => {
|
|
156
|
+
otherSameModule.editorID = 5;
|
|
157
|
+
otherSameModule.component = "HeroCard";
|
|
158
|
+
otherSameModule.title = "Hero Section";
|
|
159
|
+
otherSameModule.modules = [];
|
|
160
|
+
sameProps.value = [sameModule, otherSameModule];
|
|
161
|
+
sameProps.field = { contentType: "modules" };
|
|
162
|
+
sameProps.objKey = "elements";
|
|
163
|
+
sameProps.disabled = false;
|
|
164
|
+
sameProps.maxItems = 10;
|
|
165
|
+
sameProps.actions = {
|
|
166
|
+
addModuleAction: jest.fn(),
|
|
167
|
+
addComponentAction: jest.fn(),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
render(
|
|
171
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
172
|
+
<SameComponentArray {...sameProps} />
|
|
173
|
+
</ThemeProvider>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect(screen.getAllByTestId("iconActionComponent")).toBeTruthy();
|
|
177
|
+
fireEvent.click(screen.getAllByTestId("iconActionComponent")[0]);
|
|
178
|
+
expect(sameProps.actions.addModuleAction).toBeCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("should trigger the onClick button with addComponentAction", () => {
|
|
182
|
+
sameProps.field = { type: "components" };
|
|
183
|
+
sameProps.objKey = "elements";
|
|
184
|
+
sameProps.disabled = false;
|
|
185
|
+
sameProps.maxItems = 10;
|
|
186
|
+
otherSameModule.editorID = 5;
|
|
187
|
+
otherSameModule.component = "HeroCard";
|
|
188
|
+
otherSameModule.title = "Hero Section";
|
|
189
|
+
otherSameModule.modules = [];
|
|
190
|
+
sameProps.value = [sameModule, otherSameModule];
|
|
191
|
+
sameProps.actions = {
|
|
192
|
+
addModuleAction: jest.fn(),
|
|
193
|
+
addComponentAction: jest.fn(),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
render(
|
|
197
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
198
|
+
<SameComponentArray {...sameProps} />
|
|
199
|
+
</ThemeProvider>
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
expect(screen.getAllByTestId("iconActionComponent")).toBeTruthy();
|
|
203
|
+
fireEvent.click(screen.getAllByTestId("iconActionComponent")[0]);
|
|
204
|
+
expect(sameProps.actions.addComponentAction).toBeCalled();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
export interface ISameComponentArrayProps {
|
|
209
|
+
maxItems: number;
|
|
210
|
+
title: string;
|
|
211
|
+
whiteList: string[];
|
|
212
|
+
value: IModule[];
|
|
213
|
+
elementUniqueSelection: boolean;
|
|
214
|
+
selectedContent: any;
|
|
215
|
+
editorID: number;
|
|
216
|
+
goTo: (editorID: string) => void;
|
|
217
|
+
actions: any;
|
|
218
|
+
categories?: any;
|
|
219
|
+
disabled?: boolean;
|
|
220
|
+
activatedModules: string[];
|
|
221
|
+
objKey: string;
|
|
222
|
+
field: any;
|
|
223
|
+
mandatory?: boolean;
|
|
224
|
+
theme: string;
|
|
225
|
+
}
|
package/src/__tests__/{FieldGroup.test.tsx → components/Fields/FieldGroup/FieldGroup.test.tsx}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import FieldGroup from "
|
|
2
|
+
import FieldGroup from "@ax/components/Fields/FieldGroup";
|
|
3
3
|
import { ThemeProvider } from "styled-components";
|
|
4
4
|
import "@testing-library/jest-dom";
|
|
5
5
|
import { parseTheme } from "@griddo/core";
|
|
6
|
-
import globalTheme from "
|
|
6
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
7
7
|
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
8
8
|
|
|
9
9
|
afterEach(cleanup);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import FieldsDivider from "@ax/components/Fields/FieldsDivider";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseTheme } from "@griddo/core";
|
|
5
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
6
|
+
import { render, screen, cleanup } from "@testing-library/react";
|
|
7
|
+
|
|
8
|
+
afterEach(cleanup);
|
|
9
|
+
|
|
10
|
+
const content = {
|
|
11
|
+
title: "Titulo",
|
|
12
|
+
text: "Contenido",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("FieldsDivider component rendering", () => {
|
|
16
|
+
test("should render the component", () => {
|
|
17
|
+
render(
|
|
18
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
19
|
+
<FieldsDivider data={content} />
|
|
20
|
+
</ThemeProvider>
|
|
21
|
+
);
|
|
22
|
+
expect(screen.getAllByText("Contenido")).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
});
|