Skip to content

A platform for community discussion. Free, open, simple.

FIX: Lots of plugin tests were using old, non-Ember compat CLI APIs (#13320)

Robin Ward77d33ebe21c2
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index 5da002ab513..97642f069fa 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -19,8 +19,14 @@ import { resolveShareUrl } from "discourse/helpers/share-url";
import { userPath } from "discourse/lib/url";
const Post = RestModel.extend({
- @discourseComputed("url")
+ customShare: null,
+
+ @discourseComputed("url", "customShare")
shareUrl(url) {
+ if (this.customShare) {
+ return this.customShare;
+ }
+
const user = User.current();
return resolveShareUrl(url, user);
},
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index 42aee810a9f..f03364e14ad 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -701,7 +701,17 @@ createWidget("post-article", {
.then((posts) => {
this.state.repliesAbove = posts.map((p) => {
let result = transformWithCallbacks(p);
- result.shareUrl = `${topicUrl}/${p.post_number}`;
+
+ // We don't want to overwrite CPs - we are doing something a bit weird
+ // here by creating a post object from a transformed post. They aren't
+ // 100% the same.
+ delete result.new_user;
+ delete result.deleted;
+ delete result.shareUrl;
+ delete result.firstPost;
+ delete result.usernameUrl;
+
+ result.customShare = `${topicUrl}/${p.post_number}`;
result.asPost = this.store.createRecord("post", result);
return result;
});
diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js
index 137b9a29afc..98d33e1de81 100644
--- a/app/assets/javascripts/discourse/ember-cli-build.js
+++ b/app/assets/javascripts/discourse/ember-cli-build.js
@@ -35,6 +35,7 @@ module.exports = function (defaults) {
app.import(vendorJs + "jquery.ui.widget.js");
app.import(vendorJs + "jquery.fileupload.js");
app.import(vendorJs + "jquery.autoellipsis-1.0.10.js");
+ app.import(vendorJs + "show-html.js");
let adminVendor = funnel(vendorJs, {
files: ["resumable.js"],
diff --git a/app/assets/javascripts/discourse/tests/helpers/widget-test.js b/app/assets/javascripts/discourse/tests/helpers/widget-test.js
index ed1514e0d4c..93f16c38a33 100644
--- a/app/assets/javascripts/discourse/tests/helpers/widget-test.js
+++ b/app/assets/javascripts/discourse/tests/helpers/widget-test.js
@@ -1,8 +1,16 @@
import { addPretenderCallback } from "discourse/tests/helpers/qunit-helpers";
import componentTest from "discourse/tests/helpers/component-test";
import { moduleForComponent } from "ember-qunit";
+import { warn } from "@ember/debug";
+import deprecated from "discourse-common/lib/deprecated";
export function moduleForWidget(name, options = {}) {
+ warn(
+ "moduleForWidget will not work in the Ember CLI environment. Please upgrade your tests.",
+ { id: "module-for-widget" }
+ );
+ return;
+
let fullName = `widget:${name}`;
addPretenderCallback(fullName, options.pretend);
@@ -17,5 +25,6 @@ export function moduleForWidget(name, options = {}) {
}
export function widgetTest(name, opts) {
+ deprecated("Use `componentTest` instead of `widgetTest`");
return componentTest(name, opts);
}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/slow-mode-info-test.js b/app/assets/javascripts/discourse/tests/integration/components/slow-mode-info-test.js
index 63204bdf2a3..fbc2e8df9cf 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/slow-mode-info-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/slow-mode-info-test.js
@@ -12,7 +12,7 @@ discourseModule("Integration | Component | slow-mode-info", function (hooks) {
setupRenderingTest(hooks);
componentTest("doesn't render if the topic is closed", {
- template: "{{slow-mode-info topic=topic}}",
+ template: hbs`{{slow-mode-info topic=topic}}`,
beforeEach() {
this.set("topic", { slow_mode_seconds: 3600, closed: true });
diff --git a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6
index 25c310dac34..5c475de7c11 100644
--- a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6
+++ b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6
@@ -6,6 +6,7 @@ import {
import I18n from "I18n";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import selectKit from "discourse/tests/helpers/select-kit-helper";
+import { test } from "qunit";
acceptance("Details Button", function (needs) {
needs.user();
diff --git a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6 b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6
index 1962054ab9a..28df6289fe6 100644
--- a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6
+++ b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6
@@ -1,4 +1,5 @@
import PrettyText, { buildOptions } from "pretty-text/pretty-text";
+import { module, test } from "qunit";
module("lib:details-cooked-test");
diff --git a/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-composer-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-composer-test.js.es6
index bd0b79426ce..1ca18d534c3 100644
--- a/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-composer-test.js.es6
+++ b/plugins/discourse-local-dates/test/javascripts/acceptance/local-dates-composer-test.js.es6
@@ -1,4 +1,5 @@
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
+import { test } from "qunit";
acceptance("Local Dates - composer", function (needs) {
needs.user();
diff --git a/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js.es6
index af43d091f1f..71848a1cfd2 100644
--- a/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js.es6
+++ b/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js.es6
@@ -1,4 +1,5 @@
import DateWithZoneHelper from "./date-with-zone-helper";
+import { module, test } from "qunit";
const PARIS = "Europe/Paris";
const SYDNEY = "Australia/Sydney";
diff --git a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
index 74fb2907d61..9764dac4719 100644
--- a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
+++ b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6
@@ -1,6 +1,7 @@
import I18n from "I18n";
import LocalDateBuilder from "./local-date-builder";
import sinon from "sinon";
+import { module, test } from "qunit";
const UTC = "Etc/UTC";
const SYDNEY = "Australia/Sydney";
diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6
index a067838bb3e..04a51d762e6 100644
--- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6
+++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6
@@ -98,7 +98,8 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed("[email protected]")
pollOptionsCount(pollOptions) {
- return pollOptions.filter((option) => option.value.length > 0).length;
+ return (pollOptions || []).filter((option) => option.value.length > 0)
+ .length;
},
@discourseComputed("site.groups")
diff --git a/plugins/poll/test/javascripts/acceptance/poll-breakdown-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-breakdown-test.js.es6
index 38aba91743c..b7320a1e642 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-breakdown-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-breakdown-test.js.es6
@@ -1,10 +1,12 @@
import {
acceptance,
count,
+ exists,
query,
- queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Poll breakdown", function (needs) {
needs.user();
@@ -65,19 +67,14 @@ acceptance("Poll breakdown", function (needs) {
test("Displaying the poll breakdown modal", async function (assert) {
await visit("/t/-/topic_with_pie_chart_poll");
- assert.equal(
- queryAll(".poll-show-breakdown").text(),
- "Show breakdown",
+ assert.ok(
+ exists(".poll-show-breakdown"),
"shows the breakdown button when poll_groupable_user_fields is non-empty"
);
await click(".poll-show-breakdown");
- assert.equal(
- query(".poll-breakdown-total-votes").textContent.trim(),
- "2 votes",
- "display the correct total vote count"
- );
+ assert.ok(exists(".poll-breakdown-total-votes"), "displays the vote count");
assert.equal(
count(".poll-breakdown-chart-container"),
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
index 8969cea1640..fa70f1fadad 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
@@ -5,6 +5,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
+import { test } from "qunit";
acceptance("Poll Builder - polls are disabled", function (needs) {
needs.user();
@@ -20,7 +21,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- !exists(".select-kit-row[title='Build Poll']"),
+ !exists(".select-kit-row[data-value='showPollBuilder']"),
"it hides the builder button"
);
});
@@ -31,7 +32,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- !exists(".select-kit-row[title='Build Poll']"),
+ !exists(".select-kit-row[data-value='showPollBuilder']"),
"it hides the builder button"
);
});
@@ -42,7 +43,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- !exists(".select-kit-row[title='Build Poll']"),
+ !exists(".select-kit-row[data-value='showPollBuilder']"),
"it hides the builder button"
);
});
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
index f04178b9534..3321e07c6d9 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
@@ -5,6 +5,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
+import { test } from "qunit";
acceptance("Poll Builder - polls are enabled", function (needs) {
needs.user();
@@ -20,7 +21,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- exists(".select-kit-row[title='Build Poll']"),
+ exists(".select-kit-row[data-value='showPollBuilder']"),
"it shows the builder button"
);
});
@@ -31,7 +32,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- !exists(".select-kit-row[title='Build Poll']"),
+ !exists(".select-kit-row[data-value='showPollBuilder]"),
"it hides the builder button"
);
});
@@ -42,7 +43,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
await displayPollBuilderButton();
assert.ok(
- exists(".select-kit-row[title='Build Poll']"),
+ exists(".select-kit-row[data-value='showPollBuilder']"),
"it shows the builder button"
);
});
diff --git a/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6
index 1959caab884..12c507d1d54 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-in-reply-history-test.js.es6
@@ -1,5 +1,7 @@
-import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Poll in a post reply history", function (needs) {
needs.user();
diff --git a/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js.es6
index 994df7fdb42..4d720b2009f 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-pie-chart-test.js.es6
@@ -3,6 +3,8 @@ import {
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Rendering polls with pie charts", function (needs) {
needs.user();
diff --git a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
index d88ee700e6d..3b5bb2ddac6 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-quote-test.js.es6
@@ -1,5 +1,7 @@
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Poll quote", function (needs) {
needs.user();
diff --git a/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6 b/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6
index e22df294bd0..12147b270e9 100644
--- a/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-desktop.js.es6
@@ -1,5 +1,7 @@
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Rendering polls with bar charts - desktop", function (needs) {
needs.user();
diff --git a/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-mobile.js.es6 b/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-mobile.js.es6
index 19200119509..654241d26c8 100644
--- a/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-mobile.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/polls-bar-chart-test-mobile.js.es6
@@ -1,5 +1,7 @@
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
+import { test } from "qunit";
+import { visit } from "@ember/test-helpers";
acceptance("Rendering polls with bar charts - mobile", function (needs) {
needs.user();
diff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
index 8dc002a9f1b..6f4a420f5c3 100644
--- a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
+++ b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6
@@ -1,214 +1,220 @@
-import { controllerModule } from "discourse/tests/helpers/qunit-helpers";
+import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import {
MULTIPLE_POLL_TYPE,
NUMBER_POLL_TYPE,
REGULAR_POLL_TYPE,
} from "discourse/plugins/poll/controllers/poll-ui-builder";
+import { test } from "qunit";
+import { settled } from "@ember/test-helpers";
-controllerModule("controller:poll-ui-builder", {
- setupController(controller) {
- controller.set("toolbarEvent", { getText: () => "" });
- controller.onShow();
- },
- needs: ["controller:modal"],
-});
+function setupController(ctx) {
+ let controller = ctx.getController("poll-ui-builder");
+ controller.set("toolbarEvent", { getText: () => "" });
+ controller.onShow();
+ return controller;
+}
-test("isMultiple", function (assert) {
- const controller = this.subject();
+discourseModule("Unit | Controller | poll-ui-builder", function () {
+ test("isMultiple", function (assert) {
+ const controller = setupController(this);
- controller.setProperties({
- pollType: MULTIPLE_POLL_TYPE,
- pollOptions: [{ value: "a" }],
- });
+ controller.setProperties({
+ pollType: MULTIPLE_POLL_TYPE,
+ pollOptions: [{ value: "a" }],
+ });
- assert.equal(controller.isMultiple, true, "it should be true");
+ assert.equal(controller.isMultiple, true, "it should be true");
- controller.setProperties({
- pollType: "random",
- pollOptions: [{ value: "b" }],
+ controller.setProperties({
+ pollType: "random",
+ pollOptions: [{ value: "b" }],
+ });
+
+ assert.equal(controller.isMultiple, false, "it should be false");
});
- assert.equal(controller.isMultiple, false, "it should be false");
-});
+ test("isNumber", function (assert) {
+ const controller = setupController(this);
-test("isNumber", function (assert) {
- const controller = this.subject();
+ controller.set("pollType", REGULAR_POLL_TYPE);
- controller.set("pollType", REGULAR_POLL_TYPE);
+ assert.equal(controller.isNumber, false, "it should be false");
- assert.equal(controller.isNumber, false, "it should be false");
+ controller.set("pollType", NUMBER_POLL_TYPE);
- controller.set("pollType", NUMBER_POLL_TYPE);
+ assert.equal(controller.isNumber, true, "it should be true");
+ });
- assert.equal(controller.isNumber, true, "it should be true");
-});
+ test("pollOptionsCount", function (assert) {
+ const controller = setupController(this);
-test("pollOptionsCount", function (assert) {
- const controller = this.subject();
+ controller.set("pollOptions", [{ value: "1" }, { value: "2" }]);
- controller.set("pollOptions", [{ value: "1" }, { value: "2" }]);
+ assert.equal(controller.pollOptionsCount, 2, "it should equal 2");
- assert.equal(controller.pollOptionsCount, 2, "it should equal 2");
+ controller.set("pollOptions", []);
- controller.set("pollOptions", []);
+ assert.equal(controller.pollOptionsCount, 0, "it should equal 0");
+ });
- assert.equal(controller.pollOptionsCount, 0, "it should equal 0");
-});
+ test("disableInsert", function (assert) {
+ const controller = setupController(this);
+ controller.siteSettings.poll_maximum_options = 20;
-test("disableInsert", function (assert) {
- const controller = this.subject();
- controller.siteSettings.poll_maximum_options = 20;
+ assert.equal(controller.disableInsert, true, "it should be true");
- assert.equal(controller.disableInsert, true, "it should be true");
+ controller.set("pollOptions", [{ value: "a" }, { value: "b" }]);
- controller.set("pollOptions", [{ value: "a" }, { value: "b" }]);
+ assert.equal(controller.disableInsert, false, "it should be false");
- assert.equal(controller.disableInsert, false, "it should be false");
+ controller.set("pollType", NUMBER_POLL_TYPE);
- controller.set("pollType", NUMBER_POLL_TYPE);
+ assert.equal(controller.disableInsert, false, "it should be false");
- assert.equal(controller.disableInsert, false, "it should be false");
+ controller.setProperties({
+ pollType: REGULAR_POLL_TYPE,
+ pollOptions: [{ value: "a" }, { value: "b" }, { value: "c" }],
+ });
- controller.setProperties({
- pollType: REGULAR_POLL_TYPE,
- pollOptions: [{ value: "a" }, { value: "b" }, { value: "c" }],
- });
+ assert.equal(controller.disableInsert, false, "it should be false");
- assert.equal(controller.disableInsert, false, "it should be false");
+ controller.setProperties({
+ pollType: REGULAR_POLL_TYPE,
+ pollOptions: [],
+ });
- controller.setProperties({
- pollType: REGULAR_POLL_TYPE,
- pollOptions: [],
- });
+ assert.equal(controller.disableInsert, true, "it should be true");
- assert.equal(controller.disableInsert, true, "it should be true");
+ controller.setProperties({
+ pollType: REGULAR_POLL_TYPE,
+ pollOptions: [{ value: "w" }],
+ });
- controller.setProperties({
- pollType: REGULAR_POLL_TYPE,
- pollOptions: [{ value: "w" }],
+ assert.equal(controller.disableInsert, false, "it should be false");
});
- assert.equal(controller.disableInsert, false, "it should be false");
-});
-
-test("number pollOutput", function (assert) {
- const controller = this.subject();
- controller.siteSettings.poll_maximum_options = 20;
-
- controller.setProperties({
- pollType: NUMBER_POLL_TYPE,
- pollMin: 1,
+ test("number pollOutput", async function (assert) {
+ this.siteSettings.poll_maximum_options = 20;
+ const controller = setupController(this);
+
+ controller.setProperties({
+ pollType: NUMBER_POLL_TYPE,
+ pollMin: 1,
+ });
+ await settled();
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=number results=always min=1 max=20 step=1]\n[/poll]\n",
+ "it should return the right output"
+ );
+ controller.set("pollStep", 2);
+ await settled();
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=number results=always min=1 max=20 step=2]\n[/poll]\n",
+ "it should return the right output"
+ );
+
+ controller.set("publicPoll", true);
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=number results=always min=1 max=20 step=2 public=true]\n[/poll]\n",
+ "it should return the right output"
+ );
+
+ controller.set("pollStep", 0);
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=number results=always min=1 max=20 step=1 public=true]\n[/poll]\n",
+ "it should return the right output"
+ );
});
- assert.equal(
- controller.pollOutput,
- "[poll type=number results=always min=1 max=20 step=1]\n[/poll]\n",
- "it should return the right output"
- );
-
- controller.set("pollStep", 2);
+ test("regular pollOutput", function (assert) {
+ const controller = setupController(this);
+ controller.siteSettings.poll_maximum_options = 20;
- assert.equal(
- controller.pollOutput,
- "[poll type=number results=always min=1 max=20 step=2]\n[/poll]\n",
- "it should return the right output"
- );
+ controller.setProperties({
+ pollOptions: [{ value: "1" }, { value: "2" }],
+ pollType: REGULAR_POLL_TYPE,
+ });
- controller.set("publicPoll", true);
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=regular results=always chartType=bar]\n* 1\n* 2\n[/poll]\n",
+ "it should return the right output"
+ );
- assert.equal(
- controller.pollOutput,
- "[poll type=number results=always min=1 max=20 step=2 public=true]\n[/poll]\n",
- "it should return the right output"
- );
+ controller.set("publicPoll", "true");
- controller.set("pollStep", 0);
-
- assert.equal(
- controller.pollOutput,
- "[poll type=number results=always min=1 max=20 step=1 public=true]\n[/poll]\n",
- "it should return the right output"
- );
-});
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=regular results=always public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
+ "it should return the right output"
+ );
-test("regular pollOutput", function (assert) {
- const controller = this.subject();
- controller.siteSettings.poll_maximum_options = 20;
+ controller.set("pollGroups", "test");
- controller.setProperties({
- pollOptions: [{ value: "1" }, { value: "2" }],
- pollType: REGULAR_POLL_TYPE,
+ assert.equal(
+ controller.get("pollOutput"),
+ "[poll type=regular results=always public=true chartType=bar groups=test]\n* 1\n* 2\n[/poll]\n",
+ "it should return the right output"
+ );
});
- assert.equal(
- controller.pollOutput,
- "[poll type=regular results=always chartType=bar]\n* 1\n* 2\n[/poll]\n",
- "it should return the right output"
- );
-
- controller.set("publicPoll", "true");
-
- assert.equal(
- controller.pollOutput,
- "[poll type=regular results=always public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
- "it should return the right output"
- );
-
- controller.set("pollGroups", "test");
-
- assert.equal(
- controller.get("pollOutput"),
- "[poll type=regular results=always public=true chartType=bar groups=test]\n* 1\n* 2\n[/poll]\n",
- "it should return the right output"
- );
-});
-
-test("multiple pollOutput", function (assert) {
- const controller = this.subject();
- controller.siteSettings.poll_maximum_options = 20;
-
- controller.setProperties({
- pollType: MULTIPLE_POLL_TYPE,
- pollMin: 1,
- pollOptions: [{ value: "1" }, { value: "2" }],
+ test("multiple pollOutput", function (assert) {
+ const controller = setupController(this);
+ controller.siteSettings.poll_maximum_options = 20;
+
+ controller.setProperties({
+ pollType: MULTIPLE_POLL_TYPE,
+ pollMin: 1,
+ pollOptions: [{ value: "1" }, { value: "2" }],
+ });
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=multiple results=always min=1 max=2 chartType=bar]\n* 1\n* 2\n[/poll]\n",
+ "it should return the right output"
+ );
+
+ controller.set("publicPoll", "true");
+
+ assert.equal(
+ controller.pollOutput,
+ "[poll type=multiple results=always min=1 max=2 public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
+ "it should return the right output"
+ );
});
- assert.equal(
- controller.pollOutput,
- "[poll type=multiple results=always min=1 max=2 chartType=bar]\n* 1\n* 2\n[/poll]\n",
- "it should return the right output"
- );
-
- controller.set("publicPoll", "true");
+ test("staff_only option is not present for non-staff", async function (assert) {
+ const controller = setupController(this);
+ controller.currentUser = { staff: false };
+ controller.notifyPropertyChange("pollResults");
- assert.equal(
- controller.pollOutput,
- "[poll type=multiple results=always min=1 max=2 public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
- "it should return the right output"
- );
-});
-
-test("staff_only option is not present for non-staff", function (assert) {
- const controller = this.subject();
- controller.currentUser = { staff: false };
-
- assert.ok(
- controller.pollResults.filterBy("value", "staff_only").length === 0,
- "staff_only is not present"
- );
-});
+ assert.ok(
+ controller.pollResults.filterBy("value", "staff_only").length === 0,
+ "staff_only is not present"
+ );
+ });
-test("poll result is always by default", function (assert) {
- const controller = this.subject();
- assert.equal(controller.pollResult, "always");
-});
+ test("poll result is always by default", function (assert) {
+ const controller = setupController(this);
+ assert.equal(controller.pollResult, "always");
+ });
-test("staff_only option is present for staff", function (assert) {
- const controller = this.subject();
- controller.currentUser = { staff: true };
+ test("staff_only option is present for staff", async function (assert) {
+ const controller = setupController(this);
+ controller.currentUser = { staff: true };
+ controller.notifyPropertyChange("pollResults");
- assert.ok(
- controller.pollResults.filterBy("value", "staff_only").length === 1,
- "staff_only is present"
- );
+ assert.ok(
+ controller.pollResults.filterBy("value", "staff_only").length === 1,
+ "staff_only is present"
+ );
+ });
});
diff --git a/plugins/poll/test/javascripts/helpers/display-poll-builder-button.js.es6 b/plugins/poll/test/javascripts/helpers/display-poll-builder-button.js.es6
index 8d9318cba7e..e4d3ce0febf 100644
--- a/plugins/poll/test/javascripts/helpers/display-poll-builder-button.js.es6
+++ b/plugins/poll/test/javascripts/helpers/display-poll-builder-button.js.es6
@@ -1,4 +1,5 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
+import { click, visit } from "@ember/test-helpers";
export async function displayPollBuilderButton() {
await visit("/");
diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6
index fb57cc75a8c..ee2ca3593b4 100644
--- a/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6
+++ b/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6
@@ -1,71 +1,81 @@
+import componentTest, {
+ setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
import {
- moduleForWidget,
- widgetTest,
-} from "discourse/tests/helpers/widget-test";
-import { queryAll } from "discourse/tests/helpers/qunit-helpers";
+ discourseModule,
+ queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
-moduleForWidget("discourse-poll-option");
-
-const template = `{{mount-widget
+discourseModule(
+ "Integration | Component | Widget | discourse-poll-option",
+ function (hooks) {
+ setupRenderingTest(hooks);
+ const template = `{{mount-widget
widget="discourse-poll-option"
args=(hash option=option isMultiple=isMultiple vote=vote)}}`;
-widgetTest("single, not selected", {
- template,
+ componentTest("single, not selected", {
+ template,
- beforeEach() {
- this.set("option", { id: "opt-id" });
- this.set("vote", []);
- },
+ beforeEach() {
+ this.set("option", { id: "opt-id" });
+ this.set("vote", []);
+ },
- test(assert) {
- assert.ok(queryAll("li .d-icon-far-circle:nth-of-type(1)").length === 1);
- },
-});
+ test(assert) {
+ assert.ok(
+ queryAll("li .d-icon-far-circle:nth-of-type(1)").length === 1
+ );
+ },
+ });
-widgetTest("single, selected", {
- template,
+ componentTest("single, selected", {
+ template,
- beforeEach() {
- this.set("option", { id: "opt-id" });
- this.set("vote", ["opt-id"]);
- },
+ beforeEach() {
+ this.set("option", { id: "opt-id" });
+ this.set("vote", ["opt-id"]);
+ },
- test(assert) {
- assert.ok(queryAll("li .d-icon-circle:nth-of-type(1)").length === 1);
- },
-});
+ test(assert) {
+ assert.ok(queryAll("li .d-icon-circle:nth-of-type(1)").length === 1);
+ },
+ });
-widgetTest("multi, not selected", {
- template,
+ componentTest("multi, not selected", {
+ template,
- beforeEach() {
- this.setProperties({
- option: { id: "opt-id" },
- isMultiple: true,
- vote: [],
+ beforeEach() {
+ this.setProperties({
+ option: { id: "opt-id" },
+ isMultiple: true,
+ vote: [],
+ });
+ },
+
+ test(assert) {
+ assert.ok(
+ queryAll("li .d-icon-far-square:nth-of-type(1)").length === 1
+ );
+ },
});
- },
- test(assert) {
- assert.ok(queryAll("li .d-icon-far-square:nth-of-type(1)").length === 1);
- },
-});
+ componentTest("multi, selected", {
+ template,
-widgetTest("multi, selected", {
- template,
+ beforeEach() {
+ this.setProperties({
+ option: { id: "opt-id" },
+ isMultiple: true,
+ vote: ["opt-id"],
+ });
+ },
- beforeEach() {
- this.setProperties({
- option: { id: "opt-id" },
- isMultiple: true,
- vote: ["opt-id"],
+ test(assert) {
+ assert.ok(
+ queryAll("li .d-icon-far-check-square:nth-of-type(1)").length === 1
+ );
+ },
});
- },
-
- test(assert) {
- assert.ok(
- queryAll("li .d-icon-far-check-square:nth-of-type(1)").length === 1
- );
- },
-});
+ }
+);
diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6
index 3edd1c3e59f..9a72956aaa4 100644
--- a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6
+++ b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6
@@ -1,90 +1,97 @@
-import {
- moduleForWidget,
- widgetTest,
-} from "discourse/tests/helpers/widget-test";
+import componentTest, {
+ setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
import EmberObject from "@ember/object";
-import { queryAll } from "discourse/tests/helpers/qunit-helpers";
+import {
+ discourseModule,
+ queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
-moduleForWidget("discourse-poll-standard-results");
+discourseModule(
+ "Integration | Component | Widget | discourse-poll-standard-results",
+ function (hooks) {
+ setupRenderingTest(hooks);
-const template = `{{mount-widget
+ const template = `{{mount-widget
widget="discourse-poll-standard-results"
args=(hash poll=poll isMultiple=isMultiple)}}`;
-widgetTest("options in descending order", {
- template,
+ componentTest("options in descending order", {
+ template,
- beforeEach() {
- this.set(
- "poll",
- EmberObject.create({
- options: [{ votes: 5 }, { votes: 4 }],
- voters: 9,
- })
- );
- },
+ beforeEach() {
+ this.set(
+ "poll",
+ EmberObject.create({
+ options: [{ votes: 5 }, { votes: 4 }],
+ voters: 9,
+ })
+ );
+ },
- test(assert) {
- assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
- assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
- },
-});
+ test(assert) {
+ assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
+ assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
+ },
+ });
-widgetTest("options in ascending order", {
- template,
+ componentTest("options in ascending order", {
+ template,
- beforeEach() {
- this.set(
- "poll",
- EmberObject.create({
- options: [{ votes: 4 }, { votes: 5 }],
- voters: 9,
- })
- );
- },
+ beforeEach() {
+ this.set(
+ "poll",
+ EmberObject.create({
+ options: [{ votes: 4 }, { votes: 5 }],
+ voters: 9,
+ })
+ );
+ },
- test(assert) {
- assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
- assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
- },
-});
+ test(assert) {
+ assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
+ assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
+ },
+ });
-widgetTest("multiple options in descending order", {
- template,
+ componentTest("multiple options in descending order", {
+ template,
- beforeEach() {
- this.set("isMultiple", true);
- this.set(
- "poll",
- EmberObject.create({
- type: "multiple",
- options: [
- { votes: 5, html: "a" },
- { votes: 2, html: "b" },
- { votes: 4, html: "c" },
- { votes: 1, html: "b" },
- { votes: 1, html: "a" },
- ],
- voters: 12,
- })
- );
- },
+ beforeEach() {
+ this.set("isMultiple", true);
+ this.set(
+ "poll",
+ EmberObject.create({
+ type: "multiple",
+ options: [
+ { votes: 5, html: "a" },
+ { votes: 2, html: "b" },
+ { votes: 4, html: "c" },
+ { votes: 1, html: "b" },
+ { votes: 1, html: "a" },
+ ],
+ voters: 12,
+ })
+ );
+ },
- test(assert) {
- let percentages = queryAll(".option .percentage");
- assert.equal(percentages[0].innerText, "41%");
- assert.equal(percentages[1].innerText, "33%");
- assert.equal(percentages[2].innerText, "16%");
- assert.equal(percentages[3].innerText, "8%");
+ test(assert) {
+ let percentages = queryAll(".option .percentage");
+ assert.equal(percentages[0].innerText, "41%");
+ assert.equal(percentages[1].innerText, "33%");
+ assert.equal(percentages[2].innerText, "16%");
+ assert.equal(percentages[3].innerText, "8%");
- assert.equal(
- queryAll(".option")[3].querySelectorAll("span")[1].innerText,
- "a"
- );
- assert.equal(percentages[4].innerText, "8%");
- assert.equal(
- queryAll(".option")[4].querySelectorAll("span")[1].innerText,
- "b"
- );
- },
-});
+ assert.equal(
+ queryAll(".option")[3].querySelectorAll("span")[1].innerText,
+ "a"
+ );
+ assert.equal(percentages[4].innerText, "8%");
+ assert.equal(
+ queryAll(".option")[4].querySelectorAll("span")[1].innerText,
+ "b"
+ );
+ },
+ });
+ }
+);
diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6
index fc1efc0e674..58622b6d0dd 100644
--- a/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6
+++ b/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6
@@ -1,16 +1,23 @@
import {
- moduleForWidget,
- widgetTest,
-} from "discourse/tests/helpers/widget-test";
+ discourseModule,
+ exists,
+ queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
+import componentTest, {
+ setupRenderingTest,
+} from "discourse/tests/helpers/component-test";
import EmberObject from "@ember/object";
import I18n from "I18n";
-import { count, exists, queryAll } from "discourse/tests/helpers/qunit-helpers";
+import pretender from "discourse/tests/helpers/create-pretender";
let requests = 0;
-moduleForWidget("discourse-poll", {
- pretend(server) {
- server.put("/polls/vote", () => {
+discourseModule(
+ "Integration | Component | Widget | discourse-poll",
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ pretender.put("/polls/vote", () => {
++requests;
return [
200,
@@ -22,8 +29,16 @@ moduleForWidget("discourse-poll", {
status: "open",
results: "always",
options: [
- { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 1 },
- { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
+ {
+ id: "1f972d1df351de3ce35a787c89faad29",
+ html: "yes",
+ votes: 1,
+ },
+ {
+ id: "d7ebc3a9beea2e680815a1e4f57d6db6",
+ html: "no",
+ votes: 0,
+ },
],
voters: 1,
chart_type: "bar",
@@ -33,7 +48,7 @@ moduleForWidget("discourse-poll", {
];
});
- server.put("/polls/vote", () => {
+ pretender.put("/polls/vote", () => {
++requests;
return [
200,
@@ -45,8 +60,16 @@ moduleForWidget("discourse-poll", {
status: "open",
results: "always",
options: [
- { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 1 },
- { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
+ {
+ id: "1f972d1df351de3ce35a787c89faad29",
+ html: "yes",
+ votes: 1,
+ },
+ {
+ id: "d7ebc3a9beea2e680815a1e4f57d6db6",
+ html: "no",
+ votes: 0,
+ },
],
voters: 1,
chart_type: "bar",
@@ -56,10 +79,8 @@ moduleForWidget("discourse-poll", {
},
];
});
- },
-});
-const template = `{{mount-widget
+ const template = `{{mount-widget
widget="discourse-poll"
args=(hash id=id
post=post
@@ -67,91 +88,97 @@ const template = `{{mount-widget
vote=vote
groupableUserFields=groupableUserFields)}}`;
-widgetTest("can vote", {
- template,
+ componentTest("can vote", {
+ template,
- beforeEach() {
- this.setProperties({
- post: EmberObject.create({
- id: 42,
- topic: {
- archived: false,
- },
- }),
- poll: EmberObject.create({
- name: "poll",
- type: "regular",
- status: "open",
- results: "always",
- options: [
- { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
- { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
- ],
- voters: 0,
- chart_type: "bar",
- }),
- vote: [],
- groupableUserFields: [],
- });
- },
+ beforeEach() {
+ this.setProperties({
+ post: EmberObject.create({
+ id: 42,
+ topic: {
+ archived: false,
+ },
+ }),
+ poll: EmberObject.create({
+ name: "poll",
+ type: "regular",
+ status: "open",
+ results: "always",
+ options: [
+ { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
+ { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
+ ],
+ voters: 0,
+ chart_type: "bar",
+ }),
+ vote: [],
+ groupableUserFields: [],
+ });
+ },
- async test(assert) {
- requests = 0;
+ async test(assert) {
+ requests = 0;
- await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
- assert.equal(requests, 1);
- assert.equal(count(".chosen"), 1);
- assert.equal(queryAll(".chosen").text(), "100%yes");
- assert.equal(queryAll(".toggle-results").text(), "Show vote");
+ await click(
+ "li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']"
+ );
+ assert.equal(requests, 1);
+ assert.equal(count(".chosen"), 1);
+ assert.equal(queryAll(".chosen").text(), "100%yes");
+ assert.equal(queryAll(".toggle-results").text(), "Show vote");
- await click(".toggle-results");
- assert.equal(
- queryAll("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']")
- .length,
- 1
- );
- assert.equal(queryAll(".toggle-results").text(), "Show results");
- },
-});
+ await click(".toggle-results");
+ assert.equal(
+ queryAll("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']")
+ .length,
+ 1
+ );
+ assert.equal(queryAll(".toggle-results").text(), "Show results");
+ },
+ });
-widgetTest("cannot vote if not member of the right group", {
- template,
+ componentTest("cannot vote if not member of the right group", {
+ template,
- beforeEach() {
- this.setProperties({
- post: EmberObject.create({
- id: 42,
- topic: {
- archived: false,
- },
- }),
- poll: EmberObject.create({
- name: "poll",
- type: "regular",
- status: "open",
- results: "always",
- options: [
- { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
- { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
- ],
- voters: 0,
- chart_type: "bar",
- groups: "foo",
- }),
- vote: [],
- groupableUserFields: [],
- });
- },
+ beforeEach() {
+ this.setProperties({
+ post: EmberObject.create({
+ id: 42,
+ topic: {
+ archived: false,
+ },
+ }),
+ poll: EmberObject.create({
+ name: "poll",
+ type: "regular",
+ status: "open",
+ results: "always",
+ options: [
+ { id: "1f972d1df351de3ce35a787c89faad29", html: "yes", votes: 0 },
+ { id: "d7ebc3a9beea2e680815a1e4f57d6db6", html: "no", votes: 0 },
+ ],
+ voters: 0,
+ chart_type: "bar",
+ groups: "foo",
+ }),
+ vote: [],
+ groupableUserFields: [],
+ });
+ },
- async test(assert) {
- requests = 0;
+ async test(assert) {
+ requests = 0;
- await click("li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']");
- assert.equal(
- queryAll(".poll-container .alert").text(),
- I18n.t("poll.results.groups.title", { groups: "foo" })
- );
- assert.equal(requests, 0);
- assert.ok(!exists(".chosen"));
- },
-});
+ await click(
+ "li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29']"
+ );
+ assert.equal(
+ queryAll(".poll-container .alert").text(),
+ I18n.t("poll.results.groups.title", { groups: "foo" })
+ );
+ assert.equal(requests, 0);
+ assert.ok(!exists(".chosen"));
+ },
+ });
+ }
+);