2021-06-08 11:54:12 -04:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
count,
|
2021-06-09 10:58:55 -04:00
|
|
|
exists,
|
2021-06-08 11:54:12 -04:00
|
|
|
query,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2020-08-06 11:57:06 -04: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";
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
acceptance("Poll breakdown", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
|
|
|
poll_enabled: true,
|
|
|
|
poll_groupable_user_fields: "something",
|
|
|
|
});
|
|
|
|
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
|
|
|
needs.pretender((server, helper) => {
|
|
|
|
server.get("/polls/grouped_poll_results.json", () =>
|
|
|
|
helper.response({
|
|
|
|
grouped_results: [
|
|
|
|
{
|
|
|
|
group: "Engineering",
|
|
|
|
options: [
|
2020-08-06 11:57:06 -04:00
|
|
|
{
|
2020-10-20 13:56:52 -04:00
|
|
|
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
|
|
|
|
html: "This Is",
|
|
|
|
votes: 1,
|
2020-08-06 11:57:06 -04:00
|
|
|
},
|
|
|
|
{
|
2020-10-20 13:56:52 -04:00
|
|
|
digest: "9377906763a1221d31d656ea0c4a4495",
|
|
|
|
html: "A test for sure",
|
|
|
|
votes: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
digest: "ecf47c65a85a0bb20029072b1b721977",
|
|
|
|
html: "Why not give it some more",
|
|
|
|
votes: 1,
|
2020-09-04 14:01:14 -04:00
|
|
|
},
|
|
|
|
],
|
2020-10-20 13:56:52 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
group: "Marketing",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
|
|
|
|
html: "This Is",
|
|
|
|
votes: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
digest: "9377906763a1221d31d656ea0c4a4495",
|
|
|
|
html: "A test for sure",
|
|
|
|
votes: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
digest: "ecf47c65a85a0bb20029072b1b721977",
|
|
|
|
html: "Why not give it some more",
|
|
|
|
votes: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("Displaying the poll breakdown modal", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
await visit("/t/-/topic_with_pie_chart_poll");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
assert.ok(
|
|
|
|
exists(".poll-show-breakdown"),
|
2020-10-20 13:56:52 -04:00
|
|
|
"shows the breakdown button when poll_groupable_user_fields is non-empty"
|
|
|
|
);
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-02-03 14:22:20 -05:00
|
|
|
await click(".poll-show-breakdown");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
assert.ok(exists(".poll-breakdown-total-votes"), "displays the vote count");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-06-08 11:54:12 -04:00
|
|
|
count(".poll-breakdown-chart-container"),
|
2020-10-20 13:56:52 -04:00
|
|
|
2,
|
|
|
|
"renders a chart for each of the groups in group_results response"
|
|
|
|
);
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
assert.ok(
|
2021-06-08 11:54:12 -04:00
|
|
|
query(".poll-breakdown-chart-container > canvas").$chartjs,
|
2020-10-20 13:56:52 -04:00
|
|
|
"$chartjs is defined on the pie charts"
|
|
|
|
);
|
|
|
|
});
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("Changing the display mode from percentage to count", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
await visit("/t/-/topic_with_pie_chart_poll");
|
2021-02-03 14:22:20 -05:00
|
|
|
await click(".poll-show-breakdown");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-06-08 11:54:12 -04:00
|
|
|
query(".poll-breakdown-option-count").textContent.trim(),
|
2020-10-20 13:56:52 -04:00
|
|
|
"40.0%",
|
|
|
|
"displays the correct vote percentage"
|
|
|
|
);
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await click(".modal-tabs .count");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-06-08 11:54:12 -04:00
|
|
|
query(".poll-breakdown-option-count").textContent.trim(),
|
2020-10-20 13:56:52 -04:00
|
|
|
"2",
|
|
|
|
"displays the correct vote count"
|
|
|
|
);
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await click(".modal-tabs .percentage");
|
2020-08-06 11:57:06 -04:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-06-08 11:54:12 -04:00
|
|
|
query(".poll-breakdown-option-count").textContent.trim(),
|
|
|
|
"40.0%",
|
2020-10-20 13:56:52 -04:00
|
|
|
"displays the percentage again"
|
|
|
|
);
|
|
|
|
});
|
2020-08-06 11:57:06 -04:00
|
|
|
});
|