From 625cf5a8ae4acdf6ec84c25408c3cd80f6e16500 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 18 Nov 2020 15:15:06 -0500 Subject: [PATCH] FIX: Modal methods should be wired up in `setupTests` not in module --- .../discourse/tests/helpers/qunit-helpers.js | 31 ------------------- .../discourse/tests/setup-tests.js | 30 ++++++++++++++++++ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js index c1c45225746..7776186da1e 100644 --- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js +++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js @@ -32,7 +32,6 @@ import { getOwner } from "discourse-common/lib/get-owner"; import { setTopicList } from "discourse/lib/topic-list-tracker"; import { setURLContainer } from "discourse/lib/url"; import { setDefaultOwner } from "discourse-common/lib/get-owner"; -import bootbox from "bootbox"; import { moduleFor } from "ember-qunit"; import QUnit, { module } from "qunit"; import siteFixtures from "discourse/tests/fixtures/site-fixtures"; @@ -68,36 +67,6 @@ export function fakeTime(timeString, timezone = null, advanceTime = false) { }); } -const Plugin = $.fn.modal; -const Modal = Plugin.Constructor; - -function AcceptanceModal(option, _relatedTarget) { - return this.each(function () { - var $this = $(this); - var data = $this.data("bs.modal"); - var options = $.extend( - {}, - Modal.DEFAULTS, - $this.data(), - typeof option === "object" && option - ); - - if (!data) { - $this.data("bs.modal", (data = new Modal(this, options))); - } - data.$body = $("#ember-testing"); - - if (typeof option === "string") { - data[option](_relatedTarget); - } else if (options.show) { - data.show(_relatedTarget); - } - }); -} - -bootbox.$body = $("#ember-testing"); -$.fn.modal = AcceptanceModal; - let _pretenderCallbacks = {}; export function resetSite(siteSettings, extras) { diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index efa8b2baf86..d4405bc2a80 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -26,6 +26,34 @@ import MessageBus from "message-bus-client"; import deprecated from "discourse-common/lib/deprecated"; import sinon from "sinon"; import { setApplication, setResolver } from "@ember/test-helpers"; +import bootbox from "bootbox"; + +const Plugin = $.fn.modal; +const Modal = Plugin.Constructor; + +function AcceptanceModal(option, _relatedTarget) { + return this.each(function () { + var $this = $(this); + var data = $this.data("bs.modal"); + var options = $.extend( + {}, + Modal.DEFAULTS, + $this.data(), + typeof option === "object" && option + ); + + if (!data) { + $this.data("bs.modal", (data = new Modal(this, options))); + } + data.$body = $("#ember-testing"); + + if (typeof option === "string") { + data[option](_relatedTarget); + } else if (options.show) { + data.show(_relatedTarget); + } + }); +} export default function setupTests(app, container) { setResolver(buildResolver("discourse").create({ namespace: app })); @@ -45,6 +73,8 @@ export default function setupTests(app, container) { app.setupForTesting(); app.SiteSettings = currentSettings(); app.start(); + bootbox.$body = $("#ember-testing"); + $.fn.modal = AcceptanceModal; // disable logster error reporting if (window.Logster) {