discourse/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js.es6
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
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)
2020-10-30 17:37:32 +01:00

41 lines
1011 B
JavaScript

import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
acceptance("Rendering polls with pie charts", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_groupable_user_fields: "something",
});
test("Displays the pie chart", async function (assert) {
await visit("/t/-/topic_with_pie_chart_poll");
const poll = queryAll(".poll")[0];
assert.equal(
queryAll(".info-number", poll)[0].innerHTML,
"2",
"it should display the right number of voters"
);
assert.equal(
queryAll(".info-number", poll)[1].innerHTML,
"5",
"it should display the right number of votes"
);
assert.equal(
poll.classList.contains("pie"),
true,
"pie class is present on poll div"
);
assert.equal(
queryAll(".poll-results-chart", poll).length,
1,
"Renders the chart div instead of bar container"
);
});
});