DEV: Avoid using globals (#14909)

This commit is contained in:
Jarek Radosz 2021-11-13 13:10:13 +01:00 committed by GitHub
parent 4ad77f3382
commit bdd2c888b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 105 additions and 66 deletions

View File

@ -5,15 +5,41 @@
"eol-last": 2 "eol-last": 2
}, },
"globals": { "globals": {
"_": "off",
"acceptance": "off",
"asyncRender": "off",
"bootbox": "off",
"click": "off",
"count": "off",
"currentPath": "off",
"currentRouteName": "off",
"currentURL": "off",
"currentUser": "off",
"Discourse": "off",
"exists": "off",
"fillIn": "off",
"find": "off",
"getSettledState": "off",
"hasModule": "off",
"invisible": "off",
"jQuery": "off", "jQuery": "off",
"keyboardHelper": "off",
"keyEvent": "off",
"moduleFor": "off", "moduleFor": "off",
"moduleForComponent": "off", "moduleForComponent": "off",
"testStart": "off", "pauseTest": "off",
"testDone": "off", "Pretender": "off",
"query": "off",
"queryAll": "off",
"QUnit": "off",
"sandbox": "off",
"sinon": "off", "sinon": "off",
"currentURL": "off", "test": "off",
"invisible": "off", "testDone": "off",
"testStart": "off",
"triggerEvent": "off",
"visible": "off", "visible": "off",
"count": "off" "visit": "off",
"waitUntil": "off"
} }
} }

View File

@ -2,6 +2,7 @@ import { COMPONENTS, THEMES } from "admin/models/theme";
import I18n from "I18n"; import I18n from "I18n";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { scrollTop } from "discourse/mixins/scroll-top"; import { scrollTop } from "discourse/mixins/scroll-top";
import bootbox from "bootbox";
export function showUnassignedComponentWarning(theme, callback) { export function showUnassignedComponentWarning(theme, callback) {
bootbox.confirm( bootbox.confirm(

View File

@ -1,8 +1,9 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { empty } from "@ember/object/computed"; import { empty } from "@ember/object/computed";
import { bind, default as computed } from "discourse-common/utils/decorators"; import computed, { bind } from "discourse-common/utils/decorators";
import I18n from "I18n"; import I18n from "I18n";
import bootbox from "bootbox";
export default Component.extend({ export default Component.extend({
classNames: ["pick-files-button"], classNames: ["pick-files-button"],

View File

@ -5,6 +5,7 @@ import { getWebauthnCredential } from "discourse/lib/webauthn";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { SECOND_FACTOR_METHODS } from "discourse/models/user"; import { SECOND_FACTOR_METHODS } from "discourse/models/user";
import I18n from "I18n"; import I18n from "I18n";
import bootbox from "bootbox";
export default Controller.extend(ModalFunctionality, { export default Controller.extend(ModalFunctionality, {
showSecondFactor: false, showSecondFactor: false,

View File

@ -18,6 +18,7 @@ import {
validateUploadedFile, validateUploadedFile,
} from "discourse/lib/uploads"; } from "discourse/lib/uploads";
import { cacheShortUploadUrl } from "pretty-text/upload-short-url"; import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
import bootbox from "bootbox";
// Note: This mixin is used _in addition_ to the ComposerUpload mixin // Note: This mixin is used _in addition_ to the ComposerUpload mixin
// on the composer-editor component. It overrides some, but not all, // on the composer-editor component. It overrides some, but not all,

View File

@ -13,6 +13,7 @@ import {
validateUploadedFiles, validateUploadedFiles,
} from "discourse/lib/uploads"; } from "discourse/lib/uploads";
import { cacheShortUploadUrl } from "pretty-text/upload-short-url"; import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
import bootbox from "bootbox";
export default Mixin.create({ export default Mixin.create({
_xhr: null, _xhr: null,

View File

@ -16,6 +16,7 @@ import UppyChecksum from "discourse/lib/uppy-checksum-plugin";
import UppyS3Multipart from "discourse/mixins/uppy-s3-multipart"; import UppyS3Multipart from "discourse/mixins/uppy-s3-multipart";
import { on } from "discourse-common/utils/decorators"; import { on } from "discourse-common/utils/decorators";
import { warn } from "@ember/debug"; import { warn } from "@ember/debug";
import bootbox from "bootbox";
export const HUGE_FILE_THRESHOLD_BYTES = 104_857_600; // 100MB export const HUGE_FILE_THRESHOLD_BYTES = 104_857_600; // 100MB

View File

@ -224,6 +224,7 @@ Site.reopenClass(Singleton, {
if (typeof Discourse !== "undefined") { if (typeof Discourse !== "undefined") {
let warned = false; let warned = false;
// eslint-disable-next-line no-undef
Object.defineProperty(Discourse, "Site", { Object.defineProperty(Discourse, "Site", {
get() { get() {
if (!warned) { if (!warned) {

View File

@ -1125,6 +1125,7 @@ User.reopenClass(Singleton, {
if (typeof Discourse !== "undefined") { if (typeof Discourse !== "undefined") {
let warned = false; let warned = false;
// eslint-disable-next-line no-undef
Object.defineProperty(Discourse, "User", { Object.defineProperty(Discourse, "User", {
get() { get() {
if (!warned) { if (!warned) {

View File

@ -2,6 +2,7 @@ import {
acceptance, acceptance,
count, count,
exists, exists,
query,
queryAll, queryAll,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
@ -91,16 +92,16 @@ acceptance("Admin - Watched Words", function (needs) {
await visit("/admin/customize/watched_words/action/replace"); await visit("/admin/customize/watched_words/action/replace");
await click(".watched-word-test"); await click(".watched-word-test");
await fillIn(".modal-body textarea", "Hi there!"); await fillIn(".modal-body textarea", "Hi there!");
assert.strictEqual(find(".modal-body li .match").text(), "Hi"); assert.strictEqual(query(".modal-body li .match").innerText, "Hi");
assert.strictEqual(find(".modal-body li .replacement").text(), "hello"); assert.strictEqual(query(".modal-body li .replacement").innerText, "hello");
}); });
test("test modal - tag", async function (assert) { test("test modal - tag", async function (assert) {
await visit("/admin/customize/watched_words/action/tag"); await visit("/admin/customize/watched_words/action/tag");
await click(".watched-word-test"); await click(".watched-word-test");
await fillIn(".modal-body textarea", "Hello world!"); await fillIn(".modal-body textarea", "Hello world!");
assert.strictEqual(find(".modal-body li .match").text(), "Hello"); assert.strictEqual(query(".modal-body li .match").innerText, "Hello");
assert.strictEqual(find(".modal-body li .tag").text(), "greeting"); assert.strictEqual(query(".modal-body li .tag").innerText, "greeting");
}); });
}); });

View File

@ -1,7 +1,7 @@
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import I18n from "I18n"; import I18n from "I18n";
import { test } from "qunit"; import { skip, test } from "qunit";
acceptance("Composer - Edit conflict", function (needs) { acceptance("Composer - Edit conflict", function (needs) {
needs.user(); needs.user();
@ -14,26 +14,23 @@ acceptance("Composer - Edit conflict", function (needs) {
}); });
}); });
QUnit.skip( skip("Edit a post that causes an edit conflict", async function (assert) {
"Edit a post that causes an edit conflict", await visit("/t/internationalization-localization/280");
async function (assert) { await click(".topic-post:nth-of-type(1) button.show-more-actions");
await visit("/t/internationalization-localization/280"); await click(".topic-post:nth-of-type(1) button.edit");
await click(".topic-post:nth-of-type(1) button.show-more-actions"); await fillIn(".d-editor-input", "this will 409");
await click(".topic-post:nth-of-type(1) button.edit"); await click("#reply-control button.create");
await fillIn(".d-editor-input", "this will 409"); assert.strictEqual(
await click("#reply-control button.create"); queryAll("#reply-control button.create").text().trim(),
assert.strictEqual( I18n.t("composer.overwrite_edit"),
queryAll("#reply-control button.create").text().trim(), "it shows the overwrite button"
I18n.t("composer.overwrite_edit"), );
"it shows the overwrite button" assert.ok(
); queryAll("#draft-status .d-icon-user-edit"),
assert.ok( "error icon should be there"
queryAll("#draft-status .d-icon-user-edit"), );
"error icon should be there" await click(".modal .btn-primary");
); });
await click(".modal .btn-primary");
}
);
test("Should not send originalText when posting a new reply", async function (assert) { test("Should not send originalText when posting a new reply", async function (assert) {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");

View File

@ -379,11 +379,9 @@ acceptance("Composer", function (needs) {
// at this point, request is in flight, so post is staged // at this point, request is in flight, so post is staged
assert.strictEqual(count(".topic-post.staged"), 1); assert.strictEqual(count(".topic-post.staged"), 1);
assert.ok( assert.ok(query(".topic-post:nth-of-type(1)").className.includes("staged"));
find(".topic-post:nth-of-type(1)")[0].className.includes("staged")
);
assert.strictEqual( assert.strictEqual(
find(".topic-post.staged .cooked").text().trim(), query(".topic-post.staged .cooked").innerText.trim(),
"will return empty json" "will return empty json"
); );
@ -394,26 +392,23 @@ acceptance("Composer", function (needs) {
assert.strictEqual(count(".topic-post.staged"), 0); assert.strictEqual(count(".topic-post.staged"), 0);
}); });
QUnit.skip( skip("Editing a post can rollback to old content", async function (assert) {
"Editing a post can rollback to old content", await visit("/t/internationalization-localization/280");
async function (assert) { await click(".topic-post:nth-of-type(1) button.show-more-actions");
await visit("/t/internationalization-localization/280"); await click(".topic-post:nth-of-type(1) button.edit");
await click(".topic-post:nth-of-type(1) button.show-more-actions");
await click(".topic-post:nth-of-type(1) button.edit");
await fillIn(".d-editor-input", "this will 409"); await fillIn(".d-editor-input", "this will 409");
await fillIn("#reply-title", "This is the new text for the title"); await fillIn("#reply-title", "This is the new text for the title");
await click("#reply-control button.create"); await click("#reply-control button.create");
assert.ok(!exists(".topic-post.staged")); assert.ok(!exists(".topic-post.staged"));
assert.strictEqual( assert.strictEqual(
find(".topic-post .cooked")[0].innerText, query(".topic-post .cooked").innerText,
"Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?" "Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?"
); );
await click(".bootbox.modal .btn-primary"); await click(".bootbox.modal .btn-primary");
} });
);
test("Composer can switch between edits", async function (assert) { test("Composer can switch between edits", async function (assert) {
await visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");

View File

@ -4,6 +4,7 @@ import {
count, count,
exists, exists,
fakeTime, fakeTime,
query,
queryAll, queryAll,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit"; import { test } from "qunit";
@ -53,7 +54,7 @@ acceptance("Invites - Create & Edit Invite Modal", function (needs) {
await visit("/u/eviltrout/invited/pending"); await visit("/u/eviltrout/invited/pending");
await click(".user-invite-buttons .btn:first-child"); await click(".user-invite-buttons .btn:first-child");
assert.strictEqual( assert.strictEqual(
find("input.invite-link")[0].value, query("input.invite-link").value,
"http://example.com/invites/52641ae8878790bc7b79916247cfe6ba", "http://example.com/invites/52641ae8878790bc7b79916247cfe6ba",
"shows an invite link when modal is opened" "shows an invite link when modal is opened"
); );
@ -102,7 +103,7 @@ acceptance("Invites - Create & Edit Invite Modal", function (needs) {
await fillIn("#invite-email", "error"); await fillIn("#invite-email", "error");
await click(".invite-link .btn"); await click(".invite-link .btn");
assert.strictEqual( assert.strictEqual(
find("#modal-alert").text(), query("#modal-alert").innerText,
"error isn't a valid email address." "error isn't a valid email address."
); );
}); });

View File

@ -4,7 +4,7 @@ import {
queryAll, queryAll,
selectText, selectText,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { fillIn, triggerKeyEvent, visit } from "@ember/test-helpers"; import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
acceptance("Fast Edit", function (needs) { acceptance("Fast Edit", function (needs) {

View File

@ -4,7 +4,7 @@ import {
exists, exists,
query, query,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { skip, test } from "qunit"; import { skip, test } from "qunit";
import userFixtures from "discourse/tests/fixtures/user-fixtures"; import userFixtures from "discourse/tests/fixtures/user-fixtures";

View File

@ -1,6 +1,7 @@
import { import {
acceptance, acceptance,
count, count,
exists,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";

View File

@ -5,7 +5,7 @@ import {
query, query,
queryAll, queryAll,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import I18n from "I18n"; import I18n from "I18n";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { test } from "qunit"; import { test } from "qunit";

View File

@ -1,4 +1,4 @@
import { currentURL, triggerKeyEvent, visit } from "@ember/test-helpers"; import { click, currentURL, triggerKeyEvent, visit } from "@ember/test-helpers";
import { cloneJSON } from "discourse-common/lib/object"; import { cloneJSON } from "discourse-common/lib/object";
import I18n from "I18n"; import I18n from "I18n";
import { import {

View File

@ -1,4 +1,4 @@
import { visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { import {
acceptance, acceptance,
count, count,

View File

@ -1,5 +1,5 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";

View File

@ -6,7 +6,7 @@ import {
selectText, selectText,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import I18n from "I18n"; import I18n from "I18n";
import { triggerKeyEvent, visit } from "@ember/test-helpers"; import { click, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
// This tests are flaky on Firefox. Fails with `calling set on destroyed object` // This tests are flaky on Firefox. Fails with `calling set on destroyed object`

View File

@ -9,7 +9,7 @@ import User from "discourse/models/user";
import { autoLoadModules } from "discourse/initializers/auto-load-modules"; import { autoLoadModules } from "discourse/initializers/auto-load-modules";
import createStore from "discourse/tests/helpers/create-store"; import createStore from "discourse/tests/helpers/create-store";
import { currentSettings } from "discourse/tests/helpers/site-settings"; import { currentSettings } from "discourse/tests/helpers/site-settings";
import { test } from "qunit"; import QUnit, { test } from "qunit";
const LEGACY_ENV = !EmberSetupRenderingTest; const LEGACY_ENV = !EmberSetupRenderingTest;

View File

@ -10,6 +10,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import I18n from "I18n"; import I18n from "I18n";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { click } from "@ember/test-helpers";
discourseModule("Integration | Component | bookmark", function (hooks) { discourseModule("Integration | Component | bookmark", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);

View File

@ -8,6 +8,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import I18n from "I18n"; import I18n from "I18n";
import { click } from "@ember/test-helpers";
discourseModule("Integration | Component | hidden-details", function (hooks) { discourseModule("Integration | Component | hidden-details", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);

View File

@ -5,7 +5,11 @@ import componentTest, {
setupRenderingTest, setupRenderingTest,
} from "discourse/tests/helpers/component-test"; } from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender"; import pretender from "discourse/tests/helpers/create-pretender";
import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers"; import {
discourseModule,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
@ -45,7 +49,7 @@ discourseModule("Integration | Component | invite-panel", function (hooks) {
assert.ok(!exists(".send-invite:disabled")); assert.ok(!exists(".send-invite:disabled"));
await click(".generate-invite-link"); await click(".generate-invite-link");
assert.strictEqual( assert.strictEqual(
find(".invite-link-input")[0].value, query(".invite-link-input").value,
"http://example.com/invites/92c297e886a0ca03089a109ccd6be155" "http://example.com/invites/92c297e886a0ca03089a109ccd6be155"
); );
}, },

View File

@ -5,6 +5,7 @@ import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { triggerEvent } from "@ember/test-helpers"; import { triggerEvent } from "@ember/test-helpers";
import sinon from "sinon"; import sinon from "sinon";
import bootbox from "bootbox";
function createBlob(mimeType, extension) { function createBlob(mimeType, extension) {
const blob = new Blob(["content"], { const blob = new Blob(["content"], {

View File

@ -8,6 +8,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender"; import pretender from "discourse/tests/helpers/create-pretender";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { click } from "@ember/test-helpers";
discourseModule("Integration | Component | site-header", function (hooks) { discourseModule("Integration | Component | site-header", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);

View File

@ -3,7 +3,7 @@ import {
applyCachedInlineOnebox, applyCachedInlineOnebox,
deleteCachedInlineOnebox, deleteCachedInlineOnebox,
} from "pretty-text/inline-oneboxer"; } from "pretty-text/inline-oneboxer";
import { module, skip, test } from "qunit"; import QUnit, { module, skip, test } from "qunit";
import Post from "discourse/models/post"; import Post from "discourse/models/post";
import { buildQuote } from "discourse/lib/quote"; import { buildQuote } from "discourse/lib/quote";
import { deepMerge } from "discourse-common/lib/object"; import { deepMerge } from "discourse-common/lib/object";

View File

@ -1,4 +1,5 @@
// discourse-skip-module // discourse-skip-module
(function () { (function () {
// eslint-disable-next-line no-undef
Discourse.start(); Discourse.start();
})(); })();

View File

@ -1,4 +1,4 @@
import { currentRouteName, visit } from "@ember/test-helpers"; import { click, currentRouteName, fillIn, visit } from "@ember/test-helpers";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { run } from "@ember/runloop"; import { run } from "@ember/runloop";
import startApp from "wizard/test/helpers/start-app"; import startApp from "wizard/test/helpers/start-app";

View File

@ -1,5 +1,6 @@
import { componentTest } from "wizard/test/helpers/component-test"; import { componentTest } from "wizard/test/helpers/component-test";
import { moduleForComponent } from "ember-qunit"; import { moduleForComponent } from "ember-qunit";
import { click, fillIn } from "@ember/test-helpers";
moduleForComponent("invite-list", { integration: true }); moduleForComponent("invite-list", { integration: true });