mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 20:23:39 +08:00
a17d54d0bf
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
|
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
acceptance("Rendering polls with bar charts - mobile", function (needs) {
|
|
needs.user();
|
|
needs.mobileView();
|
|
needs.settings({ poll_enabled: true });
|
|
needs.pretender((server, helper) => {
|
|
server.get("/polls/voters.json", () => {
|
|
return helper.response({
|
|
voters: Array.from(new Array(10), (_, i) => ({
|
|
id: 500 + i,
|
|
username: `bruce${500 + i}`,
|
|
avatar_template: "/images/avatar.png",
|
|
name: "Bruce Wayne",
|
|
})),
|
|
});
|
|
});
|
|
});
|
|
needs.hooks.beforeEach(() => {
|
|
clearPopupMenuOptionsCallback();
|
|
});
|
|
|
|
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:first li").length,
|
|
25,
|
|
"it should display the right number of voters"
|
|
);
|
|
|
|
assert.notOk(
|
|
queryAll(".poll-voters:first li:first a").attr("href"),
|
|
"user URL does not exist"
|
|
);
|
|
|
|
await click(".poll-voters-toggle-expand:first a");
|
|
|
|
assert.equal(
|
|
queryAll(".poll-voters:first li").length,
|
|
35,
|
|
"it should display the right number of voters"
|
|
);
|
|
});
|
|
});
|