mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 13:25:50 +08:00
FIX: Lots of plugin tests were using old, non-Ember compat CLI APIs (#13320)
This commit is contained in:
@ -1,71 +1,81 @@
|
||||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
discourseModule,
|
||||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForWidget("discourse-poll-option");
|
||||
|
||||
const template = `{{mount-widget
|
||||
discourseModule(
|
||||
"Integration | Component | Widget | discourse-poll-option",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
const template = `{{mount-widget
|
||||
widget="discourse-poll-option"
|
||||
args=(hash option=option isMultiple=isMultiple vote=vote)}}`;
|
||||
|
||||
widgetTest("single, not selected", {
|
||||
template,
|
||||
componentTest("single, not selected", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.set("option", { id: "opt-id" });
|
||||
this.set("vote", []);
|
||||
},
|
||||
beforeEach() {
|
||||
this.set("option", { id: "opt-id" });
|
||||
this.set("vote", []);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(queryAll("li .d-icon-far-circle:nth-of-type(1)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
widgetTest("single, selected", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.set("option", { id: "opt-id" });
|
||||
this.set("vote", ["opt-id"]);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(queryAll("li .d-icon-circle:nth-of-type(1)").length === 1);
|
||||
},
|
||||
});
|
||||
|
||||
widgetTest("multi, not selected", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: "opt-id" },
|
||||
isMultiple: true,
|
||||
vote: [],
|
||||
test(assert) {
|
||||
assert.ok(
|
||||
queryAll("li .d-icon-far-circle:nth-of-type(1)").length === 1
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(queryAll("li .d-icon-far-square:nth-of-type(1)").length === 1);
|
||||
},
|
||||
});
|
||||
componentTest("single, selected", {
|
||||
template,
|
||||
|
||||
widgetTest("multi, selected", {
|
||||
template,
|
||||
beforeEach() {
|
||||
this.set("option", { id: "opt-id" });
|
||||
this.set("vote", ["opt-id"]);
|
||||
},
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: "opt-id" },
|
||||
isMultiple: true,
|
||||
vote: ["opt-id"],
|
||||
test(assert) {
|
||||
assert.ok(queryAll("li .d-icon-circle:nth-of-type(1)").length === 1);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(
|
||||
queryAll("li .d-icon-far-check-square:nth-of-type(1)").length === 1
|
||||
);
|
||||
},
|
||||
});
|
||||
componentTest("multi, not selected", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: "opt-id" },
|
||||
isMultiple: true,
|
||||
vote: [],
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(
|
||||
queryAll("li .d-icon-far-square:nth-of-type(1)").length === 1
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("multi, selected", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: "opt-id" },
|
||||
isMultiple: true,
|
||||
vote: ["opt-id"],
|
||||
});
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(
|
||||
queryAll("li .d-icon-far-check-square:nth-of-type(1)").length === 1
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -1,90 +1,97 @@
|
||||
import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import EmberObject from "@ember/object";
|
||||
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
import {
|
||||
discourseModule,
|
||||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
moduleForWidget("discourse-poll-standard-results");
|
||||
discourseModule(
|
||||
"Integration | Component | Widget | discourse-poll-standard-results",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
const template = `{{mount-widget
|
||||
const template = `{{mount-widget
|
||||
widget="discourse-poll-standard-results"
|
||||
args=(hash poll=poll isMultiple=isMultiple)}}`;
|
||||
|
||||
widgetTest("options in descending order", {
|
||||
template,
|
||||
componentTest("options in descending order", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
options: [{ votes: 5 }, { votes: 4 }],
|
||||
voters: 9,
|
||||
})
|
||||
);
|
||||
},
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
options: [{ votes: 5 }, { votes: 4 }],
|
||||
voters: 9,
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
||||
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
||||
},
|
||||
});
|
||||
test(assert) {
|
||||
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
||||
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
||||
},
|
||||
});
|
||||
|
||||
widgetTest("options in ascending order", {
|
||||
template,
|
||||
componentTest("options in ascending order", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
options: [{ votes: 4 }, { votes: 5 }],
|
||||
voters: 9,
|
||||
})
|
||||
);
|
||||
},
|
||||
beforeEach() {
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
options: [{ votes: 4 }, { votes: 5 }],
|
||||
voters: 9,
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
||||
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
||||
},
|
||||
});
|
||||
test(assert) {
|
||||
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
||||
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
||||
},
|
||||
});
|
||||
|
||||
widgetTest("multiple options in descending order", {
|
||||
template,
|
||||
componentTest("multiple options in descending order", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.set("isMultiple", true);
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
type: "multiple",
|
||||
options: [
|
||||
{ votes: 5, html: "a" },
|
||||
{ votes: 2, html: "b" },
|
||||
{ votes: 4, html: "c" },
|
||||
{ votes: 1, html: "b" },
|
||||
{ votes: 1, html: "a" },
|
||||
],
|
||||
voters: 12,
|
||||
})
|
||||
);
|
||||
},
|
||||
beforeEach() {
|
||||
this.set("isMultiple", true);
|
||||
this.set(
|
||||
"poll",
|
||||
EmberObject.create({
|
||||
type: "multiple",
|
||||
options: [
|
||||
{ votes: 5, html: "a" },
|
||||
{ votes: 2, html: "b" },
|
||||
{ votes: 4, html: "c" },
|
||||
{ votes: 1, html: "b" },
|
||||
{ votes: 1, html: "a" },
|
||||
],
|
||||
voters: 12,
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
let percentages = queryAll(".option .percentage");
|
||||
assert.equal(percentages[0].innerText, "41%");
|
||||
assert.equal(percentages[1].innerText, "33%");
|
||||
assert.equal(percentages[2].innerText, "16%");
|
||||
assert.equal(percentages[3].innerText, "8%");
|
||||
test(assert) {
|
||||
let percentages = queryAll(".option .percentage");
|
||||
assert.equal(percentages[0].innerText, "41%");
|
||||
assert.equal(percentages[1].innerText, "33%");
|
||||
assert.equal(percentages[2].innerText, "16%");
|
||||
assert.equal(percentages[3].innerText, "8%");
|
||||
|
||||
assert.equal(
|
||||
queryAll(".option")[3].querySelectorAll("span")[1].innerText,
|
||||
"a"
|
||||
);
|
||||
assert.equal(percentages[4].innerText, "8%");
|
||||
assert.equal(
|
||||
queryAll(".option")[4].querySelectorAll("span")[1].innerText,
|
||||
"b"
|
||||
);
|
||||
},
|
||||
});
|
||||
assert.equal(
|
||||
queryAll(".option")[3].querySelectorAll("span")[1].innerText,
|
||||
"a"
|
||||
);
|
||||
assert.equal(percentages[4].innerText, "8%");
|
||||
assert.equal(
|
||||
queryAll(".option")[4].querySelectorAll("span")[1].innerText,
|
||||
"b"
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -1,16 +1,23 @@
|
||||
import {
|
||||
moduleForWidget,
|
||||
widgetTest,
|
||||
} from "discourse/tests/helpers/widget-test";
|
||||
discourseModule,
|
||||
exists,
|
||||
queryAll,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import EmberObject from "@ember/object";
|
||||
import I18n from "I18n";
|
||||
import { count, exists, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
|
||||
let requests = 0;
|
||||
|
||||
moduleForWidget("discourse-poll", {
|
||||
pretend(server) {
|
||||
server.put("/polls/vote", () => {
|
||||
discourseModule(
|
||||
"Integration | Component | Widget | discourse-poll",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
pretender.put("/polls/vote", () => {
|
||||
++requests;
|
||||
return [
|
||||
200,
|
||||
@ -22,8 +29,16 @@ moduleForWidget("discourse-poll", {
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 1 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
{
|
||||
id: "1f972d1df351de3ce35a787c89faad29",
|
||||
html: "yes",
|
||||
votes: 1,
|
||||
},
|
||||
{
|
||||
id: "d7ebc3a9beea2e680815a1e4f57d6db6",
|
||||
html: "no",
|
||||
votes: 0,
|
||||
},
|
||||
],
|
||||
voters: 1,
|
||||
chart_type: "bar",
|
||||
@ -33,7 +48,7 @@ moduleForWidget("discourse-poll", {
|
||||
];
|
||||
});
|
||||
|
||||
server.put("/polls/vote", () => {
|
||||
pretender.put("/polls/vote", () => {
|
||||
++requests;
|
||||
return [
|
||||
200,
|
||||
@ -45,8 +60,16 @@ moduleForWidget("discourse-poll", {
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 1 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
{
|
||||
id: "1f972d1df351de3ce35a787c89faad29",
|
||||
html: "yes",
|
||||
votes: 1,
|
||||
},
|
||||
{
|
||||
id: "d7ebc3a9beea2e680815a1e4f57d6db6",
|
||||
html: "no",
|
||||
votes: 0,
|
||||
},
|
||||
],
|
||||
voters: 1,
|
||||
chart_type: "bar",
|
||||
@ -56,10 +79,8 @@ moduleForWidget("discourse-poll", {
|
||||
},
|
||||
];
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const template = `{{mount-widget
|
||||
const template = `{{mount-widget
|
||||
widget="discourse-poll"
|
||||
args=(hash id=id
|
||||
post=post
|
||||
@ -67,91 +88,97 @@ const template = `{{mount-widget
|
||||
vote=vote
|
||||
groupableUserFields=groupableUserFields)}}`;
|
||||
|
||||
widgetTest("can vote", {
|
||||
template,
|
||||
componentTest("can vote", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
post: EmberObject.create({
|
||||
id: 42,
|
||||
topic: {
|
||||
archived: false,
|
||||
},
|
||||
}),
|
||||
poll: EmberObject.create({
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
voters: 0,
|
||||
chart_type: "bar",
|
||||
}),
|
||||
vote: [],
|
||||
groupableUserFields: [],
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
post: EmberObject.create({
|
||||
id: 42,
|
||||
topic: {
|
||||
archived: false,
|
||||
},
|
||||
}),
|
||||
poll: EmberObject.create({
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
voters: 0,
|
||||
chart_type: "bar",
|
||||
}),
|
||||
vote: [],
|
||||
groupableUserFields: [],
|
||||
});
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
requests = 0;
|
||||
|
||||
await click(
|
||||
"li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']"
|
||||
);
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(count(".chosen"), 1);
|
||||
assert.equal(queryAll(".chosen").text(), "100%yes");
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show vote");
|
||||
|
||||
await click(".toggle-results");
|
||||
assert.equal(
|
||||
queryAll("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']")
|
||||
.length,
|
||||
1
|
||||
);
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show results");
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
requests = 0;
|
||||
componentTest("cannot vote if not member of the right group", {
|
||||
template,
|
||||
|
||||
await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
|
||||
assert.equal(requests, 1);
|
||||
assert.equal(count(".chosen"), 1);
|
||||
assert.equal(queryAll(".chosen").text(), "100%yes");
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show vote");
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
post: EmberObject.create({
|
||||
id: 42,
|
||||
topic: {
|
||||
archived: false,
|
||||
},
|
||||
}),
|
||||
poll: EmberObject.create({
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
voters: 0,
|
||||
chart_type: "bar",
|
||||
groups: "foo",
|
||||
}),
|
||||
vote: [],
|
||||
groupableUserFields: [],
|
||||
});
|
||||
},
|
||||
|
||||
await click(".toggle-results");
|
||||
assert.equal(
|
||||
queryAll("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']")
|
||||
.length,
|
||||
1
|
||||
);
|
||||
assert.equal(queryAll(".toggle-results").text(), "Show results");
|
||||
},
|
||||
});
|
||||
async test(assert) {
|
||||
requests = 0;
|
||||
|
||||
widgetTest("cannot vote if not member of the right group", {
|
||||
template,
|
||||
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
post: EmberObject.create({
|
||||
id: 42,
|
||||
topic: {
|
||||
archived: false,
|
||||
},
|
||||
}),
|
||||
poll: EmberObject.create({
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{ id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
|
||||
{ id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
|
||||
],
|
||||
voters: 0,
|
||||
chart_type: "bar",
|
||||
groups: "foo",
|
||||
}),
|
||||
vote: [],
|
||||
groupableUserFields: [],
|
||||
await click(
|
||||
"li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']"
|
||||
);
|
||||
assert.equal(
|
||||
queryAll(".poll-container .alert").text(),
|
||||
I18n.t("poll.results.groups.title", { groups: "foo" })
|
||||
);
|
||||
assert.equal(requests, 0);
|
||||
assert.ok(!exists(".chosen"));
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
requests = 0;
|
||||
|
||||
await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
|
||||
assert.equal(
|
||||
queryAll(".poll-container .alert").text(),
|
||||
I18n.t("poll.results.groups.title", { groups: "foo" })
|
||||
);
|
||||
assert.equal(requests, 0);
|
||||
assert.ok(!exists(".chosen"));
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user