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>
This commit is contained in:
Jarek Radosz 2024-07-08 13:58:35 +02:00 committed by GitHub
parent 63b4c6426e
commit 619f132f57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 6 deletions

View File

@ -13,6 +13,10 @@ export default class PollResultsPieComponent extends Component {
afterUpdate(chart, args, options) {
const ul = document.getElementById(options.containerID);
if (!ul) {
return;
}
ul.innerHTML = "";
const items = chart.options.plugins.legend.labels.generateLabels(chart);

View File

@ -1,5 +1,5 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Rendering polls with pie charts", function (needs) {
@ -9,7 +9,7 @@ acceptance("Rendering polls with pie charts", function (needs) {
poll_groupable_user_fields: "something",
});
skip("Displays the pie chart", async function (assert) {
test("Displays the pie chart", async function (assert) {
await visit("/t/-/topic_with_pie_chart_poll");
assert

View File

@ -1,6 +1,6 @@
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, skip } from "qunit";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count } from "discourse/tests/helpers/qunit-helpers";
@ -15,7 +15,7 @@ const ID = "23";
module("Poll | Component | poll-results-pie", function (hooks) {
setupRenderingTest(hooks);
skip("Renders the pie chart Component correctly", async function (assert) {
test("Renders the pie chart Component correctly", async function (assert) {
this.setProperties({
id: ID,
options: OPTIONS,

View File

@ -1,6 +1,6 @@
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, skip, test } from "qunit";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, queryAll } from "discourse/tests/helpers/qunit-helpers";
@ -36,7 +36,7 @@ const PRELOADEDVOTERS = {
module("Poll | Component | poll-results-standard", function (hooks) {
setupRenderingTest(hooks);
skip("Renders the standard results Component correctly", async function (assert) {
test("Renders the standard results Component correctly", async function (assert) {
this.setProperties({
options: TWO_OPTIONS,
pollName: "Two Choice Poll",