@griddo/ax 1.68.7 → 1.69.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.
- package/config/webpack.config.js +24 -0
- package/package.json +6 -2
- package/src/__mocks__/axios/ReferenceField.ts +471 -0
- package/src/{__tests__/components/Fields/UrlField → __mocks__}/mockedAxios.ts +0 -0
- package/src/__mocks__/reducers/structuredData.tsx +10 -0
- package/src/__mocks__/store/ReferenceField.ts +1671 -0
- package/src/__tests__/components/Fields/AnalyticsField/AnalyticsField.test.tsx +20 -28
- package/src/__tests__/components/Fields/CheckGroup/CheckGroup.test.tsx +16 -28
- package/src/__tests__/components/Fields/MultiCheckSelectGroup/MultiCheckSelectGroup.test.tsx +120 -0
- package/src/__tests__/components/Fields/ReferenceField/ReferenceField.test.tsx +532 -0
- package/src/__tests__/components/Fields/TextField/TextField.test.tsx +0 -1
- package/src/__tests__/components/Fields/UrlField/UrlField.test.tsx +14 -13
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +121 -0
- package/src/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton/index.tsx +4 -3
- package/src/components/Fields/ComponentArray/MixableComponentArray/index.tsx +69 -34
- package/src/components/Fields/ComponentArray/SameComponentArray/index.tsx +59 -26
- package/src/components/Fields/ComponentContainer/atoms.tsx +2 -8
- package/src/components/Fields/ComponentContainer/index.tsx +21 -21
- package/src/components/Fields/ComponentContainer/style.tsx +49 -28
- package/src/components/Fields/MultiCheckSelectGroup/index.tsx +2 -2
- package/src/components/Fields/MultiCheckSelectGroup/style.tsx +4 -4
- package/src/components/Fields/ReferenceField/AutoPanel/AutoItem/index.tsx +1 -1
- package/src/components/Fields/ReferenceField/AutoPanel/index.tsx +2 -4
- package/src/components/Fields/ReferenceField/AutoPanel/style.tsx +3 -0
- package/src/components/Fields/ReferenceField/Context/index.tsx +3 -3
- package/src/components/Fields/ReferenceField/ItemList/Item/index.tsx +15 -24
- package/src/components/Fields/ReferenceField/ItemList/Item/style.tsx +22 -15
- package/src/components/Fields/ReferenceField/ItemList/index.tsx +42 -11
- package/src/components/Fields/ReferenceField/ManualPanel/Item/index.tsx +1 -1
- package/src/components/Fields/ReferenceField/index.tsx +5 -6
- package/src/components/Fields/Wysiwyg/index.tsx +4 -4
- package/src/components/Gallery/GalleryPanel/DetailPanel/index.tsx +12 -4
- package/src/components/Gallery/GalleryPanel/index.tsx +10 -2
- package/src/components/Gallery/index.tsx +5 -1
- package/src/components/MainWrapper/AppBar/index.tsx +1 -1
- package/src/containers/App/reducer.tsx +1 -0
- package/src/containers/Gallery/actions.tsx +11 -5
- package/src/containers/Navigation/Defaults/actions.tsx +2 -2
- package/src/containers/PageEditor/actions.tsx +18 -7
- package/src/forms/elements.tsx +5 -6
- package/src/helpers/arrays.tsx +1 -2
- package/src/modules/Content/PageItem/index.tsx +13 -2
- package/src/modules/Content/index.tsx +18 -1
- package/src/modules/GlobalEditor/Editor/index.tsx +2 -2
- package/src/modules/GlobalEditor/index.tsx +9 -7
- package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/index.tsx +1 -1
- package/src/modules/PageEditor/Editor/index.tsx +2 -2
- package/src/modules/PageEditor/index.tsx +8 -6
- package/src/modules/StructuredData/Form/index.tsx +7 -4
- package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +25 -3
- package/src/modules/StructuredData/StructuredDataList/index.tsx +4 -0
- package/src/__mocks__/reducers/analyticsState.tsx +0 -14
- package/src/__mocks__/reducers/app.tsx +0 -10
- package/src/__mocks__/reducers/pageEditor.tsx +0 -30
- package/src/__mocks__/reducers/sites.tsx +0 -10
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "@testing-library/jest-dom";
|
|
3
|
-
import
|
|
4
|
-
import { IAnalytics } from "@ax/types";
|
|
5
|
-
import { createStore, combineReducers } from "redux";
|
|
6
|
-
import analyticsReducer from "../../../../__mocks__/reducers/analyticsState";
|
|
7
|
-
import pageEditorReducer from "../../../../__mocks__/reducers/pageEditor";
|
|
3
|
+
import configureStore from "redux-mock-store";
|
|
8
4
|
import { ThemeProvider } from "styled-components";
|
|
5
|
+
|
|
6
|
+
import { render, cleanup } from "../../../../../config/jest/test-utils";
|
|
7
|
+
|
|
8
|
+
import AnalyticsField from "@ax/components/Fields/AnalyticsField";
|
|
9
9
|
import { parseTheme } from "@griddo/core";
|
|
10
10
|
import globalTheme from "@ax/themes/theme.json";
|
|
11
|
-
import { render, cleanup } from "../../../../../config/jest/test-utils";
|
|
12
11
|
|
|
13
12
|
const valuesMock = {
|
|
14
13
|
contentSelect: "",
|
|
@@ -26,6 +25,9 @@ const analyticsMock = {
|
|
|
26
25
|
|
|
27
26
|
afterEach(cleanup);
|
|
28
27
|
|
|
28
|
+
const middlewares: any = [];
|
|
29
|
+
const mockStore = configureStore(middlewares);
|
|
30
|
+
|
|
29
31
|
describe("AnalyticsField component rendering", () => {
|
|
30
32
|
test("should render the component PageAnalytics", () => {
|
|
31
33
|
const initialState = {
|
|
@@ -36,11 +38,13 @@ describe("AnalyticsField component rendering", () => {
|
|
|
36
38
|
};
|
|
37
39
|
const initialStore = {
|
|
38
40
|
analytics: analyticsMock,
|
|
41
|
+
pageEditor: {
|
|
42
|
+
template: "BasicTemplate",
|
|
43
|
+
},
|
|
39
44
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
45
|
+
|
|
46
|
+
const store = mockStore(initialStore);
|
|
47
|
+
|
|
44
48
|
const { getByText } = render(
|
|
45
49
|
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
46
50
|
<AnalyticsField {...initialState} />
|
|
@@ -70,11 +74,13 @@ describe("AnalyticsField component rendering", () => {
|
|
|
70
74
|
};
|
|
71
75
|
const initialStore = {
|
|
72
76
|
analytics: analyticsMock,
|
|
77
|
+
pageEditor: {
|
|
78
|
+
template: "BasicTemplate",
|
|
79
|
+
},
|
|
73
80
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
81
|
+
|
|
82
|
+
const store = mockStore(initialStore);
|
|
83
|
+
|
|
78
84
|
const { getByText } = render(
|
|
79
85
|
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
80
86
|
<AnalyticsField {...initialState} />
|
|
@@ -84,17 +90,3 @@ describe("AnalyticsField component rendering", () => {
|
|
|
84
90
|
expect(getByText(/Add More Dimensions/i)).toBeInTheDocument();
|
|
85
91
|
});
|
|
86
92
|
});
|
|
87
|
-
|
|
88
|
-
export interface IAnalyticsFieldProps {
|
|
89
|
-
value: IState;
|
|
90
|
-
template: string;
|
|
91
|
-
onChange: (value: IState) => void;
|
|
92
|
-
analytics: IAnalytics;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface IState {
|
|
96
|
-
contentSelect: string;
|
|
97
|
-
groupSelect: string;
|
|
98
|
-
dimensionsSelect: string[];
|
|
99
|
-
values: Record<string, string>;
|
|
100
|
-
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { render, cleanup, fireEvent, screen } from "@testing-library/react";
|
|
6
|
+
|
|
2
7
|
import CheckGroup from "@ax/components/Fields/CheckGroup";
|
|
3
8
|
import { ThemeProvider } from "styled-components";
|
|
4
|
-
import { parseTheme } from "@griddo/core";
|
|
5
9
|
import globalTheme from "@ax/themes/theme.json";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import { render, cleanup, fireEvent, screen } from "@testing-library/react";
|
|
10
|
+
|
|
11
|
+
import { parseTheme } from "@griddo/core";
|
|
9
12
|
|
|
10
13
|
afterEach(cleanup);
|
|
11
14
|
|
|
@@ -15,6 +18,8 @@ const defaultProps = {
|
|
|
15
18
|
onChange: jest.fn(),
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
const user = userEvent.setup();
|
|
22
|
+
|
|
18
23
|
describe("CheckField component rendering", () => {
|
|
19
24
|
it("should render the component with no CheckField", () => {
|
|
20
25
|
render(
|
|
@@ -153,15 +158,9 @@ describe("CheckField events", () => {
|
|
|
153
158
|
);
|
|
154
159
|
expect(await screen.findAllByTestId("checkFieldLabel")).toHaveLength(3);
|
|
155
160
|
const checkFieldInputs = await screen.queryAllByTestId("checkFieldInput");
|
|
156
|
-
fireEvent.change(checkFieldInputs[1], {
|
|
157
|
-
target: { value: "name", checked: true },
|
|
158
|
-
});
|
|
159
|
-
Simulate.change(checkFieldInputs[1]);
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
Simulate.change(checkFieldInputs[2]);
|
|
162
|
+
await user.type(checkFieldInputs[1], "name");
|
|
163
|
+
await user.type(checkFieldInputs[2], "surname");
|
|
165
164
|
|
|
166
165
|
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
167
166
|
expect(onChangeMock).toBeCalledWith(["all"]);
|
|
@@ -204,17 +203,12 @@ describe("CheckField events", () => {
|
|
|
204
203
|
expect(await screen.findAllByTestId("checkFieldLabel")).toHaveLength(4);
|
|
205
204
|
|
|
206
205
|
const checkFieldInputs = await screen.queryAllByTestId("checkFieldInput");
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
210
|
-
Simulate.change(checkFieldInputs[1]);
|
|
206
|
+
|
|
207
|
+
await user.type(checkFieldInputs[1], "name");
|
|
211
208
|
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
212
209
|
expect(onChangeMock).toBeCalledWith(["name"]);
|
|
213
210
|
|
|
214
|
-
|
|
215
|
-
target: { value: "surname", checked: true },
|
|
216
|
-
});
|
|
217
|
-
Simulate.change(checkFieldInputs[2]);
|
|
211
|
+
await user.type(checkFieldInputs[2], "surname");
|
|
218
212
|
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
219
213
|
expect(onChangeMock).toBeCalledWith(["name", "surname"]);
|
|
220
214
|
});
|
|
@@ -256,18 +250,12 @@ describe("CheckField events", () => {
|
|
|
256
250
|
expect(await screen.findAllByTestId("checkFieldLabel")).toHaveLength(4);
|
|
257
251
|
|
|
258
252
|
const checkFieldInputs = await screen.queryAllByTestId("checkFieldInput");
|
|
259
|
-
|
|
260
|
-
target: { value: "name", checked: true },
|
|
261
|
-
});
|
|
262
|
-
Simulate.change(checkFieldInputs[1]);
|
|
253
|
+
await user.type(checkFieldInputs[1], "name");
|
|
263
254
|
|
|
264
255
|
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
265
256
|
expect(onChangeMock).toBeCalledWith(["name"]);
|
|
266
257
|
|
|
267
|
-
|
|
268
|
-
target: { value: "surname", checked: true },
|
|
269
|
-
});
|
|
270
|
-
Simulate.change(checkFieldInputs[2]);
|
|
258
|
+
await user.type(checkFieldInputs[2], "surname");
|
|
271
259
|
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
272
260
|
expect(onChangeMock).toBeCalledWith(["surname"]);
|
|
273
261
|
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Axios from "axios";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseTheme } from "@griddo/core";
|
|
5
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
6
|
+
import { mock } from "jest-mock-extended";
|
|
7
|
+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
8
|
+
import { act } from "react-dom/test-utils";
|
|
9
|
+
import MultiCheckSelectGroup, { IMultiCheckSelectGroupProps } from "@ax/components/Fields/MultiCheckSelectGroup";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
jest.mock("axios");
|
|
14
|
+
const mockedAxios = Axios as jest.MockedFunction<typeof Axios>;
|
|
15
|
+
|
|
16
|
+
const defaultProps = mock<IMultiCheckSelectGroupProps>();
|
|
17
|
+
|
|
18
|
+
describe("MultiCheckSelectGroup component rendering", () => {
|
|
19
|
+
it("should render the component", () => {
|
|
20
|
+
defaultProps.value = {
|
|
21
|
+
NEWS_AREAS: [
|
|
22
|
+
{
|
|
23
|
+
label: "another page",
|
|
24
|
+
name: "another page",
|
|
25
|
+
value: 4168,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
defaultProps.elements = [
|
|
30
|
+
{
|
|
31
|
+
source: "NEWS_AREAS",
|
|
32
|
+
key: "NEWS_AREAS",
|
|
33
|
+
placeholder: "News Areas",
|
|
34
|
+
isGlobal: true,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
render(
|
|
39
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
40
|
+
<MultiCheckSelectGroup {...defaultProps} />
|
|
41
|
+
</ThemeProvider>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const multiCheckSelectWrapper = screen.getByTestId("multi-check-select-wrapper");
|
|
45
|
+
|
|
46
|
+
expect(multiCheckSelectWrapper).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("onChange events", () => {
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
jest.resetAllMocks();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should call onChange", async () => {
|
|
56
|
+
const onChange = jest.fn();
|
|
57
|
+
defaultProps.value = {};
|
|
58
|
+
defaultProps.note = "lorem ipsum";
|
|
59
|
+
defaultProps.elements = [
|
|
60
|
+
{
|
|
61
|
+
source: "NEWS_AREAS",
|
|
62
|
+
key: "NEWS_AREAS",
|
|
63
|
+
placeholder: "News Areas",
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const Component = (
|
|
68
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
69
|
+
<MultiCheckSelectGroup {...defaultProps} onChange={onChange} />
|
|
70
|
+
</ThemeProvider>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const data = {
|
|
74
|
+
data: [
|
|
75
|
+
{
|
|
76
|
+
value: 4168,
|
|
77
|
+
label: "another page",
|
|
78
|
+
name: "another page",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: 4111,
|
|
82
|
+
label: "New Page",
|
|
83
|
+
name: "New Page",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
status: 200,
|
|
87
|
+
statusText: "Ok",
|
|
88
|
+
headers: {},
|
|
89
|
+
config: {},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
mockedAxios.mockResolvedValue(data);
|
|
93
|
+
|
|
94
|
+
const { rerender } = render(Component);
|
|
95
|
+
|
|
96
|
+
const field = screen.getByTestId("field");
|
|
97
|
+
|
|
98
|
+
await act(async () => {
|
|
99
|
+
fireEvent.click(field);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
rerender(Component);
|
|
103
|
+
|
|
104
|
+
const checkFieldInputs = screen.getAllByTestId("checkFieldInput");
|
|
105
|
+
|
|
106
|
+
await act(async () => {
|
|
107
|
+
fireEvent.click(checkFieldInputs[0]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(onChange).toBeCalledWith({
|
|
111
|
+
NEWS_AREAS: [
|
|
112
|
+
{
|
|
113
|
+
label: "another page",
|
|
114
|
+
name: "another page",
|
|
115
|
+
value: 4168,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|