discourse/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
2.6 KiB
Plaintext
Raw Normal View History

import { acceptance } from "helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - desktop", {
loggedIn: true,
settings: { poll_enabled: true },
2019-01-24 01:27:21 +08:00
beforeEach() {
clearPopupMenuOptionsCallback();
}
});
2019-02-28 02:16:24 +08:00
test("Polls", async assert => {
await visit("/t/-/15");
2018-07-30 04:51:32 +08:00
const polls = find(".poll");
2018-07-30 04:51:32 +08:00
assert.equal(polls.length, 2, "it should render the polls correctly");
2019-02-28 02:16:24 +08:00
2018-07-30 04:51:32 +08:00
assert.equal(
find(".info-number", polls[0]).text(),
"2",
"it should display the right number of votes"
);
2019-02-28 02:16:24 +08:00
2018-07-30 04:51:32 +08:00
assert.equal(
find(".info-number", polls[1]).text(),
"3",
"it should display the right number of votes"
);
});
2018-07-30 04:51:32 +08:00
test("Public poll", async assert => {
2019-02-28 02:16:24 +08:00
await visit("/t/-/14");
2018-07-30 04:51:32 +08:00
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
2018-07-30 04:51:32 +08:00
await click("button.toggle-results");
2018-07-30 04:51:32 +08:00
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
2019-02-28 02:16:24 +08:00
// eslint-disable-next-line
server.get("/polls/voters.json", () => {
const body = {
voters: {
"68b434ff88aeae7054e42cd05a4d9056": [
{
id: 777,
username: "bruce777",
avatar_template: "/images/avatar.png",
name: "Bruce Wayne"
}
]
}
};
return [200, { "Content-Type": "application/json" }, body];
});
2018-07-30 04:51:32 +08:00
await click(".poll-voters-toggle-expand:first a");
2018-07-30 04:51:32 +08:00
assert.equal(
find(".poll-voters:first li").length,
26,
2018-07-30 04:51:32 +08:00
"it should display the right number of voters"
);
});
2018-07-30 04:51:32 +08:00
test("Public number poll", async assert => {
2019-02-28 02:16:24 +08:00
await visit("/t/-/13");
2018-07-30 04:51:32 +08:00
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
2018-07-30 04:51:32 +08:00
await click("button.toggle-results");
2018-07-30 04:51:32 +08:00
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
2019-01-24 01:27:21 +08:00
assert.notOk(
2018-12-31 19:38:45 +08:00
find(".poll-voters:first li:first a").attr("href"),
2019-01-24 01:27:21 +08:00
"user URL does not exist"
2018-12-31 19:38:45 +08:00
);
2019-02-28 02:16:24 +08:00
// eslint-disable-next-line
server.get("/polls/voters.json", () => {
const body = {
voters: Array.from(new Array(5), (_, i) => ({
id: 600 + i,
username: `bruce${600 + i}`,
avatar_template: "/images/avatar.png",
name: "Bruce Wayne"
}))
};
return [200, { "Content-Type": "application/json" }, body];
});
2018-07-30 04:51:32 +08:00
await click(".poll-voters-toggle-expand:first a");
2018-07-30 04:51:32 +08:00
assert.equal(
find(".poll-voters:first li").length,
2019-02-28 02:16:24 +08:00
30,
2018-07-30 04:51:32 +08:00
"it should display the right number of voters"
);
});