2020-10-28 16:36:01 -04:00
|
|
|
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
2017-12-22 07:08:12 -05:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2021-06-09 10:58:55 -04:00
|
|
|
import { test } from "qunit";
|
2021-11-13 09:31:42 -05:00
|
|
|
import { click, visit } from "@ember/test-helpers";
|
2016-11-30 21:57:12 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({ poll_enabled: true });
|
|
|
|
needs.hooks.beforeEach(() => {
|
2017-12-22 07:08:12 -05:00
|
|
|
clearPopupMenuOptionsCallback();
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
|
|
|
needs.pretender((server, helper) => {
|
2020-10-07 17:08:19 -04:00
|
|
|
server.get("/polls/voters.json", (request) => {
|
|
|
|
let body = {};
|
|
|
|
if (
|
|
|
|
request.queryParams.option_id === "68b434ff88aeae7054e42cd05a4d9056"
|
|
|
|
) {
|
|
|
|
body = {
|
|
|
|
voters: {
|
|
|
|
"68b434ff88aeae7054e42cd05a4d9056": [
|
|
|
|
{
|
|
|
|
id: 777,
|
|
|
|
username: "bruce777",
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
name: "Bruce Wayne",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
body = {
|
|
|
|
voters: Array.from(new Array(5), (_, i) => ({
|
|
|
|
id: 600 + i,
|
|
|
|
username: `bruce${600 + i}`,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
name: "Bruce Wayne",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|
2020-10-20 13:56:52 -04:00
|
|
|
return helper.response(body);
|
2020-10-07 17:08:19 -04:00
|
|
|
});
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
2016-11-30 21:57:12 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("Polls", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
await visit("/t/-/15");
|
2016-11-30 21:57:12 -05:00
|
|
|
|
2020-10-28 16:36:01 -04:00
|
|
|
const polls = queryAll(".poll");
|
2016-11-30 21:57:12 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(polls.length, 2, "it should render the polls correctly");
|
2019-02-27 13:16:24 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".info-number", polls[0]).text(),
|
2020-10-20 13:56:52 -04:00
|
|
|
"2",
|
|
|
|
"it should display the right number of votes"
|
|
|
|
);
|
2019-02-27 13:16:24 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".info-number", polls[1]).text(),
|
2020-10-20 13:56:52 -04:00
|
|
|
"3",
|
|
|
|
"it should display the right number of votes"
|
|
|
|
);
|
|
|
|
});
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("Public poll", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
await visit("/t/-/14");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-28 16:36:01 -04:00
|
|
|
const polls = queryAll(".poll");
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(polls.length, 1, "it should render the poll correctly");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await click("button.toggle-results");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-02-03 14:22:20 -05:00
|
|
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
2020-10-20 13:56:52 -04:00
|
|
|
25,
|
|
|
|
"it should display the right number of voters"
|
|
|
|
);
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2021-02-03 14:22:20 -05:00
|
|
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-02-03 14:22:20 -05:00
|
|
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
2020-10-20 13:56:52 -04:00
|
|
|
26,
|
|
|
|
"it should display the right number of voters"
|
|
|
|
);
|
|
|
|
});
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("Public number poll", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
await visit("/t/-/13");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-28 16:36:01 -04:00
|
|
|
const polls = queryAll(".poll");
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(polls.length, 1, "it should render the poll correctly");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await click("button.toggle-results");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-02-03 14:22:20 -05:00
|
|
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
2020-10-20 13:56:52 -04:00
|
|
|
25,
|
|
|
|
"it should display the right number of voters"
|
|
|
|
);
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
assert.notOk(
|
2021-02-03 14:22:20 -05:00
|
|
|
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
|
2020-10-20 13:56:52 -04:00
|
|
|
"user URL does not exist"
|
|
|
|
);
|
2018-12-31 04:48:30 -05:00
|
|
|
|
2021-02-03 14:22:20 -05:00
|
|
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
2017-01-27 04:09:33 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-02-03 14:22:20 -05:00
|
|
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
2020-10-20 13:56:52 -04:00
|
|
|
30,
|
|
|
|
"it should display the right number of voters"
|
|
|
|
);
|
|
|
|
});
|
2017-01-27 04:09:33 -05:00
|
|
|
});
|