@sovovs/bycli 2.1.27 → 2.1.28

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.
@@ -102,21 +102,52 @@ async function fillField(page, selector, value) {
102
102
  }
103
103
 
104
104
  async function fillContent(page, text) {
105
- return page.evaluate(`(() => {
105
+ var result = await page.evaluate(`(() => {
106
+ var normalize = value => String(value ?? '').replace(/\\r\\n?/g, '\\n').trim();
107
+ var expected = normalize(${JSON.stringify(text)});
108
+ var instances = window.UE && window.UE.instants ? Object.values(window.UE.instants) : [];
109
+ var ueditor = instances.find(instance => instance
110
+ && typeof instance.setContent === 'function'
111
+ && typeof instance.getContentTxt === 'function');
112
+ if (ueditor && typeof ueditor.setContent === 'function' && typeof ueditor.getContentTxt === 'function') {
113
+ ueditor.setContent(${JSON.stringify(text)});
114
+ var ueditorActual = normalize(ueditor.getContentTxt());
115
+ if (ueditorActual === expected) {
116
+ return { ok: true, value: ueditorActual };
117
+ }
118
+ }
106
119
  var editors = document.querySelectorAll('div[contenteditable="true"]');
107
120
  var editor = editors[editors.length - 1];
108
121
  if (!editor) return { ok: false, reason: 'content editor not found' };
109
122
  editor.focus();
110
123
  if (editor.querySelector('[contenteditable="false"]')) editor.innerHTML = '';
111
- document.execCommand('selectAll', false, null);
112
- document.execCommand('insertText', false, ${JSON.stringify(text)});
113
- editor.dispatchEvent(new InputEvent('input', { bubbles: true }));
124
+ var selection = window.getSelection();
125
+ if (!selection) return { ok: false, reason: 'text selection is unavailable' };
126
+ var range = document.createRange();
127
+ range.selectNodeContents(editor);
128
+ selection.removeAllRanges();
129
+ selection.addRange(range);
130
+ return { ok: false, nativeTargetFocused: true };
131
+ })()`);
132
+
133
+ if (!result?.nativeTargetFocused || typeof page.nativeType !== 'function') return result;
134
+
135
+ try {
136
+ await page.nativeType(text);
137
+ } catch {
138
+ return result;
139
+ }
140
+
141
+ return page.evaluate(`(() => {
114
142
  var normalize = value => String(value ?? '').replace(/\\r\\n?/g, '\\n').trim();
115
143
  var expected = normalize(${JSON.stringify(text)});
144
+ var editors = document.querySelectorAll('div[contenteditable="true"]');
145
+ var editor = editors[editors.length - 1];
146
+ if (!editor) return { ok: false, reason: 'content editor not found' };
116
147
  var actual = normalize(editor.innerText ?? editor.textContent ?? '');
117
148
  return actual === expected
118
149
  ? { ok: true, value: actual }
119
- : { ok: false, reason: 'value mismatch', value: actual };
150
+ : { ok: false, reason: 'editor content verification failed', value: actual };
120
151
  })()`);
121
152
  }
122
153
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovovs/bycli",
3
- "version": "2.1.27",
3
+ "version": "2.1.28",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },