discourse/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6
Robin Ward 61f5d501cb
DEV: Migrate to Ember CLI (#11932)
This encompasses a lot of work done over the last year, much of which
has already been merged into master. This is the final set of changes
required to get Ember CLI running locally for development.

From here on it will be bug fixes / enhancements.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com>

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com>
2021-02-03 14:22:20 -05:00

113 lines
3.0 KiB
JavaScript

import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - desktop", function (needs) {
needs.user();
needs.settings({ poll_enabled: true });
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
});
needs.pretender((server, helper) => {
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",
})),
};
}
return helper.response(body);
});
});
test("Polls", async function (assert) {
await visit("/t/-/15");
const polls = queryAll(".poll");
assert.equal(polls.length, 2, "it should render the polls correctly");
assert.equal(
queryAll(".info-number", polls[0]).text(),
"2",
"it should display the right number of votes"
);
assert.equal(
queryAll(".info-number", polls[1]).text(),
"3",
"it should display the right number of votes"
);
});
test("Public poll", async function (assert) {
await visit("/t/-/14");
const polls = queryAll(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
queryAll(".poll-voters:nth-of-type(1) li").length,
25,
"it should display the right number of voters"
);
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
assert.equal(
queryAll(".poll-voters:nth-of-type(1) li").length,
26,
"it should display the right number of voters"
);
});
test("Public number poll", async function (assert) {
await visit("/t/-/13");
const polls = queryAll(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
assert.equal(
queryAll(".poll-voters:nth-of-type(1) li").length,
25,
"it should display the right number of voters"
);
assert.notOk(
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
"user URL does not exist"
);
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
assert.equal(
queryAll(".poll-voters:nth-of-type(1) li").length,
30,
"it should display the right number of voters"
);
});
});