REFACTOR: Replace global find with queryAll
In newer Embers jQuery is removed. There is a `find` but it only returns one element and not a jQuery selector. This patch migrates our code to a new helper `queryAll` which allows us to remove the global.
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { moduleForWidget, widgetTest } from "discourse/tests/helpers/widget-test";
|
||||
import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForWidget("discourse-poll-option");
|
||||
|
||||
const template = `{{mount-widget
|
||||
@@ -14,7 +19,7 @@ widgetTest("single, not selected", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find("li .d-icon-far-circle:eq(0)").length === 1);
|
||||
assert.ok(queryAll("li .d-icon-far-circle:eq(0)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -27,7 +32,7 @@ widgetTest("single, selected", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find("li .d-icon-circle:eq(0)").length === 1);
|
||||
assert.ok(queryAll("li .d-icon-circle:eq(0)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -43,7 +48,7 @@ widgetTest("multi, not selected", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find("li .d-icon-far-square:eq(0)").length === 1);
|
||||
assert.ok(queryAll("li .d-icon-far-square:eq(0)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -59,6 +64,6 @@ widgetTest("multi, selected", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(find("li .d-icon-far-check-square:eq(0)").length === 1);
|
||||
assert.ok(queryAll("li .d-icon-far-check-square:eq(0)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import { moduleForWidget, widgetTest } from "discourse/tests/helpers/widget-test";
|
||||
import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForWidget("discourse-poll-standard-results");
|
||||
|
||||
@@ -21,8 +25,8 @@ widgetTest("options in descending order", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
||||
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
||||
assert.equal(queryAll(".option .percentage:eq(0)").text(), "56%");
|
||||
assert.equal(queryAll(".option .percentage:eq(1)").text(), "44%");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -40,8 +44,8 @@ widgetTest("options in ascending order", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
||||
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
||||
assert.equal(queryAll(".option .percentage:eq(0)").text(), "56%");
|
||||
assert.equal(queryAll(".option .percentage:eq(1)").text(), "44%");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -67,12 +71,12 @@ widgetTest("multiple options in descending order", {
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(find(".option .percentage:eq(0)").text(), "41%");
|
||||
assert.equal(find(".option .percentage:eq(1)").text(), "33%");
|
||||
assert.equal(find(".option .percentage:eq(2)").text(), "16%");
|
||||
assert.equal(find(".option .percentage:eq(3)").text(), "8%");
|
||||
assert.equal(find(".option span:nth-child(2):eq(3)").text(), "a");
|
||||
assert.equal(find(".option .percentage:eq(4)").text(), "8%");
|
||||
assert.equal(find(".option span:nth-child(2):eq(4)").text(), "b");
|
||||
assert.equal(queryAll(".option .percentage:eq(0)").text(), "41%");
|
||||
assert.equal(queryAll(".option .percentage:eq(1)").text(), "33%");
|
||||
assert.equal(queryAll(".option .percentage:eq(2)").text(), "16%");
|
||||
assert.equal(queryAll(".option .percentage:eq(3)").text(), "8%");
|
||||
assert.equal(queryAll(".option span:nth-child(2):eq(3)").text(), "a");
|
||||
assert.equal(queryAll(".option .percentage:eq(4)").text(), "8%");
|
||||
assert.equal(queryAll(".option span:nth-child(2):eq(4)").text(), "b");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
let requests = 0;
|
||||
|
||||
@@ -99,16 +100,17 @@ widgetTest("can vote", {
|
||||
|
||||
await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(find(".chosen").length, 1);
|
||||
assert.equal(find(".chosen").text(), "100%yes");
|
||||
assert.equal(find(".toggle-results").text(), "Show vote");
|
||||
assert.equal(queryAll(".chosen").length, 1);
|
||||
assert.equal(queryAll(".chosen").text(), "100%yes");
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show vote");
|
||||
|
||||
await click(".toggle-results");
|
||||
assert.equal(
|
||||
find("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']").length,
|
||||
queryAll("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']")
|
||||
.length,
|
||||
1
|
||||
);
|
||||
assert.equal(find(".toggle-results").text(), "Show results");
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show results");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -146,10 +148,10 @@ widgetTest("cannot vote if not member of the right group", {
|
||||
|
||||
await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
|
||||
assert.equal(
|
||||
find(".poll-container .alert").text(),
|
||||
queryAll(".poll-container .alert").text(),
|
||||
I18n.t("poll.results.groups.title", { groups: "foo" })
|
||||
);
|
||||
assert.equal(requests, 0);
|
||||
assert.equal(find(".chosen").length, 0);
|
||||
assert.equal(queryAll(".chosen").length, 0);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user