discourse/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js
Jarek Radosz 619f132f57
DEV: Check for poll element presence (#27765)
Fixes a flaky test. `afterUpdate` from chart.js is not integrated with the runloop and component lifecycle, as a result we have no guarantee on when it will happen. The easiest change we can do for now is ensuring we actually have the DOM we expect to have, and if not, we exit early.


Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Co-authored-by: merefield <merefield@gmail.com>
2024-07-08 13:58:35 +02:00

32 lines
967 B
JavaScript

import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } 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");
assert
.dom(".poll .poll-info_counts-count:first-child .info-number")
.hasText("2", "it should display the right number of voters");
assert
.dom(".poll .poll-info_counts-count:last-child .info-number")
.hasText("5", "it should display the right number of votes");
assert
.dom(".poll-outer")
.hasClass("pie", "pie class is present on poll div");
assert
.dom(".poll .poll-results-chart")
.exists({ count: 1 }, "Renders the chart div instead of bar container");
});
});