@bigbinary/neeto-playwright-commons 4.11.14 → 4.11.15-beta1
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/index.d.ts +22 -2
- package/index.js +33 -1
- package/package.json +2 -2
- package/scripts/neeto-auth/setup.sh +0 -0
package/index.d.ts
CHANGED
|
@@ -846,7 +846,27 @@ declare class CustomCommands {
|
|
|
846
846
|
}: ToggleElementProps) => Promise<void>;
|
|
847
847
|
/**
|
|
848
848
|
*
|
|
849
|
-
* Method
|
|
849
|
+
* Method that returns a page-side promise handle which settles once the DOM selection is collapsed, or rejects once timeout elapses. Create it before the key press that moves the caret so a selectionchange that fires straight away is not missed, await it with handle.evaluate(({ promise }) => promise), then dispose the handle.
|
|
850
|
+
*
|
|
851
|
+
* timeout (optional): Milliseconds to wait for the selection to collapse before rejecting. Default is 2000.
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
*
|
|
855
|
+
* const selectionCollapsed = await neetoPlaywrightUtilities.waitForSelectionToCollapse();
|
|
856
|
+
* await page.keyboard.press("End");
|
|
857
|
+
* try {
|
|
858
|
+
* await selectionCollapsed.evaluate(({ promise }) => promise);
|
|
859
|
+
* } finally {
|
|
860
|
+
* await selectionCollapsed.dispose();
|
|
861
|
+
* }
|
|
862
|
+
* @endexample
|
|
863
|
+
*/
|
|
864
|
+
waitForSelectionToCollapse: (timeout?: number) => Promise<_playwright_test.JSHandle<{
|
|
865
|
+
promise: Promise<void>;
|
|
866
|
+
}>>;
|
|
867
|
+
/**
|
|
868
|
+
*
|
|
869
|
+
* Method to move the cursor to bottom of a custom text editor. Before calling this method, please make sure the input field is focused. It waits for the editor selection to collapse (via waitForSelectionToCollapse) before pressing Enter, so a word selected before the call is not replaced.
|
|
850
870
|
*
|
|
851
871
|
* @example
|
|
852
872
|
*
|
|
@@ -4163,7 +4183,7 @@ declare class EditorPage {
|
|
|
4163
4183
|
private dismissToolbarMenu;
|
|
4164
4184
|
/**
|
|
4165
4185
|
*
|
|
4166
|
-
* Method to move the cursor to bottom of a custom text editor. Before calling this method, please make sure the input field is focused.
|
|
4186
|
+
* Method to move the cursor to bottom of a custom text editor. Before calling this method, please make sure the input field is focused. It waits for the editor selection to collapse (via waitForSelectionToCollapse) before pressing Enter, so a word selected before the call is not replaced.
|
|
4167
4187
|
*
|
|
4168
4188
|
* @example
|
|
4169
4189
|
*
|
package/index.js
CHANGED
|
@@ -3480,15 +3480,47 @@ class CustomCommands {
|
|
|
3480
3480
|
isChecked !== shouldBeChecked && (await locator.click());
|
|
3481
3481
|
await expect(locator).toBeChecked({ checked: shouldBeChecked });
|
|
3482
3482
|
}).toPass({ timeout: 15_000 });
|
|
3483
|
+
// Returns a page-side promise that settles once the DOM selection is
|
|
3484
|
+
// collapsed, or rejects after `timeout` ms. Create it before the key press
|
|
3485
|
+
// that moves the caret so a selectionchange that fires straight away is not
|
|
3486
|
+
// missed. Both outcomes detach the listener, so nothing outlives the wait.
|
|
3487
|
+
waitForSelectionToCollapse = (timeout = 2_000) => this.page.evaluateHandle(timeout => ({
|
|
3488
|
+
promise: new Promise((resolve, reject) => {
|
|
3489
|
+
const isCollapsed = () => window.getSelection()?.isCollapsed !== false;
|
|
3490
|
+
if (isCollapsed())
|
|
3491
|
+
return resolve();
|
|
3492
|
+
let timer;
|
|
3493
|
+
const onSelectionChange = () => {
|
|
3494
|
+
if (!isCollapsed())
|
|
3495
|
+
return;
|
|
3496
|
+
clearTimeout(timer);
|
|
3497
|
+
document.removeEventListener("selectionchange", onSelectionChange);
|
|
3498
|
+
resolve();
|
|
3499
|
+
};
|
|
3500
|
+
timer = setTimeout(() => {
|
|
3501
|
+
document.removeEventListener("selectionchange", onSelectionChange);
|
|
3502
|
+
reject(new Error("Editor selection did not collapse"));
|
|
3503
|
+
}, timeout);
|
|
3504
|
+
document.addEventListener("selectionchange", onSelectionChange);
|
|
3505
|
+
}),
|
|
3506
|
+
}), timeout);
|
|
3483
3507
|
moveCursorAtBottom = async () => {
|
|
3484
3508
|
const isMacOS = os.platform() === "darwin";
|
|
3485
3509
|
const rightArrowKey = isMacOS ? "Meta+ArrowRight" : "End";
|
|
3486
3510
|
const downArrowKey = isMacOS ? "Meta+ArrowDown" : "PageDown";
|
|
3487
3511
|
await expect(async () => {
|
|
3512
|
+
// ProseMirror adopts a keyboard-moved caret only on selectionchange, which
|
|
3513
|
+
// can land after the next key press; an early Enter replaces the selection.
|
|
3514
|
+
const selectionCollapsed = await this.waitForSelectionToCollapse();
|
|
3488
3515
|
await this.page.keyboard.press(rightArrowKey);
|
|
3489
3516
|
await this.page.keyboard.press(rightArrowKey);
|
|
3490
3517
|
await this.page.keyboard.press(downArrowKey);
|
|
3491
|
-
|
|
3518
|
+
try {
|
|
3519
|
+
await selectionCollapsed.evaluate(({ promise }) => promise);
|
|
3520
|
+
}
|
|
3521
|
+
finally {
|
|
3522
|
+
await selectionCollapsed.dispose();
|
|
3523
|
+
}
|
|
3492
3524
|
}).toPass({ timeout: 15_000 });
|
|
3493
3525
|
await this.page.keyboard.press("Enter");
|
|
3494
3526
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-playwright-commons",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.15-beta1",
|
|
4
4
|
"description": "A package encapsulating common playwright code across neeto projects.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-playwright-commons.git",
|
|
6
6
|
"license": "apache-2.0",
|
|
@@ -106,4 +106,4 @@
|
|
|
106
106
|
"puppeteer-extra-plugin-stealth": "2.11.2"
|
|
107
107
|
},
|
|
108
108
|
"packageManager": "yarn@4.18.1"
|
|
109
|
-
}
|
|
109
|
+
}
|
|
File without changes
|