@lynx-js/testing-environment 0.1.6 → 0.1.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lynx-js/testing-environment
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Support `lynx.createSelectorQuery().select()` and `setNativeProps` API ([#1570](https://github.com/lynx-family/lynx-stack/pull/1570))
8
+
3
9
  ## 0.1.6
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -53,10 +53,10 @@ function _define_property(obj, key, value) {
53
53
  return obj;
54
54
  }
55
55
  function __injectElementApi(target) {
56
- const elementTree = (0, ElementPAPI_cjs_namespaceObject.initElementTree)();
57
- target.elementTree = elementTree;
56
+ const elementTree1 = (0, ElementPAPI_cjs_namespaceObject.initElementTree)();
57
+ target.elementTree = elementTree1;
58
58
  if (void 0 === target) target = globalThis;
59
- for (const k of Object.getOwnPropertyNames(elementTree.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree[k].bind(elementTree);
59
+ for (const k of Object.getOwnPropertyNames(elementTree1.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree1[k].bind(elementTree1);
60
60
  target.$kTemplateAssembler = {};
61
61
  target.registerDataProcessor = ()=>{
62
62
  console.error('registerDataProcessor is not implemented');
@@ -202,8 +202,14 @@ class NodesRef {
202
202
  fields() {
203
203
  throw new Error('not implemented');
204
204
  }
205
- setNativeProps() {
206
- throw new Error('not implemented');
205
+ setNativeProps(props) {
206
+ return {
207
+ exec: ()=>{
208
+ const element = elementTree.uniqueId2Element.get(Number(this._nodeSelectToken.identifier));
209
+ if (!element) throw new Error(`[NodesRef.setNativeProps] Element not found for identifier=${this._nodeSelectToken.identifier}`);
210
+ if (element) for(const key in props)element.setAttributeNS(null, key, props[key]);
211
+ }
212
+ };
207
213
  }
208
214
  constructor(selectorQuery, nodeSelectToken){
209
215
  _define_property(this, "_nodeSelectToken", void 0);
@@ -242,6 +248,14 @@ function injectBackgroundThreadGlobals(target, polyfills) {
242
248
  type: 2,
243
249
  identifier: uniqueId.toString()
244
250
  });
251
+ },
252
+ select: function(selector) {
253
+ const el = lynxTestingEnv.jsdom.window.document.querySelector(selector);
254
+ if (!el) throw new Error(`[createSelectorQuery.select] No element matches selector: ${selector}`);
255
+ return new NodesRef({}, {
256
+ type: 0,
257
+ identifier: el.$$uiSign.toString()
258
+ });
245
259
  }
246
260
  }),
247
261
  getCoreContext: ()=>CoreContext,
package/dist/index.js CHANGED
@@ -14,10 +14,10 @@ function _define_property(obj, key, value) {
14
14
  return obj;
15
15
  }
16
16
  function __injectElementApi(target) {
17
- const elementTree = initElementTree();
18
- target.elementTree = elementTree;
17
+ const elementTree1 = initElementTree();
18
+ target.elementTree = elementTree1;
19
19
  if (void 0 === target) target = globalThis;
20
- for (const k of Object.getOwnPropertyNames(elementTree.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree[k].bind(elementTree);
20
+ for (const k of Object.getOwnPropertyNames(elementTree1.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree1[k].bind(elementTree1);
21
21
  target.$kTemplateAssembler = {};
22
22
  target.registerDataProcessor = ()=>{
23
23
  console.error('registerDataProcessor is not implemented');
@@ -163,8 +163,14 @@ class NodesRef {
163
163
  fields() {
164
164
  throw new Error('not implemented');
165
165
  }
166
- setNativeProps() {
167
- throw new Error('not implemented');
166
+ setNativeProps(props) {
167
+ return {
168
+ exec: ()=>{
169
+ const element = elementTree.uniqueId2Element.get(Number(this._nodeSelectToken.identifier));
170
+ if (!element) throw new Error(`[NodesRef.setNativeProps] Element not found for identifier=${this._nodeSelectToken.identifier}`);
171
+ if (element) for(const key in props)element.setAttributeNS(null, key, props[key]);
172
+ }
173
+ };
168
174
  }
169
175
  constructor(selectorQuery, nodeSelectToken){
170
176
  _define_property(this, "_nodeSelectToken", void 0);
@@ -203,6 +209,14 @@ function injectBackgroundThreadGlobals(target, polyfills) {
203
209
  type: 2,
204
210
  identifier: uniqueId.toString()
205
211
  });
212
+ },
213
+ select: function(selector) {
214
+ const el = lynxTestingEnv.jsdom.window.document.querySelector(selector);
215
+ if (!el) throw new Error(`[createSelectorQuery.select] No element matches selector: ${selector}`);
216
+ return new NodesRef({}, {
217
+ type: 0,
218
+ identifier: el.$$uiSign.toString()
219
+ });
206
220
  }
207
221
  }),
208
222
  getCoreContext: ()=>CoreContext,
@@ -38,11 +38,10 @@ function _define_property(obj, key, value) {
38
38
  }
39
39
  const initElementTree = ()=>{
40
40
  let uiSignNext = 0;
41
- const uniqueId2Element = new Map();
42
41
  return new class {
43
42
  countElement(element, parentComponentUniqueId) {
44
43
  element.$$uiSign = uiSignNext++;
45
- uniqueId2Element.set(element.$$uiSign, element);
44
+ this.uniqueId2Element.set(element.$$uiSign, element);
46
45
  element.parentComponentUniqueId = parentComponentUniqueId;
47
46
  }
48
47
  __CreatePage(_tag, parentComponentUniqueId) {
@@ -251,9 +250,10 @@ const initElementTree = ()=>{
251
250
  return this.toTree();
252
251
  }
253
252
  __GetElementByUniqueId(uniqueId) {
254
- return uniqueId2Element.get(uniqueId);
253
+ return this.uniqueId2Element.get(uniqueId);
255
254
  }
256
255
  constructor(){
256
+ _define_property(this, "uniqueId2Element", new Map());
257
257
  _define_property(this, "root", void 0);
258
258
  }
259
259
  }();
@@ -45,6 +45,7 @@ export interface LynxElement extends HTMLElement {
45
45
  * @public
46
46
  */
47
47
  export declare const initElementTree: () => {
48
+ uniqueId2Element: Map<number, LynxElement>;
48
49
  root: LynxElement | undefined;
49
50
  countElement(element: LynxElement, parentComponentUniqueId: number): void;
50
51
  __CreatePage(_tag: string, parentComponentUniqueId: number): LynxElement;
@@ -10,11 +10,10 @@ function _define_property(obj, key, value) {
10
10
  }
11
11
  const initElementTree = ()=>{
12
12
  let uiSignNext = 0;
13
- const uniqueId2Element = new Map();
14
13
  return new class {
15
14
  countElement(element, parentComponentUniqueId) {
16
15
  element.$$uiSign = uiSignNext++;
17
- uniqueId2Element.set(element.$$uiSign, element);
16
+ this.uniqueId2Element.set(element.$$uiSign, element);
18
17
  element.parentComponentUniqueId = parentComponentUniqueId;
19
18
  }
20
19
  __CreatePage(_tag, parentComponentUniqueId) {
@@ -223,9 +222,10 @@ const initElementTree = ()=>{
223
222
  return this.toTree();
224
223
  }
225
224
  __GetElementByUniqueId(uniqueId) {
226
- return uniqueId2Element.get(uniqueId);
225
+ return this.uniqueId2Element.get(uniqueId);
227
226
  }
228
227
  constructor(){
228
+ _define_property(this, "uniqueId2Element", new Map());
229
229
  _define_property(this, "root", void 0);
230
230
  }
231
231
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/testing-environment",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A subset of a Lynx environment to be useful for testing",
5
5
  "keywords": [
6
6
  "Lynx",
@@ -47,7 +47,7 @@
47
47
  "CHANGELOG.md"
48
48
  ],
49
49
  "devDependencies": {
50
- "@testing-library/jest-dom": "^6.7.0",
50
+ "@testing-library/jest-dom": "^6.8.0",
51
51
  "@types/jsdom": "^21.1.7",
52
52
  "rsbuild-plugin-publint": "0.3.3"
53
53
  },