@zohodesk/library-platform 1.0.2-exp.1.2 → 1.0.2-exp.1.3
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/es/library/custom-component/domain/entities/DefaultSlotNameAppend.js +10 -0
- package/es/library/custom-component/domain/entities/Properties.js +2 -0
- package/es/library/custom-component/frameworks/ui/CreateCustomComponent.js +0 -13
- package/es/library/custom-component/frameworks/ui/__testcases__/CreateSlotComponent.spec.js +211 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3
3
|
import Property from "./Property";
|
|
4
4
|
import defaultAppendToActionPayload from "./DefaultAppendToActionPayload";
|
|
5
5
|
import getRefPropertySchema from "../../../../cc/component/properties/getRefPropertySchema";
|
|
6
|
+
import defaultSlotNameAppend from "./DefaultSlotNameAppend";
|
|
6
7
|
export default class Properties {
|
|
7
8
|
constructor(properties, componentName) {
|
|
8
9
|
this.componentName = componentName;
|
|
@@ -12,6 +13,7 @@ export default class Properties {
|
|
|
12
13
|
this.data = properties;
|
|
13
14
|
this.data.set('appendToActionPayload', new Property(defaultAppendToActionPayload));
|
|
14
15
|
this.data.set('getRef', new Property(getRefPropertySchema));
|
|
16
|
+
typeof properties.get("slotName") === "undefined" && this.data.set('slotName', new Property(defaultSlotNameAppend));
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
getAllPropertiesValue() {
|
|
@@ -16,19 +16,6 @@ function discardChildren(props) {
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
const createCustomComponent = input => {
|
|
19
|
-
var _input$properties, _input$properties$slo;
|
|
20
|
-
|
|
21
|
-
input.properties = { ...(input.properties || {}),
|
|
22
|
-
slotName: {
|
|
23
|
-
required: ((_input$properties = input.properties) === null || _input$properties === void 0 ? void 0 : (_input$properties$slo = _input$properties.slotName) === null || _input$properties$slo === void 0 ? void 0 : _input$properties$slo.required) || false,
|
|
24
|
-
typeMetadata: {
|
|
25
|
-
schema: {
|
|
26
|
-
type: "string"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
19
|
class Component extends React.Component {
|
|
33
20
|
constructor(props) {
|
|
34
21
|
super(props);
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React, { Component } from "react";
|
|
3
|
+
import createCustomComponent from "../CreateCustomComponent.tsx";
|
|
4
|
+
import ComponentRegistry from "../ComponentRegistry";
|
|
5
|
+
import { render, cleanup } from '@testing-library/react';
|
|
6
|
+
import '@testing-library/jest-dom';
|
|
7
|
+
const Parent = createCustomComponent({
|
|
8
|
+
name: "parent",
|
|
9
|
+
View: (_ref, ref) => {
|
|
10
|
+
let {
|
|
11
|
+
slotChildren
|
|
12
|
+
} = _ref;
|
|
13
|
+
const {
|
|
14
|
+
child = null,
|
|
15
|
+
siblingChild = null
|
|
16
|
+
} = slotChildren;
|
|
17
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
ref: ref
|
|
19
|
+
}, "Hi, I am the Parent.", /*#__PURE__*/React.createElement("div", null, child), /*#__PURE__*/React.createElement("div", null, siblingChild));
|
|
20
|
+
},
|
|
21
|
+
properties: {
|
|
22
|
+
slots: {
|
|
23
|
+
required: false,
|
|
24
|
+
typeMetadata: {
|
|
25
|
+
schema: {
|
|
26
|
+
type: "array"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
eventHandlers: {}
|
|
32
|
+
});
|
|
33
|
+
const Child = createCustomComponent({
|
|
34
|
+
name: "child",
|
|
35
|
+
View: (_ref2, ref) => {
|
|
36
|
+
let {
|
|
37
|
+
slotChildren
|
|
38
|
+
} = _ref2;
|
|
39
|
+
const {
|
|
40
|
+
nestedChildren = null
|
|
41
|
+
} = slotChildren;
|
|
42
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
43
|
+
ref: ref
|
|
44
|
+
}, "Hi, I am the Child.", /*#__PURE__*/React.createElement("div", null, nestedChildren));
|
|
45
|
+
},
|
|
46
|
+
eventHandlers: {},
|
|
47
|
+
properties: {
|
|
48
|
+
slots: {
|
|
49
|
+
required: false,
|
|
50
|
+
typeMetadata: {
|
|
51
|
+
schema: {
|
|
52
|
+
type: "array"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const SiblingChild = createCustomComponent({
|
|
59
|
+
name: "siblingChild",
|
|
60
|
+
View: (props, ref) => {
|
|
61
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
62
|
+
ref: ref
|
|
63
|
+
}, "Hi, I am the sibling Child.");
|
|
64
|
+
},
|
|
65
|
+
eventHandlers: {},
|
|
66
|
+
properties: {}
|
|
67
|
+
});
|
|
68
|
+
const NestedChild = createCustomComponent({
|
|
69
|
+
name: "nestedChild",
|
|
70
|
+
View: (_, ref) => {
|
|
71
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
ref: ref
|
|
73
|
+
}, "Hi, I am the nested Child.");
|
|
74
|
+
},
|
|
75
|
+
eventHandlers: {},
|
|
76
|
+
properties: {}
|
|
77
|
+
});
|
|
78
|
+
const NoSlotName = createCustomComponent({
|
|
79
|
+
name: "noSlotName",
|
|
80
|
+
View: (_, ref) => {
|
|
81
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
ref: ref
|
|
83
|
+
}, "Hi, It should not be rendered.");
|
|
84
|
+
},
|
|
85
|
+
eventHandlers: {},
|
|
86
|
+
properties: {}
|
|
87
|
+
});
|
|
88
|
+
ComponentRegistry.register("Parent", Parent);
|
|
89
|
+
ComponentRegistry.register("Child", Child);
|
|
90
|
+
ComponentRegistry.register("SiblingChild", SiblingChild);
|
|
91
|
+
describe("Slot Integration test suite", () => {
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
jest.clearAllMocks();
|
|
94
|
+
cleanup();
|
|
95
|
+
});
|
|
96
|
+
it("slot Information passed to parent and check children rendering", () => {
|
|
97
|
+
const slots = [{
|
|
98
|
+
name: "child",
|
|
99
|
+
elements: [{
|
|
100
|
+
name: "child",
|
|
101
|
+
type: "Child"
|
|
102
|
+
}]
|
|
103
|
+
}];
|
|
104
|
+
const {
|
|
105
|
+
getByText
|
|
106
|
+
} = render( /*#__PURE__*/React.createElement(Parent, {
|
|
107
|
+
slots: slots
|
|
108
|
+
}, /*#__PURE__*/React.createElement(Child, {
|
|
109
|
+
slotName: "child"
|
|
110
|
+
})));
|
|
111
|
+
const component = getByText("Hi, I am the Child.");
|
|
112
|
+
expect(component).toBeInTheDocument();
|
|
113
|
+
});
|
|
114
|
+
it("slots with nested child and check nested child rendering", () => {
|
|
115
|
+
const slots = [{
|
|
116
|
+
name: "child",
|
|
117
|
+
elements: [{
|
|
118
|
+
name: "child",
|
|
119
|
+
type: "Child",
|
|
120
|
+
slots: [{
|
|
121
|
+
name: "nestedChildren",
|
|
122
|
+
elements: [{
|
|
123
|
+
name: "nestedChild",
|
|
124
|
+
type: "NestedChild"
|
|
125
|
+
}]
|
|
126
|
+
}]
|
|
127
|
+
}]
|
|
128
|
+
}];
|
|
129
|
+
const {
|
|
130
|
+
getByText
|
|
131
|
+
} = render( /*#__PURE__*/React.createElement(Parent, {
|
|
132
|
+
slots: slots
|
|
133
|
+
}, /*#__PURE__*/React.createElement(Child, {
|
|
134
|
+
slotName: "child"
|
|
135
|
+
}, /*#__PURE__*/React.createElement(NestedChild, {
|
|
136
|
+
slotName: "nestedChildren"
|
|
137
|
+
}))));
|
|
138
|
+
const component = getByText("Hi, I am the nested Child.");
|
|
139
|
+
expect(component).toBeInTheDocument();
|
|
140
|
+
});
|
|
141
|
+
it("slots with sibling child and check sibling child rendering", () => {
|
|
142
|
+
const slots = [{
|
|
143
|
+
name: "child",
|
|
144
|
+
elements: [{
|
|
145
|
+
name: "child",
|
|
146
|
+
type: "Child",
|
|
147
|
+
slots: [{
|
|
148
|
+
name: "nestedChildren",
|
|
149
|
+
elements: [{
|
|
150
|
+
name: "nestedChild",
|
|
151
|
+
type: "NestedChild"
|
|
152
|
+
}]
|
|
153
|
+
}]
|
|
154
|
+
}]
|
|
155
|
+
}, {
|
|
156
|
+
name: "siblingChild",
|
|
157
|
+
elements: [{
|
|
158
|
+
name: "siblingChild",
|
|
159
|
+
type: "SiblingChild"
|
|
160
|
+
}]
|
|
161
|
+
}];
|
|
162
|
+
const {
|
|
163
|
+
getByText
|
|
164
|
+
} = render( /*#__PURE__*/React.createElement(Parent, {
|
|
165
|
+
slots: slots
|
|
166
|
+
}, /*#__PURE__*/React.createElement(Child, {
|
|
167
|
+
slotName: "child"
|
|
168
|
+
}, /*#__PURE__*/React.createElement(NestedChild, {
|
|
169
|
+
slotName: "nestedChildren"
|
|
170
|
+
})), /*#__PURE__*/React.createElement(SiblingChild, null)));
|
|
171
|
+
const component = getByText("Hi, I am the sibling Child.");
|
|
172
|
+
expect(component).toBeInTheDocument();
|
|
173
|
+
});
|
|
174
|
+
it("children with no slot support should not be rendered", () => {
|
|
175
|
+
const slots = [{
|
|
176
|
+
name: "child",
|
|
177
|
+
elements: [{
|
|
178
|
+
name: "child",
|
|
179
|
+
type: "Child",
|
|
180
|
+
slots: [{
|
|
181
|
+
name: "nestedChildren",
|
|
182
|
+
elements: [{
|
|
183
|
+
name: "nestedChild",
|
|
184
|
+
type: "NestedChild"
|
|
185
|
+
}]
|
|
186
|
+
}]
|
|
187
|
+
}]
|
|
188
|
+
}, {
|
|
189
|
+
name: "siblingChild",
|
|
190
|
+
elements: [{
|
|
191
|
+
name: "siblingChild",
|
|
192
|
+
type: "SiblingChild"
|
|
193
|
+
}]
|
|
194
|
+
}];
|
|
195
|
+
const {
|
|
196
|
+
queryByText
|
|
197
|
+
} = render( /*#__PURE__*/React.createElement(Parent, {
|
|
198
|
+
slots: slots
|
|
199
|
+
}, /*#__PURE__*/React.createElement(Child, {
|
|
200
|
+
slotName: "child"
|
|
201
|
+
}, /*#__PURE__*/React.createElement(NestedChild, {
|
|
202
|
+
slotName: "nestedChildren"
|
|
203
|
+
})), /*#__PURE__*/React.createElement(SiblingChild, {
|
|
204
|
+
slotName: "siblingChild"
|
|
205
|
+
}), /*#__PURE__*/React.createElement(NoSlotName, {
|
|
206
|
+
slotName: "noslotname"
|
|
207
|
+
})));
|
|
208
|
+
const component = queryByText("Hi, It should not be rendered.");
|
|
209
|
+
expect(component).toBeNull();
|
|
210
|
+
});
|
|
211
|
+
});
|