@domql/element 3.0.1 → 3.0.4
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/create.js +0 -12
- package/dist/cjs/create.js +0 -9
- package/dist/esm/create.js +0 -9
- package/package.json +4 -4
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/cjs/__tests__/children.test.js +0 -177
- package/dist/cjs/__tests__/define.test.js +0 -75
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/cjs/__tests__/renderElement.test.js +0 -138
- package/dist/cjs/__tests__/resetElement.test.js +0 -35
- package/dist/cjs/__tests__/set.test.js +0 -256
- package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
- package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/cjs/__tests__/tree.test.js +0 -11
- package/dist/cjs/__tests__/update.test.js +0 -219
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/esm/__tests__/children.test.js +0 -177
- package/dist/esm/__tests__/define.test.js +0 -53
- package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/esm/__tests__/renderElement.test.js +0 -116
- package/dist/esm/__tests__/resetElement.test.js +0 -35
- package/dist/esm/__tests__/set.test.js +0 -256
- package/dist/esm/__tests__/throughExecProps.test.js +0 -62
- package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/esm/__tests__/tree.test.js +0 -11
- package/dist/esm/__tests__/update.test.js +0 -219
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
var import_globals = require("@jest/globals");
|
|
2
|
-
var import_set = require("../set");
|
|
3
|
-
describe("set", () => {
|
|
4
|
-
let element, ref;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
ref = {
|
|
7
|
-
contentElementKey: "content",
|
|
8
|
-
__noChildrenDifference: false
|
|
9
|
-
};
|
|
10
|
-
element = {
|
|
11
|
-
__ref: ref,
|
|
12
|
-
props: {},
|
|
13
|
-
children: [],
|
|
14
|
-
context: { components: {} },
|
|
15
|
-
state: {},
|
|
16
|
-
node: document.createElement("div"),
|
|
17
|
-
childExtends: {},
|
|
18
|
-
parent: { node: document.createElement("div") }
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
it("updates element.props when params.props are provided", async () => {
|
|
22
|
-
await import_set.set.call(element, { props: { title: "New Title" } });
|
|
23
|
-
expect(element.content.props.title).toBe("New Title");
|
|
24
|
-
});
|
|
25
|
-
it("skips update when deepContains matches existing content", async () => {
|
|
26
|
-
ref.__noChildrenDifference = true;
|
|
27
|
-
const originalProps = { ...element.props };
|
|
28
|
-
await import_set.set.call(element, { props: { id: "same" } });
|
|
29
|
-
expect(element.props).toEqual(originalProps);
|
|
30
|
-
});
|
|
31
|
-
it("merges element.childExtends into params when missing", async () => {
|
|
32
|
-
element.childExtends = { button: "PrimaryButton" };
|
|
33
|
-
const params = { tag: "fragment", props: {} };
|
|
34
|
-
await import_set.set.call(element, params);
|
|
35
|
-
expect(params.childExtends).toEqual({ button: "PrimaryButton" });
|
|
36
|
-
expect(params.props.ignoreChildExtends).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
it("preserves content when preventContentUpdate=true and no children", async () => {
|
|
39
|
-
const originalContent = element[ref.contentElementKey];
|
|
40
|
-
await import_set.set.call(
|
|
41
|
-
element,
|
|
42
|
-
{ props: { new: true } },
|
|
43
|
-
{ preventContentUpdate: true }
|
|
44
|
-
);
|
|
45
|
-
expect(element[ref.contentElementKey]).toBeDefined();
|
|
46
|
-
expect(originalContent).toBeUndefined();
|
|
47
|
-
});
|
|
48
|
-
it("copies element.props.childProps into params when missing", async () => {
|
|
49
|
-
element.props.childProps = { size: "large" };
|
|
50
|
-
const params = { tag: "fragment", props: {} };
|
|
51
|
-
await import_set.set.call(element, params);
|
|
52
|
-
expect(params.props.childProps).toEqual({ size: "large" });
|
|
53
|
-
expect(params.props.ignoreChildProps).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
it("preserves state when beforeUpdate returns false", async () => {
|
|
56
|
-
ref.__noChildrenDifference = true;
|
|
57
|
-
const originalState = { ...element.state };
|
|
58
|
-
await import_set.set.call(element, { state: { shouldChange: true } });
|
|
59
|
-
expect(element.state).toEqual(originalState);
|
|
60
|
-
});
|
|
61
|
-
it("updates node reference when provided in params", async () => {
|
|
62
|
-
const newNode = document.createElement("section");
|
|
63
|
-
await import_set.set.call(element, { node: newNode });
|
|
64
|
-
expect(element.node.tagName).toBe("DIV");
|
|
65
|
-
});
|
|
66
|
-
it("resolves context components in params", async () => {
|
|
67
|
-
element.context.components = { Header: {} };
|
|
68
|
-
await import_set.set.call(element, { Header: {} });
|
|
69
|
-
expect(element.Header).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
it("updates nested props without mutating original", async () => {
|
|
72
|
-
const originalProps = { nested: { value: 1 } };
|
|
73
|
-
element.props = originalProps;
|
|
74
|
-
await import_set.set.call(element, { props: { nested: { value: 2 } } });
|
|
75
|
-
expect(element.props.nested.value).toBe(1);
|
|
76
|
-
expect(originalProps.nested.value).toBe(1);
|
|
77
|
-
});
|
|
78
|
-
it("preserves existing props when params=null", async () => {
|
|
79
|
-
element.props = { preserveMe: true };
|
|
80
|
-
await import_set.set.call(element, null);
|
|
81
|
-
expect(element.props.preserveMe).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
it("removes content correctly when calling removeContent", async () => {
|
|
84
|
-
const content = document.createElement("div");
|
|
85
|
-
element.content = {
|
|
86
|
-
node: content,
|
|
87
|
-
tag: "div",
|
|
88
|
-
remove: import_globals.jest.fn()
|
|
89
|
-
};
|
|
90
|
-
element.node.appendChild(content);
|
|
91
|
-
await import_set.set.call(element, { props: { new: true } });
|
|
92
|
-
expect(element.content.__ref).toBeDefined();
|
|
93
|
-
expect(element.node.contains(content)).toBeFalsy();
|
|
94
|
-
});
|
|
95
|
-
it("handles lazy loading with requestAnimationFrame", async () => {
|
|
96
|
-
import_globals.jest.useFakeTimers();
|
|
97
|
-
element.props = { lazyLoad: true };
|
|
98
|
-
const params = { props: { test: true } };
|
|
99
|
-
await import_set.set.call(element, params);
|
|
100
|
-
import_globals.jest.runAllTimers();
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
expect(element.content).toBeDefined();
|
|
103
|
-
}, 35);
|
|
104
|
-
import_globals.jest.useRealTimers();
|
|
105
|
-
});
|
|
106
|
-
it("handles fragment content removal correctly", async () => {
|
|
107
|
-
const remove1 = import_globals.jest.fn(() => Promise.resolve());
|
|
108
|
-
const remove2 = import_globals.jest.fn(() => Promise.resolve());
|
|
109
|
-
const node1 = document.createElement("div");
|
|
110
|
-
const node2 = document.createElement("div");
|
|
111
|
-
element.tag = "fragment";
|
|
112
|
-
element.content = {
|
|
113
|
-
tag: "fragment",
|
|
114
|
-
node: element.node,
|
|
115
|
-
__ref: {
|
|
116
|
-
__children: ["child1", "child2"]
|
|
117
|
-
},
|
|
118
|
-
child1: { node: node1, remove: remove1 },
|
|
119
|
-
child2: { node: node2, remove: remove2 }
|
|
120
|
-
};
|
|
121
|
-
element.node.appendChild(node1);
|
|
122
|
-
element.node.appendChild(node2);
|
|
123
|
-
await import_set.set.call(element, { props: { new: true } });
|
|
124
|
-
expect(remove1).toHaveBeenCalled();
|
|
125
|
-
expect(remove2).toHaveBeenCalled();
|
|
126
|
-
});
|
|
127
|
-
it("handles fragment content removal with children", async () => {
|
|
128
|
-
const remove1 = import_globals.jest.fn();
|
|
129
|
-
const remove2 = import_globals.jest.fn();
|
|
130
|
-
const node1 = document.createElement("div");
|
|
131
|
-
const node2 = document.createElement("div");
|
|
132
|
-
element.content = {
|
|
133
|
-
tag: "fragment",
|
|
134
|
-
node: element.node,
|
|
135
|
-
__ref: {
|
|
136
|
-
__children: ["child1", "child2"]
|
|
137
|
-
},
|
|
138
|
-
child1: { node: node1, remove: remove1 },
|
|
139
|
-
child2: { node: node2, remove: remove2 }
|
|
140
|
-
};
|
|
141
|
-
element.node.appendChild(node1);
|
|
142
|
-
element.node.appendChild(node2);
|
|
143
|
-
await import_set.set.call(element, { props: { new: true } });
|
|
144
|
-
expect(remove1).toHaveBeenCalled();
|
|
145
|
-
expect(remove2).toHaveBeenCalled();
|
|
146
|
-
});
|
|
147
|
-
it("merges element.childExtends into params when tag is fragment", async () => {
|
|
148
|
-
element.tag = "fragment";
|
|
149
|
-
element.childExtends = { button: "PrimaryButton" };
|
|
150
|
-
const params = { tag: "fragment", props: {} };
|
|
151
|
-
await import_set.set.call(element, params);
|
|
152
|
-
expect(params.childExtends).toEqual(element.childExtends);
|
|
153
|
-
});
|
|
154
|
-
it("copies element.props.childProps into params for fragments", async () => {
|
|
155
|
-
element.tag = "fragment";
|
|
156
|
-
element.props.childProps = { size: "large" };
|
|
157
|
-
const params = { tag: "fragment", props: {} };
|
|
158
|
-
await import_set.set.call(element, params);
|
|
159
|
-
expect(params.props.childProps).toEqual(element.props.childProps);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe("setContentKey", () => {
|
|
163
|
-
test("should set default content key", () => {
|
|
164
|
-
const element = {
|
|
165
|
-
__ref: {}
|
|
166
|
-
};
|
|
167
|
-
const result = (0, import_set.setContentKey)(element);
|
|
168
|
-
expect(result).toBe("content");
|
|
169
|
-
expect(element.__ref.contentElementKey).toBe("content");
|
|
170
|
-
});
|
|
171
|
-
test("should set custom content key", () => {
|
|
172
|
-
const element = {
|
|
173
|
-
__ref: {}
|
|
174
|
-
};
|
|
175
|
-
const opts = { contentElementKey: "customContent" };
|
|
176
|
-
const result = (0, import_set.setContentKey)(element, opts);
|
|
177
|
-
expect(result).toBe("customContent");
|
|
178
|
-
expect(element.__ref.contentElementKey).toBe("customContent");
|
|
179
|
-
});
|
|
180
|
-
test("should not override existing content key if same value", () => {
|
|
181
|
-
const element = {
|
|
182
|
-
__ref: {
|
|
183
|
-
contentElementKey: "content"
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
const result = (0, import_set.setContentKey)(element);
|
|
187
|
-
expect(result).toBe("content");
|
|
188
|
-
expect(element.__ref.contentElementKey).toBe("content");
|
|
189
|
-
});
|
|
190
|
-
test("should override existing content key if different value", () => {
|
|
191
|
-
const element = {
|
|
192
|
-
__ref: {
|
|
193
|
-
contentElementKey: "oldContent"
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const opts = { contentElementKey: "newContent" };
|
|
197
|
-
const result = (0, import_set.setContentKey)(element, opts);
|
|
198
|
-
expect(result).toBe("newContent");
|
|
199
|
-
expect(element.__ref.contentElementKey).toBe("newContent");
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
describe("removeContent", () => {
|
|
203
|
-
let element;
|
|
204
|
-
beforeEach(() => {
|
|
205
|
-
element = {
|
|
206
|
-
node: document.createElement("div"),
|
|
207
|
-
__ref: {}
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
|
-
test("removes basic content", () => {
|
|
211
|
-
const contentNode = document.createElement("span");
|
|
212
|
-
element.content = {
|
|
213
|
-
node: contentNode,
|
|
214
|
-
tag: "span"
|
|
215
|
-
};
|
|
216
|
-
element.node.appendChild(contentNode);
|
|
217
|
-
(0, import_set.removeContent)(element);
|
|
218
|
-
expect(element.content).toBeUndefined();
|
|
219
|
-
expect(element.node.children.length).toBe(0);
|
|
220
|
-
});
|
|
221
|
-
test("removes fragment content", () => {
|
|
222
|
-
const remove1 = import_globals.jest.fn();
|
|
223
|
-
const remove2 = import_globals.jest.fn();
|
|
224
|
-
const node1 = document.createElement("div");
|
|
225
|
-
const node2 = document.createElement("div");
|
|
226
|
-
const fragmentNode = document.createElement("div");
|
|
227
|
-
fragmentNode.setAttribute("fragment", "");
|
|
228
|
-
element.node.appendChild(node1);
|
|
229
|
-
element.node.appendChild(node2);
|
|
230
|
-
element.content = {
|
|
231
|
-
tag: "fragment",
|
|
232
|
-
node: fragmentNode,
|
|
233
|
-
__ref: {
|
|
234
|
-
__children: ["child1", "child2"]
|
|
235
|
-
},
|
|
236
|
-
child1: { node: node1, remove: remove1 },
|
|
237
|
-
child2: { node: node2, remove: remove2 }
|
|
238
|
-
};
|
|
239
|
-
(0, import_set.removeContent)(element);
|
|
240
|
-
expect(remove1).toHaveBeenCalled();
|
|
241
|
-
expect(remove2).toHaveBeenCalled();
|
|
242
|
-
expect(element.content).toBeUndefined();
|
|
243
|
-
expect(element.node.children.length).toBe(0);
|
|
244
|
-
});
|
|
245
|
-
test("handles custom content element key", () => {
|
|
246
|
-
const contentNode = document.createElement("span");
|
|
247
|
-
element.customContent = {
|
|
248
|
-
node: contentNode,
|
|
249
|
-
tag: "span"
|
|
250
|
-
};
|
|
251
|
-
element.node.appendChild(contentNode);
|
|
252
|
-
(0, import_set.removeContent)(element, { contentElementKey: "customContent" });
|
|
253
|
-
expect(element.customContent).toBeUndefined();
|
|
254
|
-
expect(element.node.children.length).toBe(0);
|
|
255
|
-
});
|
|
256
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var import_iterate = require("../iterate");
|
|
2
|
-
describe("throughExecProps", () => {
|
|
3
|
-
let element, ref;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
ref = {
|
|
6
|
-
__execProps: {}
|
|
7
|
-
};
|
|
8
|
-
element = {
|
|
9
|
-
__ref: ref,
|
|
10
|
-
props: {},
|
|
11
|
-
state: { test: "state" },
|
|
12
|
-
context: { test: "context" }
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
it("should cache and execute define-prefixed function props", () => {
|
|
16
|
-
element.props.isActive = () => true;
|
|
17
|
-
element.props.hasFeature = (el, state) => state.test === "state";
|
|
18
|
-
(0, import_iterate.throughExecProps)(element);
|
|
19
|
-
expect(element.props.isActive).toBe(true);
|
|
20
|
-
expect(element.props.hasFeature).toBe(true);
|
|
21
|
-
expect(ref.__execProps).toEqual({
|
|
22
|
-
isActive: expect.any(Function),
|
|
23
|
-
hasFeature: expect.any(Function)
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
it("should execute cached functions from previous runs", () => {
|
|
27
|
-
ref.__execProps.value = () => "cached";
|
|
28
|
-
element.props.value = "current";
|
|
29
|
-
(0, import_iterate.throughExecProps)(element);
|
|
30
|
-
expect(element.props.value).toBe("cached");
|
|
31
|
-
});
|
|
32
|
-
it("should leave non-function props unchanged", () => {
|
|
33
|
-
element.props.title = "static text";
|
|
34
|
-
element.props.disabled = false;
|
|
35
|
-
(0, import_iterate.throughExecProps)(element);
|
|
36
|
-
expect(element.props.title).toBe("static text");
|
|
37
|
-
expect(element.props.disabled).toBe(false);
|
|
38
|
-
expect(ref.__execProps).toEqual({});
|
|
39
|
-
});
|
|
40
|
-
it("should handle mixed define-prefixed and regular props", () => {
|
|
41
|
-
element.props.useHelper = () => "helper";
|
|
42
|
-
element.props.color = "blue";
|
|
43
|
-
(0, import_iterate.throughExecProps)(element);
|
|
44
|
-
expect(element.props.useHelper).toBe("helper");
|
|
45
|
-
expect(element.props.color).toBe("blue");
|
|
46
|
-
expect(ref.__execProps).toHaveProperty("useHelper");
|
|
47
|
-
});
|
|
48
|
-
it("should preserve existing cache entries", () => {
|
|
49
|
-
ref.__execProps.existing = () => "prior";
|
|
50
|
-
element.props.existing = "new";
|
|
51
|
-
(0, import_iterate.throughExecProps)(element);
|
|
52
|
-
expect(element.props.existing).toBe("prior");
|
|
53
|
-
expect(ref.__execProps.existing).toBeInstanceOf(Function);
|
|
54
|
-
});
|
|
55
|
-
it("should pass correct execution context", () => {
|
|
56
|
-
element.props.checkContext = function(el, state, context) {
|
|
57
|
-
return this === element && state === element.state && context === element.context;
|
|
58
|
-
};
|
|
59
|
-
(0, import_iterate.throughExecProps)(element);
|
|
60
|
-
expect(typeof element.props.checkContext).toBe("function");
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
var import_iterate = require("../iterate");
|
|
2
|
-
describe("throughInitialDefine", () => {
|
|
3
|
-
let element, ref;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
ref = {
|
|
6
|
-
__exec: {},
|
|
7
|
-
__defineCache: {}
|
|
8
|
-
};
|
|
9
|
-
element = {
|
|
10
|
-
__ref: ref,
|
|
11
|
-
define: {},
|
|
12
|
-
state: { testState: true },
|
|
13
|
-
context: { testContext: true }
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
it("should merge local and global define objects", () => {
|
|
17
|
-
element.define = { localProp: () => "local" };
|
|
18
|
-
element.context.define = { globalProp: () => "global" };
|
|
19
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
20
|
-
expect(element.localProp).toBe("local");
|
|
21
|
-
expect(element.globalProp).toBe("global");
|
|
22
|
-
});
|
|
23
|
-
it("should cache and execute define functions", () => {
|
|
24
|
-
element.define.testProp = (value) => "defined value";
|
|
25
|
-
element.testProp = () => "initial value";
|
|
26
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
27
|
-
expect(element.testProp).toBe("defined value");
|
|
28
|
-
expect(ref.__exec.testProp).toBeInstanceOf(Function);
|
|
29
|
-
expect(ref.__defineCache.testProp).toBe("initial value");
|
|
30
|
-
});
|
|
31
|
-
it("should skip execution for method properties", () => {
|
|
32
|
-
element.define.update = (value) => "should not execute";
|
|
33
|
-
element.update = () => "built-in method";
|
|
34
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
35
|
-
expect(ref.__exec).not.toHaveProperty("update");
|
|
36
|
-
expect(ref.__defineCache).not.toHaveProperty("update");
|
|
37
|
-
});
|
|
38
|
-
it("should handle parse method in execution result", () => {
|
|
39
|
-
element.define.testProp = () => ({ parse: () => "parsed value" });
|
|
40
|
-
element.testProp = () => "initial value";
|
|
41
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
42
|
-
expect(ref.__defineCache.testProp).toBe("initial value");
|
|
43
|
-
});
|
|
44
|
-
it("should pass correct arguments to define functions", () => {
|
|
45
|
-
element.define.testProp = (value, el, state, context) => ({
|
|
46
|
-
valueMatch: value === "initial value",
|
|
47
|
-
elMatch: el === element,
|
|
48
|
-
stateMatch: state === element.state,
|
|
49
|
-
contextMatch: context === element.context
|
|
50
|
-
});
|
|
51
|
-
element.testProp = "initial value";
|
|
52
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
53
|
-
expect(element.testProp).toEqual({
|
|
54
|
-
valueMatch: true,
|
|
55
|
-
elMatch: true,
|
|
56
|
-
stateMatch: true,
|
|
57
|
-
contextMatch: true
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
it("should handle non-function element properties", () => {
|
|
61
|
-
element.define.testProp = (value) => "defined value";
|
|
62
|
-
element.testProp = "non-function value";
|
|
63
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
64
|
-
expect(element.testProp).toBe("defined value");
|
|
65
|
-
});
|
|
66
|
-
it("should handle empty define objects", () => {
|
|
67
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
68
|
-
expect(element).toEqual({
|
|
69
|
-
...element,
|
|
70
|
-
__ref: ref
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
it("should handle null or undefined define properties", () => {
|
|
74
|
-
element.define.testProp = () => null;
|
|
75
|
-
element.testProp = "initial value";
|
|
76
|
-
(0, import_iterate.throughInitialDefine)(element);
|
|
77
|
-
expect(element.testProp).toBe("initial value");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var import_iterate = require("../iterate");
|
|
2
|
-
describe("throughInitialExec", () => {
|
|
3
|
-
let element, ref;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
ref = { __exec: {} };
|
|
6
|
-
element = {
|
|
7
|
-
__ref: ref,
|
|
8
|
-
state: { testState: true },
|
|
9
|
-
context: { testContext: true },
|
|
10
|
-
// Default non-method function
|
|
11
|
-
customFn: () => "executed"
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
it("should process non-method functions and update element properties", () => {
|
|
15
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
16
|
-
expect(element.customFn).toBe("executed");
|
|
17
|
-
expect(ref.__exec.customFn).toBeInstanceOf(Function);
|
|
18
|
-
});
|
|
19
|
-
it("should skip excluded parameters", () => {
|
|
20
|
-
element.excludedFn = () => "should not execute";
|
|
21
|
-
(0, import_iterate.throughInitialExec)(element, { excludedFn: true });
|
|
22
|
-
expect(element.excludedFn).toBeInstanceOf(Function);
|
|
23
|
-
expect(ref.__exec).not.toHaveProperty("excludedFn");
|
|
24
|
-
});
|
|
25
|
-
it("should skip methods from METHODS array", () => {
|
|
26
|
-
element.update = () => "built-in method";
|
|
27
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
28
|
-
expect(element.update).toBeInstanceOf(Function);
|
|
29
|
-
expect(ref.__exec).not.toHaveProperty("update");
|
|
30
|
-
});
|
|
31
|
-
it("should skip methods from context.methods", () => {
|
|
32
|
-
element.context.methods = { contextMethod: true };
|
|
33
|
-
element.contextMethod = () => "context method";
|
|
34
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
35
|
-
expect(element.contextMethod).toBeInstanceOf(Function);
|
|
36
|
-
expect(ref.__exec).not.toHaveProperty("contextMethod");
|
|
37
|
-
});
|
|
38
|
-
it("should leave non-function properties unchanged", () => {
|
|
39
|
-
element.stringProp = "text";
|
|
40
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
41
|
-
expect(element.stringProp).toBe("text");
|
|
42
|
-
expect(ref.__exec).not.toHaveProperty("stringProp");
|
|
43
|
-
});
|
|
44
|
-
it("should store original functions in __exec", () => {
|
|
45
|
-
const originalFn = () => "original";
|
|
46
|
-
element.testFn = originalFn;
|
|
47
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
48
|
-
expect(ref.__exec.testFn).toBe(originalFn);
|
|
49
|
-
expect(element.testFn).toBe("original");
|
|
50
|
-
});
|
|
51
|
-
it("should execute functions with correct arguments", () => {
|
|
52
|
-
element.argChecker = (el, state, context) => ({
|
|
53
|
-
elIsElement: el === element,
|
|
54
|
-
stateMatch: state === element.state,
|
|
55
|
-
contextMatch: context === element.context
|
|
56
|
-
});
|
|
57
|
-
(0, import_iterate.throughInitialExec)(element);
|
|
58
|
-
expect(element.argChecker).toEqual({
|
|
59
|
-
elIsElement: true,
|
|
60
|
-
stateMatch: true,
|
|
61
|
-
contextMatch: true
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it("should handle empty exclude object", () => {
|
|
65
|
-
element.fn1 = () => "one";
|
|
66
|
-
element.fn2 = () => "two";
|
|
67
|
-
(0, import_iterate.throughInitialExec)(element, {});
|
|
68
|
-
expect(element.fn1).toBe("one");
|
|
69
|
-
expect(element.fn2).toBe("two");
|
|
70
|
-
expect(ref.__exec).toHaveProperty("fn1");
|
|
71
|
-
expect(ref.__exec).toHaveProperty("fn2");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
var import_iterate = require("../iterate");
|
|
2
|
-
describe("throughUpdatedDefine", () => {
|
|
3
|
-
let element, ref;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
ref = {
|
|
6
|
-
__exec: {},
|
|
7
|
-
__defineCache: {}
|
|
8
|
-
};
|
|
9
|
-
element = {
|
|
10
|
-
__ref: ref,
|
|
11
|
-
define: {},
|
|
12
|
-
state: { testState: true },
|
|
13
|
-
context: { testContext: true }
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
it("should merge local and global define objects", () => {
|
|
17
|
-
element.define = { localProp: () => "local" };
|
|
18
|
-
element.context.define = { globalProp: () => "global" };
|
|
19
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
20
|
-
expect(element.localProp).toBe("local");
|
|
21
|
-
expect(element.globalProp).toBe("global");
|
|
22
|
-
});
|
|
23
|
-
it("should update element properties using cached exec functions", () => {
|
|
24
|
-
ref.__exec.testProp = () => "cached value";
|
|
25
|
-
element.define.testProp = (cached) => `updated ${cached}`;
|
|
26
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
27
|
-
expect(element.testProp).toBe("updated cached value");
|
|
28
|
-
expect(ref.__defineCache.testProp).toBe("cached value");
|
|
29
|
-
});
|
|
30
|
-
it("should handle non-function cached values", () => {
|
|
31
|
-
ref.__defineCache.testProp = "static value";
|
|
32
|
-
element.define.testProp = (cached) => `updated ${cached}`;
|
|
33
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
34
|
-
expect(element.testProp).toBe("updated static value");
|
|
35
|
-
});
|
|
36
|
-
it("should skip updates for undefined or null results", () => {
|
|
37
|
-
ref.__exec.testProp = () => "cached value";
|
|
38
|
-
element.define.testProp = () => null;
|
|
39
|
-
element.testProp = "original value";
|
|
40
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
41
|
-
expect(element.testProp).toBe("original value");
|
|
42
|
-
});
|
|
43
|
-
it("should handle empty define objects", () => {
|
|
44
|
-
const originalElement = { ...element };
|
|
45
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
46
|
-
expect(element).toEqual(originalElement);
|
|
47
|
-
});
|
|
48
|
-
it("should pass correct arguments to define functions", () => {
|
|
49
|
-
element.define.testProp = (cached, el, state, context) => ({
|
|
50
|
-
cachedMatch: cached === "cached value",
|
|
51
|
-
elMatch: el === element,
|
|
52
|
-
stateMatch: state === element.state,
|
|
53
|
-
contextMatch: context === element.context
|
|
54
|
-
});
|
|
55
|
-
ref.__defineCache.testProp = "cached value";
|
|
56
|
-
(0, import_iterate.throughUpdatedDefine)(element);
|
|
57
|
-
expect(element.testProp).toEqual({
|
|
58
|
-
cachedMatch: true,
|
|
59
|
-
elMatch: true,
|
|
60
|
-
stateMatch: true,
|
|
61
|
-
contextMatch: true
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it("should return an empty changes object", () => {
|
|
65
|
-
element.define.testProp = () => "updated value";
|
|
66
|
-
const changes = (0, import_iterate.throughUpdatedDefine)(element);
|
|
67
|
-
expect(changes).toEqual({});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
var import_iterate = require("../iterate");
|
|
2
|
-
describe("throughUpdatedExec", () => {
|
|
3
|
-
let element, ref;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
ref = {
|
|
6
|
-
__exec: {},
|
|
7
|
-
__defineCache: {}
|
|
8
|
-
};
|
|
9
|
-
element = {
|
|
10
|
-
__ref: ref,
|
|
11
|
-
state: { testState: true },
|
|
12
|
-
context: { testContext: true }
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
it("should skip execution for params in __defineCache", () => {
|
|
16
|
-
ref.__defineCache.cachedParam = true;
|
|
17
|
-
ref.__exec.cachedParam = () => "should not execute";
|
|
18
|
-
element.cachedParam = "original";
|
|
19
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
20
|
-
expect(element.cachedParam).toBe("original");
|
|
21
|
-
expect(changes).toEqual({});
|
|
22
|
-
});
|
|
23
|
-
it("should update element properties when newExec differs from current value", () => {
|
|
24
|
-
ref.__exec.testParam = () => "new value";
|
|
25
|
-
element.testParam = "old value";
|
|
26
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
27
|
-
expect(element.testParam).toBe("new value");
|
|
28
|
-
expect(changes).toEqual({ testParam: "old value" });
|
|
29
|
-
});
|
|
30
|
-
it("should overwrite text property for nodes when exec returns string or number", () => {
|
|
31
|
-
const node = { node: true, text: "old text" };
|
|
32
|
-
ref.__exec.testParam = () => "new text";
|
|
33
|
-
element.testParam = node;
|
|
34
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
35
|
-
expect(element.testParam.text).toBe("new text");
|
|
36
|
-
expect(changes).toEqual({});
|
|
37
|
-
});
|
|
38
|
-
it("should handle component naming matches and overwrite with context component", () => {
|
|
39
|
-
const contextComponent = { extends: "Component", prop: "value" };
|
|
40
|
-
element.context.components = { TestComponent: contextComponent };
|
|
41
|
-
ref.__exec.TestComponent = () => contextComponent;
|
|
42
|
-
element.TestComponent = { oldProp: "oldValue" };
|
|
43
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
44
|
-
expect(element.TestComponent).toEqual({
|
|
45
|
-
oldProp: "oldValue",
|
|
46
|
-
prop: "value"
|
|
47
|
-
});
|
|
48
|
-
expect(changes).toEqual({});
|
|
49
|
-
});
|
|
50
|
-
it("should not update element properties when newExec matches current value", () => {
|
|
51
|
-
ref.__exec.testParam = () => "same value";
|
|
52
|
-
element.testParam = "same value";
|
|
53
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
54
|
-
expect(element.testParam).toBe("same value");
|
|
55
|
-
expect(changes).toEqual({});
|
|
56
|
-
});
|
|
57
|
-
it("should handle non-string/non-number exec returns for non-node properties", () => {
|
|
58
|
-
const newValue = { complex: "object" };
|
|
59
|
-
ref.__exec.testParam = () => newValue;
|
|
60
|
-
element.testParam = "old value";
|
|
61
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
62
|
-
expect(element.testParam).toBe(newValue);
|
|
63
|
-
expect(changes).toEqual({ testParam: "old value" });
|
|
64
|
-
});
|
|
65
|
-
it("should return an empty changes object when no updates occur", () => {
|
|
66
|
-
ref.__exec.testParam = () => "same value";
|
|
67
|
-
element.testParam = "same value";
|
|
68
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
69
|
-
expect(changes).toEqual({});
|
|
70
|
-
});
|
|
71
|
-
it("should handle multiple properties and return correct changes", () => {
|
|
72
|
-
ref.__exec.param1 = () => "new value 1";
|
|
73
|
-
ref.__exec.param2 = () => "new value 2";
|
|
74
|
-
element.param1 = "old value 1";
|
|
75
|
-
element.param2 = "old value 2";
|
|
76
|
-
const changes = (0, import_iterate.throughUpdatedExec)(element);
|
|
77
|
-
expect(element.param1).toBe("new value 1");
|
|
78
|
-
expect(element.param2).toBe("new value 2");
|
|
79
|
-
expect(changes).toEqual({
|
|
80
|
-
param1: "old value 1",
|
|
81
|
-
param2: "old value 2"
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var import_tree = require("../tree");
|
|
2
|
-
describe("ROOT/TREE initialization and report()", () => {
|
|
3
|
-
it("initializes ROOT with :root key and document.body node", () => {
|
|
4
|
-
expect(import_tree.ROOT.key).toBe(":root");
|
|
5
|
-
expect(import_tree.ROOT.node).toBe(document.body);
|
|
6
|
-
});
|
|
7
|
-
it("assigns TREE to reference ROOT", () => {
|
|
8
|
-
expect(import_tree.TREE).toBe(import_tree.ROOT);
|
|
9
|
-
expect(import_tree.TREE.node).toBe(document.body);
|
|
10
|
-
});
|
|
11
|
-
});
|