@blotch/angular-lynx-testing-library 22.2.17 → 22.2.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDpB,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,OAAO,QAAQ,CAAC;AACvC,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;AAC/E,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG;KAC3D,CAAC,IAAI,SAAS,GAAG,YAAY;CAC/B,CAAC;AA+JF,eAAO,MAAM,SAAS,EAAE,SAET,CAAC"}
1
+ {"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDpB,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,OAAO,QAAQ,CAAC;AACvC,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;AAC/E,KAAK,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG;KAC3D,CAAC,IAAI,SAAS,GAAG,YAAY;CAC/B,CAAC;AAsLF,eAAO,MAAM,SAAS,EAAE,SAET,CAAC"}
@@ -220,12 +220,29 @@ const keepDetail = (event) => {
220
220
  }
221
221
  return event;
222
222
  };
223
+ /**
224
+ * Puts the text an `input` event reports in its field, where a device's field
225
+ * has it as it sends the event: the user typed it there. So `input.value`
226
+ * reads it after, as the bound value does, and the runtime, which doesn't set
227
+ * a field to the text it shows already (see LynxElement's setProperty),
228
+ * leaves it there when the binding hands it back.
229
+ */
230
+ const typeInto = (elem, name, init) => {
231
+ const value = init['detail']?.value;
232
+ if (name === 'input' &&
233
+ typeof value === 'string' &&
234
+ // A missing element is reported by the delivery that follows.
235
+ /^(input|textarea)$/i.test(String(elem?.tagName))) {
236
+ elem.value = value;
237
+ }
238
+ };
223
239
  export const fireEvent = ((elem, event) => {
224
240
  return domFireEvent(elem, keepDetail(event));
225
241
  });
226
242
  for (const key of Object.keys(eventMap)) {
227
243
  fireEvent[key] = (elem, init) => {
228
244
  const { eventType, ...rest } = init ?? {};
245
+ typeInto(elem, key, rest);
229
246
  if (eventType === undefined) {
230
247
  const eventInit = { ...eventMap[key].defaultInit, ...rest };
231
248
  // Run through Testing Library's eventWrapper, as its fireEvent runs a
package/dist/setup.js CHANGED
@@ -221,13 +221,34 @@ globalThis.__GetChildren = (e) => Array.from(e.children);
221
221
  */
222
222
  globalThis.__SetConfig = () => { };
223
223
  /**
224
- * Invokes a native UI method by name (e.g. the `setValue` UIMethod that Lynx
225
- * inputs/textareas require for programmatic text updates — see
226
- * LynxElement.invoke() in the runtime). LynxElement.invoke() always passes an
227
- * empty result callback, so a no-op that still calls back (matching the real
228
- * host's async {code, data} contract) is sufficient here.
224
+ * Whether `element` is a text field: an `<input>` or `<textarea>`, which the
225
+ * testing environment makes a JSDOM input or textarea.
229
226
  */
230
- globalThis.__InvokeUIMethod = (_element, _methodName, _params, callback) => {
227
+ const isTextField = (element) => /^(input|textarea)$/i.test(element?.tagName ?? '');
228
+ /**
229
+ * Invokes a native UI method by name. A text field's `setValue` puts the
230
+ * text in the JSDOM field's `value`, where a test reads it (`input.value`,
231
+ * `toHaveValue`), and `getValue` reads it back: the runtime shows a bound
232
+ * value with setValue (see LynxElement's setProperty), so a field shows on
233
+ * screen what it reads here. Other methods do nothing. Each answers at once
234
+ * that it ran, as a device answers for an element whose UI it has made.
235
+ */
236
+ globalThis.__InvokeUIMethod = (element, methodName, params, callback) => {
237
+ if (isTextField(element) && methodName === 'setValue') {
238
+ element.value = String(params?.value ?? '');
239
+ }
240
+ if (isTextField(element) && methodName === 'getValue') {
241
+ callback?.({
242
+ code: 0,
243
+ data: {
244
+ value: element.value,
245
+ selectionStart: -1,
246
+ selectionEnd: -1,
247
+ isComposing: false,
248
+ },
249
+ });
250
+ return;
251
+ }
231
252
  callback?.({ code: 0 });
232
253
  };
233
254
  // ─── After reset ─────────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/angular-lynx-testing-library",
3
- "version": "22.2.17",
3
+ "version": "22.2.19",
4
4
  "description": "Testing utilities for AngularLynx apps",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {