From a2b744ae2530aab0e07b96a3e247ef5cbedc674c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 21 Jun 2021 15:52:15 -0400 Subject: [PATCH] DEV: Allow plugin tests to run in Ember CLI qunit --- app/assets/javascripts/discourse/ember-cli-build.js | 3 +++ .../discourse/public/assets/scripts/discourse-boot.js | 6 ++++++ app/assets/javascripts/discourse/tests/index.html | 4 ++++ .../tests/integration/components/bookmark-test.js | 11 ++++++----- .../javascripts/acceptance/poll-results-test.js.es6 | 2 ++ .../widgets/discourse-poll-option-test.js.es6 | 3 ++- .../discourse-poll-standard-results-test.js.es6 | 3 ++- .../javascripts/widgets/discourse-poll-test.js.es6 | 5 ++--- 8 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.js index 4650fb52925..29e9a396f65 100644 --- a/app/assets/javascripts/discourse/ember-cli-build.js +++ b/app/assets/javascripts/discourse/ember-cli-build.js @@ -37,6 +37,9 @@ module.exports = function (defaults) { app.import(vendorJs + "jquery.fileupload-process.js"); app.import(vendorJs + "jquery.autoellipsis-1.0.10.js"); app.import(vendorJs + "show-html.js"); + app.import("node_modules/ember-source/dist/ember-template-compiler.js", { + type: "test", + }); let adminVendor = funnel(vendorJs, { files: ["resumable.js"], diff --git a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js index a4811cab76a..f33a20a7bdf 100644 --- a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js +++ b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js @@ -166,6 +166,12 @@ define("I18n", ["exports"], function (exports) { return I18n; }); + + define("htmlbars-inline-precompile", ["exports"], function (exports) { + exports.default = function tag(strings) { + return Ember.Handlebars.compile(strings[0]); + }; + }); window.__widget_helpers = require("discourse-widget-hbs/helpers").default; // TODO: Eliminate this global diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.html index 4660e3ef84a..34c33c48e40 100644 --- a/app/assets/javascripts/discourse/tests/index.html +++ b/app/assets/javascripts/discourse/tests/index.html @@ -26,6 +26,9 @@ -o-transition: none !important; transition: none !important; } + #ember-testing { + background-color: white; + } #qunit-fixture { position: absolute; top: -10000px; @@ -47,6 +50,7 @@ + diff --git a/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js b/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js index 4a637123c6b..877b1635fb2 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/bookmark-test.js @@ -8,25 +8,26 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; import I18n from "I18n"; +import hbs from "htmlbars-inline-precompile"; discourseModule("Integration | Component | bookmark", function (hooks) { setupRenderingTest(hooks); - const template = `{{bookmark + const template = hbs`{{bookmark model=model afterSave=afterSave afterDelete=afterDelete onCloseWithoutSaving=onCloseWithoutSaving - registerOnCloseHandler=(action "registerOnCloseHandler") - closeModal=(action "closeModal")}}`; + registerOnCloseHandler=registerOnCloseHandler + closeModal=closeModal}}`; hooks.beforeEach(function () { - this.actions.registerOnCloseHandler = () => {}; - this.actions.closeModal = () => {}; this.setProperties({ model: {}, + closeModal: () => {}, afterSave: () => {}, afterDelete: () => {}, + registerOnCloseHandler: () => {}, onCloseWithoutSaving: () => {}, }); }); diff --git a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 index 06956b676aa..30a7889d430 100644 --- a/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/poll-results-test.js.es6 @@ -2,7 +2,9 @@ import { acceptance, publishToMessageBus, } from "discourse/tests/helpers/qunit-helpers"; +import { test } from "qunit"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; +import { visit } from "@ember/test-helpers"; acceptance("Poll results", function (needs) { needs.user(); 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 ee2ca3593b4..bb900876468 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 @@ -5,12 +5,13 @@ import { discourseModule, queryAll, } from "discourse/tests/helpers/qunit-helpers"; +import hbs from "htmlbars-inline-precompile"; discourseModule( "Integration | Component | Widget | discourse-poll-option", function (hooks) { setupRenderingTest(hooks); - const template = `{{mount-widget + const template = hbs`{{mount-widget widget="discourse-poll-option" args=(hash option=option isMultiple=isMultiple vote=vote)}}`; 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 9a72956aaa4..b7d219b88c7 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 @@ -6,13 +6,14 @@ import { discourseModule, queryAll, } from "discourse/tests/helpers/qunit-helpers"; +import hbs from "htmlbars-inline-precompile"; discourseModule( "Integration | Component | Widget | discourse-poll-standard-results", function (hooks) { setupRenderingTest(hooks); - const template = `{{mount-widget + const template = hbs`{{mount-widget widget="discourse-poll-standard-results" args=(hash poll=poll isMultiple=isMultiple)}}`; 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 e85a560a92c..5666f832b24 100644 --- a/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6 +++ b/plugins/poll/test/javascripts/widgets/discourse-poll-test.js.es6 @@ -10,6 +10,7 @@ import componentTest, { import EmberObject from "@ember/object"; import I18n from "I18n"; import pretender from "discourse/tests/helpers/create-pretender"; +import hbs from "htmlbars-inline-precompile"; let requests = 0; @@ -81,7 +82,7 @@ discourseModule( ]; }); - const template = `{{mount-widget + const template = hbs`{{mount-widget widget="discourse-poll" args=(hash id=id post=post @@ -126,7 +127,6 @@ discourseModule( 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( @@ -134,7 +134,6 @@ discourseModule( .length, 1 ); - assert.equal(queryAll(".toggle-results").text(), "Show results"); }, });