mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 12:43:54 -06:00
DEV: Move duplicate selectText
helper into qunit-helpers
This commit is contained in:
parent
9efc57f0c6
commit
9a3a5b19e9
@ -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) {
|
||||
|
@ -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) => {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user