@griddo/ax 1.65.12 → 1.65.15

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 (28) hide show
  1. package/package.json +3 -2
  2. package/src/api/structuredData.tsx +13 -2
  3. package/src/components/Button/index.tsx +15 -2
  4. package/src/components/Fields/AnalyticsField/PageAnalytics/index.test.tsx +204 -0
  5. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/atoms.tsx +1 -0
  6. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/index.test.tsx +146 -0
  7. package/src/components/Fields/ArrayFieldGroup/ArrayFieldInline/index.tsx +2 -1
  8. package/src/components/Fields/ArrayFieldGroup/ArrayFieldItem/index.tsx +1 -1
  9. package/src/components/Fields/ArrayFieldGroup/index.test.tsx +277 -0
  10. package/src/components/Fields/ArrayFieldGroup/index.tsx +0 -1
  11. package/src/components/Fields/AsyncCheckGroup/index.test.tsx +108 -0
  12. package/src/components/Fields/AsyncCheckGroup/index.tsx +3 -5
  13. package/src/components/Fields/AsyncSelect/index.test.tsx +306 -0
  14. package/src/components/Fields/AsyncSelect/index.tsx +18 -17
  15. package/src/components/Fields/HeadingField/index.test.tsx +71 -0
  16. package/src/components/Fields/HeadingField/index.tsx +1 -1
  17. package/src/components/Fields/Select/index.tsx +39 -24
  18. package/src/components/Fields/UrlField/index.tsx +38 -4
  19. package/src/components/Fields/UrlField/utils.tsx +74 -14
  20. package/src/components/FieldsBehavior/index.tsx +1 -1
  21. package/src/containers/StructuredData/actions.tsx +7 -0
  22. package/src/containers/StructuredData/constants.tsx +2 -0
  23. package/src/containers/StructuredData/interfaces.tsx +7 -0
  24. package/src/containers/StructuredData/reducer.tsx +4 -0
  25. package/src/modules/StructuredData/Form/index.tsx +12 -1
  26. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +4 -2
  27. package/src/modules/StructuredData/StructuredDataList/index.tsx +1 -0
  28. package/src/types/index.tsx +7 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "1.65.12",
4
+ "version": "1.65.15",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -171,6 +171,7 @@
171
171
  "eslint-plugin-react": "7.14.3",
172
172
  "eslint-plugin-react-hooks": "^4.2.0",
173
173
  "jest": "^27.5.1",
174
+ "jest-mock-extended": "^2.0.5",
174
175
  "jest-styled-components": "^7.0.8",
175
176
  "prettier": "^2.3.0",
176
177
  "react-test-render": "1.1.2",
@@ -220,5 +221,5 @@
220
221
  "publishConfig": {
221
222
  "access": "public"
222
223
  },
223
- "gitHead": "5b4a284eedba36d038835f1d3812d76b6c5d0195"
224
+ "gitHead": "9b983396fedb02687f1b4db58b5def37b289bc21"
224
225
  }
@@ -104,11 +104,22 @@ const getDataContent = (dataContentId: number, langID: number | null) => {
104
104
 
105
105
  const getDataContents = (params: IGetStructuredDataParams, siteID?: number | null) => {
106
106
  const { host, endpoint } = SERVICES.GET_DATA_CONTENTS;
107
- const { dataID, page, itemsPerPage, pagination, deleted, include_draft, query, filterQuery } = params;
107
+ const {
108
+ dataID,
109
+ page,
110
+ itemsPerPage,
111
+ pagination,
112
+ deleted,
113
+ include_draft,
114
+ query,
115
+ filterQuery,
116
+ relatedFields = false,
117
+ } = params;
108
118
 
109
119
  const url = siteID ? `${host}/site/${siteID}${endpoint}` : `${host}${endpoint}`;
110
120
 
111
- SERVICES.GET_DATA_CONTENTS.dynamicUrl = `${url}${dataID}?page=${page}&itemsPerPage=${itemsPerPage}&pagination=${pagination}&deleted=${deleted}&includeDraft=${include_draft}&relatedFields=true`;
121
+ SERVICES.GET_DATA_CONTENTS.dynamicUrl = `${url}${dataID}?page=${page}&itemsPerPage=${itemsPerPage}&pagination=${pagination}&deleted=${deleted}&includeDraft=${include_draft}`;
122
+ if (relatedFields) SERVICES.GET_DATA_CONTENTS.dynamicUrl += `&relatedFields=true`;
112
123
  if (query && query.trim() !== "") SERVICES.GET_DATA_CONTENTS.dynamicUrl += `&query=${query}`;
113
124
  if (filterQuery) SERVICES.GET_DATA_CONTENTS.dynamicUrl += filterQuery;
114
125
 
@@ -35,7 +35,13 @@ const Button = ({ children, type, disabled, icon, buttonStyle, onClick, classNam
35
35
  switch (buttonStyle) {
36
36
  case buttonStyles.TEXT:
37
37
  return (
38
- <S.TextButton className={className} type={type} disabled={disabled} onClick={handleOnClick}>
38
+ <S.TextButton
39
+ data-testid="buttonText"
40
+ className={className}
41
+ type={type}
42
+ disabled={disabled}
43
+ onClick={handleOnClick}
44
+ >
39
45
  {buttonContent}
40
46
  </S.TextButton>
41
47
  );
@@ -43,6 +49,7 @@ const Button = ({ children, type, disabled, icon, buttonStyle, onClick, classNam
43
49
  case buttonStyles.INVERSE:
44
50
  return (
45
51
  <S.LineButton
52
+ data-testid="buttonLineInverse"
46
53
  className={className}
47
54
  type={type}
48
55
  disabled={disabled}
@@ -54,7 +61,13 @@ const Button = ({ children, type, disabled, icon, buttonStyle, onClick, classNam
54
61
  );
55
62
  default:
56
63
  return (
57
- <S.Button className={className} type={type} disabled={disabled} onClick={handleOnClick}>
64
+ <S.Button
65
+ data-testid="buttonDefault"
66
+ className={className}
67
+ type={type}
68
+ disabled={disabled}
69
+ onClick={handleOnClick}
70
+ >
58
71
  {buttonContent}
59
72
  </S.Button>
60
73
  );
@@ -0,0 +1,204 @@
1
+ import React from "react";
2
+ import "@testing-library/jest-dom";
3
+ import PageAnalytics from "./index";
4
+ import { IAnalytics } from "@ax/types";
5
+ import { ThemeProvider } from "styled-components";
6
+ import { parseTheme } from "@griddo/core";
7
+ import globalTheme from "../../../../themes/theme.json";
8
+ import { render, cleanup } from "@testing-library/react";
9
+
10
+ const valuesMock = {
11
+ contentSelect: "",
12
+ groupSelect: "",
13
+ dimensionsSelect: ["BasicTemplate", "NewsDetail"],
14
+ values: { key: "", value: "" },
15
+ };
16
+
17
+ const analyticsMock = {
18
+ scriptCode: "",
19
+ siteScriptCodeExists: false,
20
+ dimensions: [],
21
+ groups: [],
22
+ };
23
+
24
+ afterEach(cleanup);
25
+
26
+ describe("PageAnalytics component rendering", () => {
27
+ test("should render the component PageAnalytics", () => {
28
+ const props = {
29
+ value: valuesMock,
30
+ template: "BasicTemplate",
31
+ onChange: jest.fn(),
32
+ analytics: analyticsMock,
33
+ };
34
+
35
+ const { getByText } = render(
36
+ <ThemeProvider theme={parseTheme(globalTheme)}>
37
+ <PageAnalytics {...props} />
38
+ </ThemeProvider>
39
+ );
40
+ expect(getByText(/based on the page content/i)).toBeInTheDocument();
41
+ expect(getByText(/Select Dimensions Options/i)).toBeInTheDocument();
42
+ });
43
+
44
+ test("should render the component PageAnalytics whith group", () => {
45
+ const analyticsMockFilled = {
46
+ scriptCode: "",
47
+ siteScriptCodeExists: false,
48
+ dimensions: [
49
+ {
50
+ name: "BasicTemplate",
51
+ values: "BasicTemplate",
52
+ },
53
+ {
54
+ name: "NewsDetail",
55
+ values: "NewsDetail",
56
+ },
57
+ ],
58
+ groups: [
59
+ {
60
+ name: "grupo",
61
+ dimensions: "BasicTemplate",
62
+ templates: "BasicTemplate",
63
+ },
64
+ {
65
+ name: "grupo2",
66
+ dimensions: "NewsDetail",
67
+ templates: "NewsDetail",
68
+ },
69
+ ],
70
+ };
71
+
72
+ const valuesMock = {
73
+ contentSelect: "group",
74
+ groupSelect: "grupo",
75
+ dimensionsSelect: ["valores"],
76
+ values: { key: "", value: "" },
77
+ };
78
+
79
+ const props = {
80
+ value: valuesMock,
81
+ template: "BasicTemplate",
82
+ onChange: jest.fn(),
83
+ analytics: analyticsMockFilled,
84
+ };
85
+
86
+ const { getAllByText, getByText } = render(
87
+ <ThemeProvider theme={parseTheme(globalTheme)}>
88
+ <PageAnalytics {...props} />
89
+ </ThemeProvider>
90
+ );
91
+ expect(getAllByText(/Select variable/i)).toHaveLength(1);
92
+ expect(getByText(/Select Group/i)).toBeInTheDocument();
93
+ });
94
+
95
+ test("should render the component PageAnalytics null value", () => {
96
+ const valuesMock = {
97
+ contentSelect: "individual",
98
+ groupSelect: "",
99
+ dimensionsSelect: ["valores"],
100
+ values: { key: "", value: "" },
101
+ };
102
+
103
+ const analyticsMockFilled = {
104
+ scriptCode: "",
105
+ siteScriptCodeExists: false,
106
+ dimensions: [
107
+ {
108
+ name: "valores",
109
+ values: "null",
110
+ },
111
+ ],
112
+ groups: [
113
+ {
114
+ name: "grupo",
115
+ dimensions: "BasicTemplate",
116
+ templates: "BasicTemplate",
117
+ },
118
+ {
119
+ name: "grupo2",
120
+ dimensions: "NewsDetail",
121
+ templates: "NewsDetail",
122
+ },
123
+ ],
124
+ };
125
+
126
+ const props = {
127
+ value: valuesMock,
128
+ template: "BasicTemplate",
129
+ onChange: jest.fn(),
130
+ analytics: analyticsMockFilled,
131
+ };
132
+
133
+ const { getByPlaceholderText } = render(
134
+ <ThemeProvider theme={parseTheme(globalTheme)}>
135
+ <PageAnalytics {...props} />
136
+ </ThemeProvider>
137
+ );
138
+ expect(getByPlaceholderText(/Type a variable/i)).toBeInTheDocument();
139
+ });
140
+
141
+ test("should render the component PageAnalytics null value", () => {
142
+ const valuesMock = {
143
+ contentSelect: "individual",
144
+ groupSelect: "",
145
+ dimensionsSelect: ["valores"],
146
+ values: { key: "", value: "" },
147
+ };
148
+
149
+ const analyticsMockFilled = {
150
+ scriptCode: "",
151
+ siteScriptCodeExists: false,
152
+ dimensions: [
153
+ {
154
+ name: "BasicTemplate",
155
+ values: "BasicTemplate",
156
+ },
157
+ {
158
+ name: "NewsDetail",
159
+ values: "NewsDetail",
160
+ },
161
+ ],
162
+ groups: [
163
+ {
164
+ name: "grupo",
165
+ dimensions: "BasicTemplate",
166
+ templates: "BasicTemplate",
167
+ },
168
+ {
169
+ name: "grupo2",
170
+ dimensions: "NewsDetail",
171
+ templates: "NewsDetail",
172
+ },
173
+ ],
174
+ };
175
+
176
+ const props = {
177
+ value: valuesMock,
178
+ template: "BasicTemplate",
179
+ onChange: jest.fn(),
180
+ analytics: analyticsMockFilled,
181
+ };
182
+
183
+ const { getAllByText } = render(
184
+ <ThemeProvider theme={parseTheme(globalTheme)}>
185
+ <PageAnalytics {...props} />
186
+ </ThemeProvider>
187
+ );
188
+ expect(getAllByText(/Select Dimensions/i)).toHaveLength(2);
189
+ });
190
+ });
191
+
192
+ export interface IAnalyticsFieldProps {
193
+ value: IState;
194
+ template: string;
195
+ onChange: (value: IState) => void;
196
+ analytics: IAnalytics;
197
+ }
198
+
199
+ export interface IState {
200
+ contentSelect: string;
201
+ groupSelect: string;
202
+ dimensionsSelect: string[];
203
+ values: Record<string, string>;
204
+ }
@@ -50,6 +50,7 @@ const DimensionValue = (props: {
50
50
  }) => {
51
51
  const { dimension, setDimension, values } = props;
52
52
  const dimensionValues = splitAndTrim(dimension?.values, ";");
53
+
53
54
  const options = dimensionValues.map((option) => ({ label: option, value: option }));
54
55
  const handleOnChange = (value: string) => {
55
56
  dimension && setDimension({ [dimension.name]: value });
@@ -0,0 +1,146 @@
1
+ import React from "react";
2
+ import "@testing-library/jest-dom";
3
+ import StructuredDataAnalytics from "./index";
4
+ import { IAnalytics } from "@ax/types";
5
+ import { ThemeProvider } from "styled-components";
6
+ import { parseTheme } from "@griddo/core";
7
+ import globalTheme from "../../../../themes/theme.json";
8
+ import { render, cleanup, fireEvent } from "@testing-library/react";
9
+
10
+ const valuesMock = {
11
+ contentSelect: "",
12
+ groupSelect: "",
13
+ dimensionsSelect: ["BasicTemplate", "NewsDetail"],
14
+ values: { key: "", value: "" },
15
+ };
16
+
17
+ const analyticsMock = {
18
+ scriptCode: "",
19
+ siteScriptCodeExists: false,
20
+ dimensions: [],
21
+ groups: [],
22
+ };
23
+
24
+ afterEach(cleanup);
25
+
26
+ describe("StructuredDataAnalytics component rendering", () => {
27
+ test("should render the component StructuredDataAnalytics", () => {
28
+ const props = {
29
+ value: valuesMock,
30
+ template: "BasicTemplate",
31
+ onChange: jest.fn(),
32
+ analytics: analyticsMock,
33
+ };
34
+
35
+ const { container } = render(
36
+ <ThemeProvider theme={parseTheme(globalTheme)}>
37
+ <StructuredDataAnalytics {...props} />
38
+ </ThemeProvider>
39
+ );
40
+ expect(container).toBeEmptyDOMElement();
41
+ });
42
+
43
+ test("should render the component StructuredDataAnalytics with templateDimensions", () => {
44
+ const analyticsMockFilled = {
45
+ scriptCode: "",
46
+ siteScriptCodeExists: false,
47
+ dimensions: [
48
+ {
49
+ name: "BasicTemplate",
50
+ values: "BasicTemplate",
51
+ },
52
+ {
53
+ name: "NewsDetail",
54
+ values: "NewsDetail",
55
+ },
56
+ ],
57
+ groups: [
58
+ {
59
+ name: "grupo",
60
+ dimensions: "BasicTemplate",
61
+ templates: "BasicTemplate",
62
+ },
63
+ {
64
+ name: "grupo2",
65
+ dimensions: "NewsDetail",
66
+ templates: "NewsDetail",
67
+ },
68
+ ],
69
+ };
70
+
71
+ const props = {
72
+ value: valuesMock,
73
+ template: "BasicTemplate",
74
+ onChange: jest.fn(),
75
+ analytics: analyticsMockFilled,
76
+ };
77
+
78
+ const { getAllByText, getByText } = render(
79
+ <ThemeProvider theme={parseTheme(globalTheme)}>
80
+ <StructuredDataAnalytics {...props} />
81
+ </ThemeProvider>
82
+ );
83
+ expect(getAllByText(/Select variable/i)).toHaveLength(3);
84
+ expect(getByText(/Select Dimensions/i)).toBeInTheDocument();
85
+ });
86
+
87
+ test("should render the component StructuredDataAnalytics with null value", () => {
88
+ const valuesMock = {
89
+ contentSelect: "",
90
+ groupSelect: "",
91
+ dimensionsSelect: ["valores"],
92
+ values: { key: "", value: "" },
93
+ };
94
+
95
+ const analyticsMockFilled = {
96
+ scriptCode: "",
97
+ siteScriptCodeExists: false,
98
+ dimensions: [
99
+ {
100
+ name: "valores",
101
+ values: "null",
102
+ },
103
+ ],
104
+ groups: [
105
+ {
106
+ name: "grupo",
107
+ dimensions: "BasicTemplate",
108
+ templates: "BasicTemplate",
109
+ },
110
+ {
111
+ name: "grupo2",
112
+ dimensions: "NewsDetail",
113
+ templates: "NewsDetail",
114
+ },
115
+ ],
116
+ };
117
+
118
+ const props = {
119
+ value: valuesMock,
120
+ template: "BasicTemplate",
121
+ onChange: jest.fn(),
122
+ analytics: analyticsMockFilled,
123
+ };
124
+
125
+ const { getByPlaceholderText } = render(
126
+ <ThemeProvider theme={parseTheme(globalTheme)}>
127
+ <StructuredDataAnalytics {...props} />
128
+ </ThemeProvider>
129
+ );
130
+ expect(getByPlaceholderText(/Type a variable/i)).toBeInTheDocument();
131
+ });
132
+ });
133
+
134
+ export interface IAnalyticsFieldProps {
135
+ value: IState;
136
+ template: string;
137
+ onChange: (value: IState) => void;
138
+ analytics: IAnalytics;
139
+ }
140
+
141
+ export interface IState {
142
+ contentSelect: string;
143
+ groupSelect: string;
144
+ dimensionsSelect: string[];
145
+ values: Record<string, string>;
146
+ }
@@ -12,6 +12,7 @@ const ArrayFieldInline = (props: IProps): JSX.Element => {
12
12
  const getFields = (fields: any[]): any[] => {
13
13
  return fields.map((field: any) => {
14
14
  const key = field.props.objKey;
15
+
15
16
  const handleChange = (newValue: any) => onChange({ [key]: newValue });
16
17
 
17
18
  const innerFields = field.props.innerFields ? getFields(field.props.innerFields) : undefined;
@@ -25,7 +26,7 @@ const ArrayFieldInline = (props: IProps): JSX.Element => {
25
26
  };
26
27
 
27
28
  return (
28
- <S.Wrapper>
29
+ <S.Wrapper data-testid="arrayFieldInline">
29
30
  <S.Content>
30
31
  <S.IconWrapper>
31
32
  <IconAction icon="delete" onClick={deleteItem} size="s" />
@@ -42,7 +42,7 @@ const ArrayFieldItem = (props: IProps): JSX.Element => {
42
42
  };
43
43
 
44
44
  return (
45
- <S.Wrapper isOpen={isOpen === index}>
45
+ <S.Wrapper data-testid="arrayFieldItem" isOpen={isOpen === index}>
46
46
  <S.Title onClick={handleClick} isOpen={isOpen === index}>
47
47
  {getItemTitle(fields)}
48
48
  <S.StyledActionMenu icon="more" options={menuOptions} />