DEV: Move duplicate `selectText` helper into qunit-helpers

DEV: Move duplicate selectText helper into qunit-helpers

diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js
index 7ddeca5..d553538 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js
@@ -3,20 +3,11 @@ import {
   chromeTest,
   exists,
   queryAll,
+  selectText,
 } from "discourse/tests/helpers/qunit-helpers";
 import I18n from "I18n";
 import { settled, visit } from "@ember/test-helpers";
 
-async function selectText(selector) {
-  const range = document.createRange();
-  const node = document.querySelector(selector);
-  range.selectNodeContents(node);
-
-  const selection = window.getSelection();
-  selection.removeAllRanges();
-  selection.addRange(range);
-  await settled();
-}
 
 // This tests are flaky on Firefox. Fails with `calling set on destroyed object`
 acceptance("Topic - Quote button - logged in", function (needs) {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
index 584989f..a4f5380 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
@@ -5,31 +5,15 @@ import {
   exists,
   query,
   queryAll,
+  selectText,
   visible,
 } from "discourse/tests/helpers/qunit-helpers";
-import {
-  click,
-  fillIn,
-  settled,
-  triggerKeyEvent,
-  visit,
-} from "@ember/test-helpers";
+import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
 import I18n from "I18n";
 import selectKit from "discourse/tests/helpers/select-kit-helper";
 import { test } from "qunit";
 import { withPluginApi } from "discourse/lib/plugin-api";
 
-async function selectText(selector) {
-  const range = document.createRange();
-  const node = document.querySelector(selector);
-  range.selectNodeContents(node);
-
-  const selection = window.getSelection();
-  selection.removeAllRanges();
-  selection.addRange(range);
-  await settled();
-}
-
 acceptance("Topic", function (needs) {
   needs.user();
   needs.pretender((server, helper) => {
diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
index 8841b86..76a0889 100644
--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
@@ -10,7 +10,7 @@ import {
   mergeSettings,
 } from "discourse/tests/helpers/site-settings";
 import { forceMobile, resetMobile } from "discourse/lib/mobile";
-import { getApplication, getContext } from "@ember/test-helpers";
+import { getApplication, getContext, settled } from "@ember/test-helpers";
 import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
 import { later, run } from "@ember/runloop";
 import { moduleFor, setupApplicationTest } from "ember-qunit";
@@ -479,6 +479,28 @@ export function publishToMessageBus(channelPath, ...args) {
     .map((c) => c.func(...args));
 }
 
+export async function selectText(selector, endOffset = null) {
+  const range = document.createRange();
+  let node;
+
+  if (typeof selector === "string") {
+    node = document.querySelector(selector);
+  } else {
+    node = selector;
+  }
+
+  range.selectNodeContents(node);
+
+  if (endOffset) {
+    range.setEnd(node, endOffset);
+  }
+
+  const selection = window.getSelection();
+  selection.removeAllRanges();
+  selection.addRange(range);
+  await settled();
+}
+
 export function conditionalTest(name, condition, testCase) {
   if (condition) {
     test(name, testCase);

GitHub sha: 9a3a5b19e9d8768d2d7e294db01939f4dd4025cb

This commit appears in #14563 which was approved by eviltrout. It was merged by davidtaylorhq.