@bigbinary/neeto-playwright-commons 4.11.15-beta1 → 4.11.15-beta2
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 +5 -11
- package/index.js +19 -33
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -846,24 +846,18 @@ declare class CustomCommands {
|
|
|
846
846
|
}: ToggleElementProps) => Promise<void>;
|
|
847
847
|
/**
|
|
848
848
|
*
|
|
849
|
-
* Method that
|
|
849
|
+
* Method that waits until the focused editor's own selection is collapsed, by polling the ProseMirror state of the editor that owns document.activeElement. Use it before a key press that would replace a selection, such as Enter. Fails if no editor is focused or the selection is still a range when the timeout elapses.
|
|
850
850
|
*
|
|
851
|
-
* timeout (optional): Milliseconds to wait for the selection to collapse
|
|
851
|
+
* timeout (optional): Milliseconds to wait for the selection to collapse. Default is 2000.
|
|
852
852
|
*
|
|
853
853
|
* @example
|
|
854
854
|
*
|
|
855
|
-
* const selectionCollapsed = await neetoPlaywrightUtilities.waitForSelectionToCollapse();
|
|
856
855
|
* await page.keyboard.press("End");
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
* } finally {
|
|
860
|
-
* await selectionCollapsed.dispose();
|
|
861
|
-
* }
|
|
856
|
+
* await neetoPlaywrightUtilities.waitForSelectionToCollapse();
|
|
857
|
+
* await page.keyboard.press("Enter");
|
|
862
858
|
* @endexample
|
|
863
859
|
*/
|
|
864
|
-
waitForSelectionToCollapse: (timeout?: number) => Promise<
|
|
865
|
-
promise: Promise<void>;
|
|
866
|
-
}>>;
|
|
860
|
+
waitForSelectionToCollapse: (timeout?: number) => Promise<void>;
|
|
867
861
|
/**
|
|
868
862
|
*
|
|
869
863
|
* 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.
|
package/index.js
CHANGED
|
@@ -3480,47 +3480,33 @@ class CustomCommands {
|
|
|
3480
3480
|
isChecked !== shouldBeChecked && (await locator.click());
|
|
3481
3481
|
await expect(locator).toBeChecked({ checked: shouldBeChecked });
|
|
3482
3482
|
}).toPass({ timeout: 15_000 });
|
|
3483
|
-
//
|
|
3484
|
-
//
|
|
3485
|
-
//
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
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
|
+
// Polls the editor's own state, which is what the next key press acts on.
|
|
3484
|
+
// The DOM selection is not proof: ProseMirror re-applies its stored
|
|
3485
|
+
// selection shortly after a programmatic focus, undoing an early collapse.
|
|
3486
|
+
waitForSelectionToCollapse = (timeout = 2_000) => expect
|
|
3487
|
+
.poll(() => this.page.evaluate(contentField => {
|
|
3488
|
+
const editor = document.activeElement?.closest(`[data-testid="${contentField}"]`)?.editor;
|
|
3489
|
+
if (!editor)
|
|
3490
|
+
return "no focused editor";
|
|
3491
|
+
const { selection } = editor.state;
|
|
3492
|
+
return selection.empty
|
|
3493
|
+
? "collapsed"
|
|
3494
|
+
: `${selection.from}-${selection.to}`;
|
|
3495
|
+
}, NEETO_EDITOR_SELECTORS.contentField), {
|
|
3496
|
+
timeout,
|
|
3497
|
+
intervals: [50, 100, 250],
|
|
3498
|
+
message: "Editor selection did not collapse",
|
|
3499
|
+
})
|
|
3500
|
+
.toBe("collapsed");
|
|
3507
3501
|
moveCursorAtBottom = async () => {
|
|
3508
3502
|
const isMacOS = os.platform() === "darwin";
|
|
3509
3503
|
const rightArrowKey = isMacOS ? "Meta+ArrowRight" : "End";
|
|
3510
3504
|
const downArrowKey = isMacOS ? "Meta+ArrowDown" : "PageDown";
|
|
3511
3505
|
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();
|
|
3515
3506
|
await this.page.keyboard.press(rightArrowKey);
|
|
3516
3507
|
await this.page.keyboard.press(rightArrowKey);
|
|
3517
3508
|
await this.page.keyboard.press(downArrowKey);
|
|
3518
|
-
|
|
3519
|
-
await selectionCollapsed.evaluate(({ promise }) => promise);
|
|
3520
|
-
}
|
|
3521
|
-
finally {
|
|
3522
|
-
await selectionCollapsed.dispose();
|
|
3523
|
-
}
|
|
3509
|
+
await this.waitForSelectionToCollapse();
|
|
3524
3510
|
}).toPass({ timeout: 15_000 });
|
|
3525
3511
|
await this.page.keyboard.press("Enter");
|
|
3526
3512
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-playwright-commons",
|
|
3
|
-
"version": "4.11.15-
|
|
3
|
+
"version": "4.11.15-beta2",
|
|
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",
|