@bigbinary/neeto-playwright-commons 4.11.14 → 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 CHANGED
@@ -846,7 +846,21 @@ declare class CustomCommands {
846
846
  }: ToggleElementProps) => Promise<void>;
847
847
  /**
848
848
  *
849
- * Method to move the cursor to bottom of a custom text editor. Before calling this method, please make sure the input field is focused.
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
+ *
851
+ * timeout (optional): Milliseconds to wait for the selection to collapse. Default is 2000.
852
+ *
853
+ * @example
854
+ *
855
+ * await page.keyboard.press("End");
856
+ * await neetoPlaywrightUtilities.waitForSelectionToCollapse();
857
+ * await page.keyboard.press("Enter");
858
+ * @endexample
859
+ */
860
+ waitForSelectionToCollapse: (timeout?: number) => Promise<void>;
861
+ /**
862
+ *
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.
850
864
  *
851
865
  * @example
852
866
  *
@@ -4163,7 +4177,7 @@ declare class EditorPage {
4163
4177
  private dismissToolbarMenu;
4164
4178
  /**
4165
4179
  *
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.
4180
+ * 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
4181
  *
4168
4182
  * @example
4169
4183
  *
package/index.js CHANGED
@@ -3480,6 +3480,24 @@ class CustomCommands {
3480
3480
  isChecked !== shouldBeChecked && (await locator.click());
3481
3481
  await expect(locator).toBeChecked({ checked: shouldBeChecked });
3482
3482
  }).toPass({ timeout: 15_000 });
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");
3483
3501
  moveCursorAtBottom = async () => {
3484
3502
  const isMacOS = os.platform() === "darwin";
3485
3503
  const rightArrowKey = isMacOS ? "Meta+ArrowRight" : "End";
@@ -3488,7 +3506,7 @@ class CustomCommands {
3488
3506
  await this.page.keyboard.press(rightArrowKey);
3489
3507
  await this.page.keyboard.press(rightArrowKey);
3490
3508
  await this.page.keyboard.press(downArrowKey);
3491
- await expect(this.page.locator(NEETO_EDITOR_SELECTORS.selectedText)).toHaveCount(0, { timeout: 2_000 });
3509
+ await this.waitForSelectionToCollapse();
3492
3510
  }).toPass({ timeout: 15_000 });
3493
3511
  await this.page.keyboard.press("Enter");
3494
3512
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-playwright-commons",
3
- "version": "4.11.14",
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",
@@ -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