From c6a104295045ff95fbba12822e429cfe4fea2e84 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 27 Jan 2021 12:39:20 +0100 Subject: [PATCH] DEV: prettier 2.2.1 (#11862) --- .eslintignore | 1 + .prettierignore | 1 + .../admin/addon/components/admin-graph.js | 2 +- .../addon/components/secret-value-list.js | 4 +- .../addon/controllers/admin-badges-show.js | 2 +- .../addon/controllers/admin-user-fields.js | 21 +- .../admin/addon/helpers/value-at-tl.js | 4 +- .../admin/addon/routes/admin-user-badges.js | 2 +- app/assets/javascripts/browser-update.js | 18 +- .../addon/lib/attribute-hook.js | 4 +- .../discourse-common/addon/lib/helpers.js | 2 +- .../discourse-common/addon/lib/object.js | 2 +- .../addon/lib/raw-handlebars-helpers.js | 32 +- .../addon/lib/raw-handlebars.js | 22 +- .../discourse-common/addon/resolver.js | 12 +- .../addon/utils/decorator-alias.js | 2 +- .../addon/utils/decorators.js | 2 +- .../addon/utils/handle-descriptor.js | 2 +- .../discourse-hbr/raw-handlebars-compiler.js | 22 +- .../discourse/app/components/backup-codes.js | 12 +- .../app/components/basic-topic-list.js | 2 +- .../app/components/composer-editor.js | 4 +- .../discourse/app/components/d-editor.js | 2 +- .../app/components/popup-input-tip.js | 6 +- .../discourse/app/components/topic-list.js | 6 +- .../discourse/app/components/user-badge.js | 2 +- .../discourse/app/controllers/composer.js | 2 +- .../app/controllers/full-page-search.js | 6 +- .../discourse/app/controllers/history.js | 8 +- .../app/controllers/preferences/emails.js | 2 +- .../discourse/app/controllers/tags-index.js | 2 +- .../app/controllers/user-activity.js | 2 +- .../app/controllers/user-private-messages.js | 2 +- .../discourse/app/helpers/category-link.js | 4 +- .../discourse/app/helpers/format-date.js | 4 +- .../discourse/app/helpers/loading-spinner.js | 4 +- .../discourse/app/helpers/shorten-url.js | 2 +- .../discourse/app/lib/after-transition.js | 6 +- .../discourse/app/lib/category-hashtags.js | 4 +- .../discourse/app/lib/category-tag-search.js | 6 +- .../javascripts/discourse/app/lib/mobile.js | 2 +- .../discourse/app/lib/page-visible.js | 2 +- .../discourse/app/lib/plugin-api.js | 10 +- .../discourse/app/lib/safari-hacks.js | 12 +- .../discourse/app/lib/user-search.js | 12 +- .../discourse/app/lib/utilities.js | 16 +- .../discourse/app/mapping-router.js | 2 +- .../discourse/app/mixins/singleton.js | 2 +- .../discourse/app/models/category.js | 8 +- .../discourse/app/models/nav-item.js | 2 +- .../javascripts/discourse/app/models/store.js | 6 +- .../app/models/topic-tracking-state.js | 2 +- .../discourse/app/models/user-badge.js | 14 +- .../javascripts/discourse/app/models/user.js | 2 +- .../register-dom-templates.js | 4 +- .../app/routes/build-category-route.js | 2 +- .../discourse/app/routes/full-page-search.js | 2 +- .../discourse/app/routes/signup.js | 2 +- .../discourse/app/widgets/avatar-flair.js | 2 +- .../app/widgets/post-small-action.js | 2 +- .../tests/acceptance/hamburger-menu-test.js | 35 +- .../tests/acceptance/preferences-test.js | 43 +- .../discourse/tests/acceptance/tags-test.js | 2 +- .../components/activation-controls-test.js | 31 +- .../integration/components/d-editor-test.js | 216 ++++---- .../components/date-time-input-range-test.js | 35 +- .../components/secret-value-list-test.js | 153 ++--- .../select-kit/category-drop-test.js | 523 +++++++++--------- .../components/select-kit/combo-box-test.js | 109 ++-- .../select-kit/list-setting-test.js | 45 +- .../select-kit/multi-select-test.js | 69 +-- .../select-kit/single-select-test.js | 470 ++++++++-------- .../components/select-kit/tag-drop-test.js | 99 ++-- .../select-kit/user-chooser-test.js | 55 +- .../widgets/actions-summary-test.js | 51 +- .../integration/widgets/avatar-flair-test.js | 73 +-- .../widgets/hamburger-menu-test.js | 412 +++++++------- .../integration/widgets/home-logo-test.js | 423 +++++++------- .../integration/widgets/post-links-test.js | 140 +++-- .../integration/widgets/post-menu-test.js | 85 +-- .../integration/widgets/post-stream-test.js | 253 ++++----- .../integration/widgets/poster-name-test.js | 135 ++--- .../widgets/small-user-list-test.js | 43 +- .../integration/widgets/topic-status-test.js | 73 +-- .../integration/widgets/user-menu-test.js | 365 ++++++------ .../widgets/widget-dropdown-test.js | 435 +++++++-------- .../discourse/tests/setup-tests.js | 10 +- .../tests/unit/ember/resolver-test.js | 4 +- .../tests/unit/lib/click-track-test.js | 6 +- .../discourse/tests/unit/lib/computed-test.js | 10 +- .../tests/unit/lib/formatter-test.js | 10 +- .../discourse/tests/unit/lib/uploads-test.js | 2 +- .../tests/unit/lib/utilities-test.js | 10 +- .../tests/unit/mixins/singleton-test.js | 16 +- .../discourse/tests/unit/models/post-test.js | 8 +- .../tests/unit/models/rest-model-test.js | 2 +- .../tests/unit/models/topic-details-test.js | 4 +- .../tests/unit/models/user-action-test.js | 2 +- .../tests/unit/models/user-stream-test.js | 8 +- .../discourse/tests/unit/models/user-test.js | 6 +- app/assets/javascripts/embed-application.js | 20 +- .../discourse-markdown/bbcode-block.js | 2 +- .../engines/discourse-markdown/helpers.js | 2 +- .../engines/discourse-markdown/html-img.js | 2 +- .../engines/discourse-markdown/newline.js | 2 +- .../engines/discourse-markdown/paragraph.js | 2 +- .../engines/discourse-markdown/quotes.js | 2 +- .../discourse-markdown/resize-controls.js | 4 +- .../wizard/test/acceptance/wizard-test.js | 2 +- .../javascripts/wizard/test/test_helper.js | 10 +- package.json | 2 +- plugins/lazy-yt/assets/javascripts/lazyYT.js | 10 +- .../lib/discourse-markdown/poll.js.es6 | 14 +- .../assets/javascripts/lib/even-round.js.es6 | 2 +- .../javascripts/widgets/discourse-poll.js.es6 | 2 +- test/run-qunit.js | 10 +- yarn.lock | 18 +- 117 files changed, 2495 insertions(+), 2433 deletions(-) diff --git a/.eslintignore b/.eslintignore index c7910a26c05..afeff2c8691 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ +app/assets/javascripts/discourse-loader.js app/assets/javascripts/env.js app/assets/javascripts/main_include_admin.js app/assets/javascripts/vendor.js diff --git a/.prettierignore b/.prettierignore index ca81e935a82..b8874cd71cb 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,7 @@ config/locales/**/*.yml !config/locales/**/*.en*.yml script/import_scripts/**/*.yml +app/assets/javascripts/discourse-loader.js app/assets/javascripts/env.js app/assets/javascripts/main_include_admin.js app/assets/javascripts/vendor.js diff --git a/app/assets/javascripts/admin/addon/components/admin-graph.js b/app/assets/javascripts/admin/addon/components/admin-graph.js index bee93aa1c51..b6bf870bc19 100644 --- a/app/assets/javascripts/admin/addon/components/admin-graph.js +++ b/app/assets/javascripts/admin/addon/components/admin-graph.js @@ -10,7 +10,7 @@ export default Component.extend({ const model = this.model; const rawData = this.get("model.data"); - var data = { + let data = { labels: rawData.map((r) => r.x), datasets: [ { diff --git a/app/assets/javascripts/admin/addon/components/secret-value-list.js b/app/assets/javascripts/admin/addon/components/secret-value-list.js index 5ad0e5b3ceb..cd63e3b0ad3 100644 --- a/app/assets/javascripts/admin/addon/components/secret-value-list.js +++ b/app/assets/javascripts/admin/addon/components/secret-value-list.js @@ -94,9 +94,9 @@ export default Component.extend({ _splitValues(values, delimiter) { if (values && values.length) { const keys = ["key", "secret"]; - var res = []; + let res = []; values.split(delimiter).forEach(function (str) { - var object = {}; + let object = {}; str.split("|").forEach(function (a, i) { object[keys[i]] = a; }); diff --git a/app/assets/javascripts/admin/addon/controllers/admin-badges-show.js b/app/assets/javascripts/admin/addon/controllers/admin-badges-show.js index 3653af5fb1d..19f1d6ab6d3 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-badges-show.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-badges-show.js @@ -110,7 +110,7 @@ export default Controller.extend(bufferedProperty("model"), { const data = {}; const buffered = this.buffered; fields.forEach(function (field) { - var d = buffered.get(field); + let d = buffered.get(field); if (boolFields.includes(field)) { d = !!d; } diff --git a/app/assets/javascripts/admin/addon/controllers/admin-user-fields.js b/app/assets/javascripts/admin/addon/controllers/admin-user-fields.js index 9b37e931da2..bafcc02937e 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-user-fields.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-user-fields.js @@ -53,17 +53,18 @@ export default Controller.extend({ // Only confirm if we already been saved if (f.get("id")) { - bootbox.confirm(I18n.t("admin.user_fields.delete_confirm"), function ( - result - ) { - if (result) { - f.destroyRecord() - .then(function () { - model.removeObject(f); - }) - .catch(popupAjaxError); + bootbox.confirm( + I18n.t("admin.user_fields.delete_confirm"), + function (result) { + if (result) { + f.destroyRecord() + .then(function () { + model.removeObject(f); + }) + .catch(popupAjaxError); + } } - }); + ); } else { model.removeObject(f); } diff --git a/app/assets/javascripts/admin/addon/helpers/value-at-tl.js b/app/assets/javascripts/admin/addon/helpers/value-at-tl.js index 9e6b8c7514e..158b02b5468 100644 --- a/app/assets/javascripts/admin/addon/helpers/value-at-tl.js +++ b/app/assets/javascripts/admin/addon/helpers/value-at-tl.js @@ -1,9 +1,9 @@ import { registerUnbound } from "discourse-common/lib/helpers"; registerUnbound("value-at-tl", function (data, params) { - var tl = parseInt(params.level, 10); + let tl = parseInt(params.level, 10); if (data) { - var item = data.find(function (d) { + let item = data.find(function (d) { return parseInt(d.x, 10) === tl; }); if (item) { diff --git a/app/assets/javascripts/admin/addon/routes/admin-user-badges.js b/app/assets/javascripts/admin/addon/routes/admin-user-badges.js index f9549e39e6b..0c1621926ff 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-user-badges.js +++ b/app/assets/javascripts/admin/addon/routes/admin-user-badges.js @@ -14,7 +14,7 @@ export default DiscourseRoute.extend({ Badge.findAll().then(function (badges) { controller.set("badges", badges); if (badges.length > 0) { - var grantableBadges = controller.get("grantableBadges"); + let grantableBadges = controller.get("grantableBadges"); if (grantableBadges.length > 0) { controller.set("selectedBadgeId", grantableBadges[0].get("id")); } diff --git a/app/assets/javascripts/browser-update.js b/app/assets/javascripts/browser-update.js index cd2f60430b8..405b2e4a1d4 100644 --- a/app/assets/javascripts/browser-update.js +++ b/app/assets/javascripts/browser-update.js @@ -2,10 +2,10 @@ //Copyright (c) 2007-2009, MIT Style License (function () { - var $buo = function () { + let $buo = function () { // Sometimes we have to resort to parsing the user agent string. :( if (navigator && navigator.userAgent) { - var ua = navigator.userAgent; + let ua = navigator.userAgent; // we don't ask Googlebot to update their browser if ( @@ -22,10 +22,10 @@ } document.getElementsByTagName("body")[0].className += " crawler"; - var mainElement = document.getElementById("main"); - var noscriptElements = document.getElementsByTagName("noscript"); + let mainElement = document.getElementById("main"); + let noscriptElements = document.getElementsByTagName("noscript"); // find the element with the "data-path" attribute set - for (var i = 0; i < noscriptElements.length; ++i) { + for (let i = 0; i < noscriptElements.length; ++i) { if (noscriptElements[i].getAttribute("data-path")) { // noscriptElements[i].innerHTML contains encoded HTML if (noscriptElements[i].childNodes.length > 0) { @@ -36,7 +36,7 @@ } // retrieve localized browser upgrade text - var t = I18n.t("browser_update"); // eslint-disable-line no-undef + let t = I18n.t("browser_update"); // eslint-disable-line no-undef if (t.indexOf(".browser_update]") !== -1) { // very old browsers might fail to load even translations t = @@ -44,13 +44,13 @@ } // create the notification div HTML - var div = document.createElement("div"); + let div = document.createElement("div"); div.className = "buorg"; div.innerHTML = "
" + t + "
"; // create the notification div stylesheet - var sheet = document.createElement("style"); - var style = + let sheet = document.createElement("style"); + let style = ".buorg {position:absolute; z-index:111111; width:100%; top:0px; left:0px; background:#FDF2AB; text-align:left; font-family: sans-serif; color:#000; font-size: 14px;} .buorg div {padding: 8px;} .buorg a, .buorg a:visited {color:#E25600; text-decoration: underline;} @media print { .buorg { display: none !important; } }"; // insert the div and stylesheet into the DOM diff --git a/app/assets/javascripts/discourse-common/addon/lib/attribute-hook.js b/app/assets/javascripts/discourse-common/addon/lib/attribute-hook.js index 07bda95a9ec..d60b94eaf71 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/attribute-hook.js +++ b/app/assets/javascripts/discourse-common/addon/lib/attribute-hook.js @@ -32,8 +32,8 @@ AttributeHook.prototype.unhook = function (node, prop, next) { return; } - var colonPosition = prop.indexOf(":"); - var localName = colonPosition > -1 ? prop.substr(colonPosition + 1) : prop; + let colonPosition = prop.indexOf(":"); + let localName = colonPosition > -1 ? prop.substr(colonPosition + 1) : prop; node.removeAttributeNS(this.namespace, localName); }; diff --git a/app/assets/javascripts/discourse-common/addon/lib/helpers.js b/app/assets/javascripts/discourse-common/addon/lib/helpers.js index e9af233da88..a2014653c8e 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/helpers.js +++ b/app/assets/javascripts/discourse-common/addon/lib/helpers.js @@ -22,7 +22,7 @@ const _helpers = {}; function rawGet(ctx, property, options) { if (options.types && options.data.view) { - var view = options.data.view; + let view = options.data.view; return view.getStream ? view.getStream(property).value() : view.getAttr(property); diff --git a/app/assets/javascripts/discourse-common/addon/lib/object.js b/app/assets/javascripts/discourse-common/addon/lib/object.js index 4fe99d96b8a..294235b1ce2 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/object.js +++ b/app/assets/javascripts/discourse-common/addon/lib/object.js @@ -47,7 +47,7 @@ export function deepEqual(obj1, obj2) { if (Object.keys(obj1).length !== Object.keys(obj2).length) { return false; } - for (var prop in obj1) { + for (let prop in obj1) { if (!deepEqual(obj1[prop], obj2[prop])) { return false; } diff --git a/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars-helpers.js b/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars-helpers.js index 37bb2c93d0d..634d77c39e0 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars-helpers.js +++ b/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars-helpers.js @@ -29,24 +29,22 @@ export function registerRawHelpers(hbs, handlebarsClass) { }; // #each .. in support (as format is transformed to this) - hbs.registerHelper("each", function ( - localName, - inKeyword, - contextName, - options - ) { - if (typeof contextName === "undefined") { - return; + hbs.registerHelper( + "each", + function (localName, inKeyword, contextName, options) { + if (typeof contextName === "undefined") { + return; + } + let list = get(this, contextName); + let output = []; + for (let i = 0; i < list.length; i++) { + let innerContext = {}; + innerContext[localName] = list[i]; + output.push(options.fn(innerContext)); + } + return output.join(""); } - var list = get(this, contextName); - var output = []; - for (var i = 0; i < list.length; i++) { - let innerContext = {}; - innerContext[localName] = list[i]; - output.push(options.fn(innerContext)); - } - return output.join(""); - }); + ); function stringCompatHelper(fn) { const old = hbs.helpers[fn]; diff --git a/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars.js b/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars.js index d2d3149c796..f49e4273176 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars.js +++ b/app/assets/javascripts/discourse-common/addon/lib/raw-handlebars.js @@ -6,7 +6,7 @@ import Handlebars from "handlebars"; const RawHandlebars = Handlebars.create(); function buildPath(blk, args) { - var result = { + let result = { type: "PathExpression", data: false, depth: blk.path.depth, @@ -22,7 +22,7 @@ function buildPath(blk, args) { } function replaceGet(ast) { - var visitor = new Handlebars.Visitor(); + let visitor = new Handlebars.Visitor(); visitor.mutating = true; visitor.MustacheStatement = function (mustache) { @@ -42,7 +42,7 @@ function replaceGet(ast) { // This allows us to use the same syntax in all templates visitor.BlockStatement = function (block) { if (block.path.original === "each" && block.params.length === 1) { - var paramName = block.program.blockParams[0]; + let paramName = block.program.blockParams[0]; block.params = [ buildPath(block, { original: paramName }), { type: "CommentStatement", value: "in" }, @@ -74,10 +74,10 @@ if (Handlebars.Compiler) { RawHandlebars.JavaScriptCompiler.prototype.namespace = "RawHandlebars"; RawHandlebars.precompile = function (value, asObject) { - var ast = Handlebars.parse(value); + let ast = Handlebars.parse(value); replaceGet(ast); - var options = { + let options = { knownHelpers: { get: true, }, @@ -87,7 +87,7 @@ if (Handlebars.Compiler) { asObject = asObject === undefined ? true : asObject; - var environment = new RawHandlebars.Compiler().compile(ast, options); + let environment = new RawHandlebars.Compiler().compile(ast, options); return new RawHandlebars.JavaScriptCompiler().compile( environment, options, @@ -97,20 +97,20 @@ if (Handlebars.Compiler) { }; RawHandlebars.compile = function (string) { - var ast = Handlebars.parse(string); + let ast = Handlebars.parse(string); replaceGet(ast); // this forces us to rewrite helpers - var options = { data: true, stringParams: true }; - var environment = new RawHandlebars.Compiler().compile(ast, options); - var templateSpec = new RawHandlebars.JavaScriptCompiler().compile( + let options = { data: true, stringParams: true }; + let environment = new RawHandlebars.Compiler().compile(ast, options); + let templateSpec = new RawHandlebars.JavaScriptCompiler().compile( environment, options, undefined, true ); - var t = RawHandlebars.template(templateSpec); + let t = RawHandlebars.template(templateSpec); t.isMethod = false; return t; diff --git a/app/assets/javascripts/discourse-common/addon/resolver.js b/app/assets/javascripts/discourse-common/addon/resolver.js index f720febb291..51222877ffd 100644 --- a/app/assets/javascripts/discourse-common/addon/resolver.js +++ b/app/assets/javascripts/discourse-common/addon/resolver.js @@ -111,7 +111,7 @@ export function buildResolver(baseName) { ); }); - var module; + let module; if (moduleName) { module = requirejs(moduleName, null, null, true /* force sync */); if (module && module["default"]) { @@ -200,7 +200,7 @@ export function buildResolver(baseName) { findPluginMobileTemplate(parsedName) { if (_options.mobileView) { - var pluginParsedName = this.parseName( + let pluginParsedName = this.parseName( parsedName.fullName.replace( "template:", "template:javascripts/mobile/" @@ -212,7 +212,7 @@ export function buildResolver(baseName) { findMobileTemplate(parsedName) { if (_options.mobileView) { - var mobileParsedName = this.parseName( + let mobileParsedName = this.parseName( parsedName.fullName.replace("template:", "template:mobile/") ); return this.findTemplate(mobileParsedName); @@ -241,15 +241,15 @@ export function buildResolver(baseName) { }, findUnderscoredTemplate(parsedName) { - var decamelized = parsedName.fullNameWithoutType.decamelize(); - var underscored = decamelized.replace(/\-/g, "_"); + let decamelized = parsedName.fullNameWithoutType.decamelize(); + let underscored = decamelized.replace(/\-/g, "_"); return Ember.TEMPLATES[underscored]; }, // Try to find a template within a special admin namespace, e.g. adminEmail => admin/templates/email // (similar to how discourse lays out templates) findAdminTemplate(parsedName) { - var decamelized = parsedName.fullNameWithoutType.decamelize(); + let decamelized = parsedName.fullNameWithoutType.decamelize(); if (decamelized.indexOf("components") === 0) { let comPath = `admin/templates/${decamelized}`; const compTemplate = diff --git a/app/assets/javascripts/discourse-common/addon/utils/decorator-alias.js b/app/assets/javascripts/discourse-common/addon/utils/decorator-alias.js index 96692bb5531..dd4299c700b 100644 --- a/app/assets/javascripts/discourse-common/addon/utils/decorator-alias.js +++ b/app/assets/javascripts/discourse-common/addon/utils/decorator-alias.js @@ -12,7 +12,7 @@ export default function decoratorAlias(fn, errorMessage) { configurable: desc.configurable, writable: desc.writable, initializer: function () { - var value = extractValue(desc); + let value = extractValue(desc); return fn.apply(null, params.concat(value)); }, }; diff --git a/app/assets/javascripts/discourse-common/addon/utils/decorators.js b/app/assets/javascripts/discourse-common/addon/utils/decorators.js index c7f3729d8e2..4fad373bf8b 100644 --- a/app/assets/javascripts/discourse-common/addon/utils/decorators.js +++ b/app/assets/javascripts/discourse-common/addon/utils/decorators.js @@ -51,7 +51,7 @@ export function readOnly(target, name, desc) { enumerable: desc.enumerable, configurable: desc.configurable, initializer: function () { - var value = extractValue(desc); + let value = extractValue(desc); return value.readOnly(); }, }; diff --git a/app/assets/javascripts/discourse-common/addon/utils/handle-descriptor.js b/app/assets/javascripts/discourse-common/addon/utils/handle-descriptor.js index f8ff22c817a..3987adffa6c 100644 --- a/app/assets/javascripts/discourse-common/addon/utils/handle-descriptor.js +++ b/app/assets/javascripts/discourse-common/addon/utils/handle-descriptor.js @@ -10,7 +10,7 @@ export default function handleDescriptor(target, key, desc, params = []) { let computedDescriptor; if (desc.writable) { - var val = extractValue(desc); + let val = extractValue(desc); if (typeof val === "object") { let value = {}; if (val.get) { diff --git a/app/assets/javascripts/discourse-hbr/raw-handlebars-compiler.js b/app/assets/javascripts/discourse-hbr/raw-handlebars-compiler.js index 1cbffd611bf..659f9241149 100644 --- a/app/assets/javascripts/discourse-hbr/raw-handlebars-compiler.js +++ b/app/assets/javascripts/discourse-hbr/raw-handlebars-compiler.js @@ -6,7 +6,7 @@ const Handlebars = require("handlebars"); const RawHandlebars = Handlebars.create(); function buildPath(blk, args) { - var result = { + let result = { type: "PathExpression", data: false, depth: blk.path.depth, @@ -22,7 +22,7 @@ function buildPath(blk, args) { } function replaceGet(ast) { - var visitor = new Handlebars.Visitor(); + let visitor = new Handlebars.Visitor(); visitor.mutating = true; visitor.MustacheStatement = function (mustache) { @@ -42,7 +42,7 @@ function replaceGet(ast) { // This allows us to use the same syntax in all templates visitor.BlockStatement = function (block) { if (block.path.original === "each" && block.params.length === 1) { - var paramName = block.program.blockParams[0]; + let paramName = block.program.blockParams[0]; block.params = [ buildPath(block, { original: paramName }), { type: "CommentStatement", value: "in" }, @@ -71,10 +71,10 @@ RawHandlebars.JavaScriptCompiler.prototype.compiler = RawHandlebars.JavaScriptCompiler.prototype.namespace = "RawHandlebars"; RawHandlebars.precompile = function (value, asObject) { - var ast = Handlebars.parse(value); + let ast = Handlebars.parse(value); replaceGet(ast); - var options = { + let options = { knownHelpers: { get: true, }, @@ -84,7 +84,7 @@ RawHandlebars.precompile = function (value, asObject) { asObject = asObject === undefined ? true : asObject; - var environment = new RawHandlebars.Compiler().compile(ast, options); + let environment = new RawHandlebars.Compiler().compile(ast, options); return new RawHandlebars.JavaScriptCompiler().compile( environment, options, @@ -94,20 +94,20 @@ RawHandlebars.precompile = function (value, asObject) { }; RawHandlebars.compile = function (string) { - var ast = Handlebars.parse(string); + let ast = Handlebars.parse(string); replaceGet(ast); // this forces us to rewrite helpers - var options = { data: true, stringParams: true }; - var environment = new RawHandlebars.Compiler().compile(ast, options); - var templateSpec = new RawHandlebars.JavaScriptCompiler().compile( + let options = { data: true, stringParams: true }; + let environment = new RawHandlebars.Compiler().compile(ast, options); + let templateSpec = new RawHandlebars.JavaScriptCompiler().compile( environment, options, undefined, true ); - var t = RawHandlebars.template(templateSpec); + let t = RawHandlebars.template(templateSpec); t.isMethod = false; return t; diff --git a/app/assets/javascripts/discourse/app/components/backup-codes.js b/app/assets/javascripts/discourse/app/components/backup-codes.js index e66fe6de634..565f2821741 100644 --- a/app/assets/javascripts/discourse/app/components/backup-codes.js +++ b/app/assets/javascripts/discourse/app/components/backup-codes.js @@ -5,12 +5,12 @@ import discourseComputed from "discourse-common/utils/decorators"; // https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding function b64EncodeUnicode(str) { return btoa( - encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes( - match, - p1 - ) { - return String.fromCharCode("0x" + p1); - }) + encodeURIComponent(str).replace( + /%([0-9A-F]{2})/g, + function toSolidBytes(match, p1) { + return String.fromCharCode("0x" + p1); + } + ) ); } diff --git a/app/assets/javascripts/discourse/app/components/basic-topic-list.js b/app/assets/javascripts/discourse/app/components/basic-topic-list.js index 0445741f0b1..3343512568a 100644 --- a/app/assets/javascripts/discourse/app/components/basic-topic-list.js +++ b/app/assets/javascripts/discourse/app/components/basic-topic-list.js @@ -10,7 +10,7 @@ export default Component.extend({ @discourseComputed("topicList.loaded") loaded() { - var topicList = this.topicList; + let topicList = this.topicList; if (topicList) { return topicList.get("loaded"); } else { diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.js index 2ed3a8712ac..b666a5ad339 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor.js +++ b/app/assets/javascripts/discourse/app/components/composer-editor.js @@ -536,10 +536,10 @@ export default Component.extend({ _warnMentionedGroups($preview) { schedule("afterRender", () => { - var found = this.warnedGroupMentions || []; + let found = this.warnedGroupMentions || []; $preview.find(".mention-group.notify").each((idx, e) => { const $e = $(e); - var name = $e.data("name"); + let name = $e.data("name"); if (found.indexOf(name) === -1) { this.groupsMentioned([ { diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js index c5c636ab67e..de6531d172e 100644 --- a/app/assets/javascripts/discourse/app/components/d-editor.js +++ b/app/assets/javascripts/discourse/app/components/d-editor.js @@ -184,7 +184,7 @@ class Toolbar { if (button.shortcut) { const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); const mod = mac ? "Meta" : "Ctrl"; - var shortcutTitle = `${mod}+${button.shortcut}`; + let shortcutTitle = `${mod}+${button.shortcut}`; // Mac users are used to glyphs for shortcut keys if (mac) { diff --git a/app/assets/javascripts/discourse/app/components/popup-input-tip.js b/app/assets/javascripts/discourse/app/components/popup-input-tip.js index 51d5519862d..9d02aeff014 100644 --- a/app/assets/javascripts/discourse/app/components/popup-input-tip.js +++ b/app/assets/javascripts/discourse/app/components/popup-input-tip.js @@ -28,7 +28,7 @@ export default Component.extend({ @observes("lastShownAt") bounce() { if (this.lastShownAt) { - var $elem = $(this.element); + let $elem = $(this.element); if (!this.animateAttribute) { this.animateAttribute = $elem.css("left") === "auto" ? "right" : "left"; } @@ -51,7 +51,7 @@ export default Component.extend({ }, bounceLeft($elem) { - for (var i = 0; i < 5; i++) { + for (let i = 0; i < 5; i++) { $elem .animate({ left: "+=" + this.bouncePixels }, this.bounceDelay) .animate({ left: "-=" + this.bouncePixels }, this.bounceDelay); @@ -59,7 +59,7 @@ export default Component.extend({ }, bounceRight($elem) { - for (var i = 0; i < 5; i++) { + for (let i = 0; i < 5; i++) { $elem .animate({ right: "-=" + this.bouncePixels }, this.bounceDelay) .animate({ right: "+=" + this.bouncePixels }, this.bounceDelay); diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js index 2f1270844f1..8383cb035e0 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list.js +++ b/app/assets/javascripts/discourse/app/components/topic-list.js @@ -163,9 +163,9 @@ export default Component.extend(LoadMore, { }, click(e) { - var self = this; - var onClick = function (sel, callback) { - var target = $(e.target).closest(sel); + let self = this; + let onClick = function (sel, callback) { + let target = $(e.target).closest(sel); if (target.length === 1) { callback.apply(self, [target]); diff --git a/app/assets/javascripts/discourse/app/components/user-badge.js b/app/assets/javascripts/discourse/app/components/user-badge.js index 201fa550218..6a2c8ceddb1 100644 --- a/app/assets/javascripts/discourse/app/components/user-badge.js +++ b/app/assets/javascripts/discourse/app/components/user-badge.js @@ -12,7 +12,7 @@ export default Component.extend({ @discourseComputed("badge", "user") badgeUrl() { // NOTE: I tried using a link-to helper here but the queryParams mean it fails - var username = this.get("user.username_lower") || ""; + let username = this.get("user.username_lower") || ""; username = username !== "" ? "?username=" + username : ""; return this.get("badge.url") + username; }, diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index afdf82bb263..6f8d6e245ed 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -727,7 +727,7 @@ export default Controller.extend({ } } - var staged = false; + let staged = false; // TODO: This should not happen in model const imageSizes = {}; diff --git a/app/assets/javascripts/discourse/app/controllers/full-page-search.js b/app/assets/javascripts/discourse/app/controllers/full-page-search.js index 44dee80ae3e..a7ba222f8c2 100644 --- a/app/assets/javascripts/discourse/app/controllers/full-page-search.js +++ b/app/assets/javascripts/discourse/app/controllers/full-page-search.js @@ -77,9 +77,9 @@ export default Controller.extend({ @discourseComputed("context", "context_id") searchContextDescription(context, id) { - var name = id; + let name = id; if (context === "category") { - var category = Category.findById(id); + let category = Category.findById(id); if (!category) { return; } @@ -322,7 +322,7 @@ export default Controller.extend({ }, loadMore() { - var page = this.page; + let page = this.page; if ( this.get("model.grouped_search_result.more_full_page_results") && !this.loading && diff --git a/app/assets/javascripts/discourse/app/controllers/history.js b/app/assets/javascripts/discourse/app/controllers/history.js index 23d66efe331..b6fd92cc7e8 100644 --- a/app/assets/javascripts/discourse/app/controllers/history.js +++ b/app/assets/javascripts/discourse/app/controllers/history.js @@ -17,7 +17,7 @@ import { sanitizeAsync } from "discourse/lib/text"; function customTagArray(fieldName) { return computed(fieldName, function () { - var val = this.get(fieldName); + let val = this.get(fieldName); if (!val) { return val; } @@ -194,7 +194,7 @@ export default Controller.extend(ModalFunctionality, { if (displayingInline) { return this.isEitherRevisionHidden ? "hidden-revision-either" : null; } else { - var result = []; + let result = []; if (prevHidden) { result.push("hidden-revision-previous"); } @@ -227,7 +227,7 @@ export default Controller.extend(ModalFunctionality, { @discourseComputed("model.category_id_changes") previousCategory(changes) { if (changes) { - var category = Category.findById(changes["previous"]); + let category = Category.findById(changes["previous"]); return categoryBadgeHTML(category, { allowUncategorized: true }); } }, @@ -235,7 +235,7 @@ export default Controller.extend(ModalFunctionality, { @discourseComputed("model.category_id_changes") currentCategory(changes) { if (changes) { - var category = Category.findById(changes["current"]); + let category = Category.findById(changes["current"]); return categoryBadgeHTML(category, { allowUncategorized: true }); } }, diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/emails.js b/app/assets/javascripts/discourse/app/controllers/preferences/emails.js index 2062170002d..2709ebe99eb 100644 --- a/app/assets/javascripts/discourse/app/controllers/preferences/emails.js +++ b/app/assets/javascripts/discourse/app/controllers/preferences/emails.js @@ -62,7 +62,7 @@ export default Controller.extend({ @discourseComputed() frequencyEstimate() { - var estimate = this.get("model.mailing_list_posts_per_day"); + let estimate = this.get("model.mailing_list_posts_per_day"); if (!estimate || estimate < 2) { return I18n.t("user.mailing_list_mode.few_per_day"); } else { diff --git a/app/assets/javascripts/discourse/app/controllers/tags-index.js b/app/assets/javascripts/discourse/app/controllers/tags-index.js index 7222df90c92..60acd67e74f 100644 --- a/app/assets/javascripts/discourse/app/controllers/tags-index.js +++ b/app/assets/javascripts/discourse/app/controllers/tags-index.js @@ -72,7 +72,7 @@ export default Controller.extend({ } const joinedTags = tags.slice(0, displayN).join(", "); - var more = Math.max(0, tags.length - displayN); + let more = Math.max(0, tags.length - displayN); const tagsString = more === 0 diff --git a/app/assets/javascripts/discourse/app/controllers/user-activity.js b/app/assets/javascripts/discourse/app/controllers/user-activity.js index d6e7241f358..f2023c232bb 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-activity.js +++ b/app/assets/javascripts/discourse/app/controllers/user-activity.js @@ -16,7 +16,7 @@ export default Controller.extend({ @observes("userActionType", "model.stream.itemsLoaded") _showFooter: function () { - var showFooter; + let showFooter; if (this.userActionType) { const stat = (this.get("model.stats") || []).find( (s) => s.action_type === this.userActionType diff --git a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js index 4e1fd703931..e14955789e1 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js +++ b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js @@ -40,7 +40,7 @@ export default Controller.extend({ bulkOperation(operation) { const selected = this.selected; - var params = { type: operation }; + let params = { type: operation }; if (this.isGroup) { params.group = this.groupFilter; } diff --git a/app/assets/javascripts/discourse/app/helpers/category-link.js b/app/assets/javascripts/discourse/app/helpers/category-link.js index 71dcd3d7224..289b0407d90 100644 --- a/app/assets/javascripts/discourse/app/helpers/category-link.js +++ b/app/assets/javascripts/discourse/app/helpers/category-link.js @@ -16,7 +16,7 @@ export function replaceCategoryLinkRenderer(fn) { } function categoryStripe(color, classes) { - var style = color ? "style='background-color: #" + color + ";'" : ""; + let style = color ? "style='background-color: #" + color + ";'" : ""; return ""; } @@ -65,7 +65,7 @@ export function categoryBadgeHTML(category, opts) { } export function categoryLinkHTML(category, options) { - var categoryOptions = {}; + let categoryOptions = {}; // TODO: This is a compatibility layer with the old helper structure. // Can be removed once we migrate to `registerUnbound` fully diff --git a/app/assets/javascripts/discourse/app/helpers/format-date.js b/app/assets/javascripts/discourse/app/helpers/format-date.js index e91759cdce8..1798b23e02f 100644 --- a/app/assets/javascripts/discourse/app/helpers/format-date.js +++ b/app/assets/javascripts/discourse/app/helpers/format-date.js @@ -7,7 +7,7 @@ import { registerUnbound } from "discourse-common/lib/helpers"; update the dates on a regular interval. **/ registerUnbound("format-date", function (val, params) { - var leaveAgo, + let leaveAgo, format = "medium", title = true; @@ -22,7 +22,7 @@ registerUnbound("format-date", function (val, params) { } if (val) { - var date = new Date(val); + let date = new Date(val); return htmlSafe( autoUpdatingRelativeAge(date, { format: format, diff --git a/app/assets/javascripts/discourse/app/helpers/loading-spinner.js b/app/assets/javascripts/discourse/app/helpers/loading-spinner.js index 5f15403d050..5188c619905 100644 --- a/app/assets/javascripts/discourse/app/helpers/loading-spinner.js +++ b/app/assets/javascripts/discourse/app/helpers/loading-spinner.js @@ -1,13 +1,13 @@ import { htmlHelper } from "discourse-common/lib/helpers"; function renderSpinner(cssClass) { - var html = "
"; } -var spinnerHTML = renderSpinner(); +let spinnerHTML = renderSpinner(); export default htmlHelper((params) => { const hash = params.hash; diff --git a/app/assets/javascripts/discourse/app/helpers/shorten-url.js b/app/assets/javascripts/discourse/app/helpers/shorten-url.js index 5b7012a3394..4a35906190d 100644 --- a/app/assets/javascripts/discourse/app/helpers/shorten-url.js +++ b/app/assets/javascripts/discourse/app/helpers/shorten-url.js @@ -1,7 +1,7 @@ import { registerUnbound } from "discourse-common/lib/helpers"; registerUnbound("shorten-url", function (url) { - var matches = url.match(/\//g); + let matches = url.match(/\//g); if (matches && matches.length === 3) { url = url.replace(/\/$/, ""); diff --git a/app/assets/javascripts/discourse/app/lib/after-transition.js b/app/assets/javascripts/discourse/app/lib/after-transition.js index 16c57b53cff..70edaaf8436 100644 --- a/app/assets/javascripts/discourse/app/lib/after-transition.js +++ b/app/assets/javascripts/discourse/app/lib/after-transition.js @@ -4,7 +4,7 @@ SO: http://stackoverflow.com/questions/9943435/css3-animation-end-techniques **/ -var dummy = document.createElement("div"), +let dummy = document.createElement("div"), eventNameHash = { webkit: "webkitTransitionEnd", Moz: "transitionend", @@ -12,8 +12,8 @@ var dummy = document.createElement("div"), ms: "MSTransitionEnd", }; -var transitionEnd = (function () { - var retValue; +let transitionEnd = (function () { + let retValue; retValue = "transitionend"; Object.keys(eventNameHash).some(function (vendor) { if (vendor + "TransitionProperty" in dummy.style) { diff --git a/app/assets/javascripts/discourse/app/lib/category-hashtags.js b/app/assets/javascripts/discourse/app/lib/category-hashtags.js index 75c85616f91..18cf98b8993 100644 --- a/app/assets/javascripts/discourse/app/lib/category-hashtags.js +++ b/app/assets/javascripts/discourse/app/lib/category-hashtags.js @@ -15,8 +15,8 @@ export function replaceSpan($elem, categorySlug, categoryLink, type) { export function categoryHashtagTriggerRule(textarea, opts) { const result = caretRowCol(textarea); const row = result.rowNum; - var col = result.colNum; - var line = textarea.value.split("\n")[row - 1]; + let col = result.colNum; + let line = textarea.value.split("\n")[row - 1]; if (opts && opts.backSpace) { col = col - 1; diff --git a/app/assets/javascripts/discourse/app/lib/category-tag-search.js b/app/assets/javascripts/discourse/app/lib/category-tag-search.js index d2e1fd5c83f..ef84ac811f1 100644 --- a/app/assets/javascripts/discourse/app/lib/category-tag-search.js +++ b/app/assets/javascripts/discourse/app/lib/category-tag-search.js @@ -37,7 +37,7 @@ function searchTags(term, categories, limit) { data: { limit: limit, q }, }); - var returnVal = CANCELLED_STATUS; + let returnVal = CANCELLED_STATUS; oldSearch .then((r) => { @@ -91,8 +91,8 @@ export function search(term, siteSettings) { } const limit = 5; - var categories = Category.search(term, { limit }); - var numOfCategories = categories.length; + let categories = Category.search(term, { limit }); + let numOfCategories = categories.length; categories = categories.map((category) => { return { model: category, text: Category.slugFor(category, SEPARATOR, 2) }; diff --git a/app/assets/javascripts/discourse/app/lib/mobile.js b/app/assets/javascripts/discourse/app/lib/mobile.js index e7c15439486..a35cfcee6df 100644 --- a/app/assets/javascripts/discourse/app/lib/mobile.js +++ b/app/assets/javascripts/discourse/app/lib/mobile.js @@ -27,7 +27,7 @@ const Mobile = { localStorage.removeItem("mobileView"); } if (localStorage.mobileView) { - var savedValue = localStorage.mobileView === "true"; + let savedValue = localStorage.mobileView === "true"; if (savedValue !== this.mobileView) { this.reloadPage(savedValue); } diff --git a/app/assets/javascripts/discourse/app/lib/page-visible.js b/app/assets/javascripts/discourse/app/lib/page-visible.js index 7733a9d7474..0771a2f3c00 100644 --- a/app/assets/javascripts/discourse/app/lib/page-visible.js +++ b/app/assets/javascripts/discourse/app/lib/page-visible.js @@ -1,5 +1,5 @@ // for android we test webkit -var hiddenProperty = +let hiddenProperty = document.hidden !== undefined ? "hidden" : document.webkitHidden !== undefined diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js index ce4145cd5e8..636c8207a7a 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-api.js +++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js @@ -1227,11 +1227,11 @@ let _pluginv01; // from http://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number function cmpVersions(a, b) { - var i, diff; - var regExStrip0 = /(\.0+)+$/; - var segmentsA = a.replace(regExStrip0, "").split("."); - var segmentsB = b.replace(regExStrip0, "").split("."); - var l = Math.min(segmentsA.length, segmentsB.length); + let i, diff; + let regExStrip0 = /(\.0+)+$/; + let segmentsA = a.replace(regExStrip0, "").split("."); + let segmentsB = b.replace(regExStrip0, "").split("."); + let l = Math.min(segmentsA.length, segmentsB.length); for (i = 0; i < l; i++) { diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); diff --git a/app/assets/javascripts/discourse/app/lib/safari-hacks.js b/app/assets/javascripts/discourse/app/lib/safari-hacks.js index 99c8b335e1f..1bea1a5f078 100644 --- a/app/assets/javascripts/discourse/app/lib/safari-hacks.js +++ b/app/assets/javascripts/discourse/app/lib/safari-hacks.js @@ -93,7 +93,7 @@ function positioningWorkaround($fixedElement) { const fixedElement = $fixedElement[0]; const oldHeight = fixedElement.style.height; - var originalScrollTop = 0; + let originalScrollTop = 0; let lastTouchedElement = null; positioningWorkaround.blur = function (evt) { @@ -114,7 +114,7 @@ function positioningWorkaround($fixedElement) { } }; - var blurredNow = function (evt) { + let blurredNow = function (evt) { // we cannot use evt.relatedTarget to get the last focused element in safari iOS // document.activeElement is also unreliable (iOS does not mark buttons as focused) // so instead, we store the last touched element and check against it @@ -145,11 +145,11 @@ function positioningWorkaround($fixedElement) { positioningWorkaround.blur(evt); }; - var blurred = function (evt) { + let blurred = function (evt) { discourseDebounce(this, blurredNow, evt, INPUT_DELAY); }; - var positioningHack = function (evt) { + let positioningHack = function (evt) { let _this = this; if (evt === undefined) { @@ -203,7 +203,7 @@ function positioningWorkaround($fixedElement) { }, delay); }; - var lastTouched = function (evt) { + let lastTouched = function (evt) { if (evt && evt.target) { lastTouchedElement = evt.target; } @@ -231,7 +231,7 @@ function positioningWorkaround($fixedElement) { }; positioningWorkaround.touchstartEvent = function (element) { - var triggerHack = positioningHack.bind(element); + let triggerHack = positioningHack.bind(element); triggerHack(); }; diff --git a/app/assets/javascripts/discourse/app/lib/user-search.js b/app/assets/javascripts/discourse/app/lib/user-search.js index c77c5c6cd79..980d92a417a 100644 --- a/app/assets/javascripts/discourse/app/lib/user-search.js +++ b/app/assets/javascripts/discourse/app/lib/user-search.js @@ -6,7 +6,7 @@ import { emailValid } from "discourse/lib/utilities"; import { isTesting } from "discourse-common/config/environment"; import { userPath } from "discourse/lib/url"; -var cache = {}, +let cache = {}, cacheKey, cacheTime, currentTerm, @@ -23,7 +23,7 @@ function performSearch( groupMembersOf, resultsFn ) { - var cached = cache[term]; + let cached = cache[term]; if (cached) { resultsFn(cached); return; @@ -52,7 +52,7 @@ function performSearch( }, }); - var returnVal = CANCELLED_STATUS; + let returnVal = CANCELLED_STATUS; oldSearch .then(function (r) { @@ -81,7 +81,7 @@ function performSearch( }); } -var debouncedSearch = function ( +let debouncedSearch = function ( term, topicId, categoryId, @@ -113,7 +113,7 @@ function organizeResults(r, options) { return r; } - var exclude = options.exclude || [], + let exclude = options.exclude || [], limit = options.limit || 5, users = [], emails = [], @@ -182,7 +182,7 @@ export default function userSearch(options) { options.term = options.term.substring(1); } - var term = options.term || "", + let term = options.term || "", includeGroups = options.includeGroups, includeMentionableGroups = options.includeMentionableGroups, includeMessageableGroups = options.includeMessageableGroups, diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js index 6267aa8f219..f7b7bad13e8 100644 --- a/app/assets/javascripts/discourse/app/lib/utilities.js +++ b/app/assets/javascripts/discourse/app/lib/utilities.js @@ -97,7 +97,7 @@ export function tinyAvatar(avatarTemplate, options) { } export function postUrl(slug, topicId, postNumber) { - var url = getURL("/t/"); + let url = getURL("/t/"); if (slug) { url += slug + "/"; } else { @@ -190,11 +190,11 @@ export function selectedElement() { // Determine the row and col of the caret in an element export function caretRowCol(el) { - var cp = caretPosition(el); - var rows = el.value.slice(0, cp).split("\n"); - var rowNum = rows.length; + let cp = caretPosition(el); + let rows = el.value.slice(0, cp).split("\n"); + let rowNum = rows.length; - var colNum = + let colNum = cp - rows.splice(0, rowNum - 1).reduce(function (sum, row) { return sum + row.length + 1; @@ -205,7 +205,7 @@ export function caretRowCol(el) { // Determine the position of the caret in an element export function caretPosition(el) { - var r, rc, re; + let r, rc, re; if (el.selectionStart) { return el.selectionStart; } @@ -227,7 +227,7 @@ export function caretPosition(el) { // Set the caret's position export function setCaretPosition(ctrl, pos) { - var range; + let range; if (ctrl.setSelectionRange) { ctrl.focus(); ctrl.setSelectionRange(pos, pos); @@ -421,7 +421,7 @@ export function areCookiesEnabled() { // see: https://github.com/Modernizr/Modernizr/blob/400db4043c22af98d46e1d2b9cbc5cb062791192/feature-detects/cookies.js try { document.cookie = "cookietest=1"; - var ret = document.cookie.indexOf("cookietest=") !== -1; + let ret = document.cookie.indexOf("cookietest=") !== -1; document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT"; return ret; } catch (e) { diff --git a/app/assets/javascripts/discourse/app/mapping-router.js b/app/assets/javascripts/discourse/app/mapping-router.js index 3f332c6e429..39ab250c8f4 100644 --- a/app/assets/javascripts/discourse/app/mapping-router.js +++ b/app/assets/javascripts/discourse/app/mapping-router.js @@ -113,7 +113,7 @@ export function mapRoutes() { // can define admin routes. Object.keys(requirejs._eak_seen).forEach(function (key) { if (/route-map$/.test(key)) { - var module = requirejs(key, null, null, true); + let module = requirejs(key, null, null, true); if (!module || !module.default) { throw new Error(key + " must export a route map."); } diff --git a/app/assets/javascripts/discourse/app/mixins/singleton.js b/app/assets/javascripts/discourse/app/mixins/singleton.js index 6bed17037e1..7aabd44c354 100644 --- a/app/assets/javascripts/discourse/app/mixins/singleton.js +++ b/app/assets/javascripts/discourse/app/mixins/singleton.js @@ -67,7 +67,7 @@ const Singleton = Mixin.create({ // Returns OR sets a property on the singleton instance. currentProp(property, value) { - var instance = this.current(); + let instance = this.current(); if (!instance) { return; } diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js index 2340a7213dd..b6b84f4634f 100644 --- a/app/assets/javascripts/discourse/app/models/category.js +++ b/app/assets/javascripts/discourse/app/models/category.js @@ -312,7 +312,7 @@ const Category = RestModel.extend({ }, }); -var _uncategorized; +let _uncategorized; Category.reopenClass({ slugEncoded() { @@ -508,7 +508,7 @@ Category.reopenClass({ }, search(term, opts) { - var limit = 5; + let limit = 5; if (opts) { if (opts.limit === 0) { @@ -529,8 +529,8 @@ Category.reopenClass({ const categories = Category.listByActivity(); const length = categories.length; - var i; - var data = []; + let i; + let data = []; const done = () => { return data.length === limit; diff --git a/app/assets/javascripts/discourse/app/models/nav-item.js b/app/assets/javascripts/discourse/app/models/nav-item.js index 6c1fe8213c9..d369d05f366 100644 --- a/app/assets/javascripts/discourse/app/models/nav-item.js +++ b/app/assets/javascripts/discourse/app/models/nav-item.js @@ -177,7 +177,7 @@ NavItem.reopenClass({ return null; } - var args = { name: filterType, hasIcon: filterType === "unread" }; + let args = { name: filterType, hasIcon: filterType === "unread" }; if (opts.category) { args.category = opts.category; } diff --git a/app/assets/javascripts/discourse/app/models/store.js b/app/assets/javascripts/discourse/app/models/store.js index aa477b0ee1e..d1783c08ef3 100644 --- a/app/assets/javascripts/discourse/app/models/store.js +++ b/app/assets/javascripts/discourse/app/models/store.js @@ -114,9 +114,9 @@ export default EmberObject.extend({ }, find(type, findArgs, opts) { - var adapter = this.adapterFor(type); + let adapter = this.adapterFor(type); return adapter.find(this, type, findArgs, opts).then((result) => { - var hydrated = this._hydrateFindResults(result, type, findArgs, opts); + let hydrated = this._hydrateFindResults(result, type, findArgs, opts); if (result.extras) { hydrated.set("extras", result.extras); @@ -139,7 +139,7 @@ export default EmberObject.extend({ hydrated.set( "content", hydrated.get("content").map((item) => { - var staleItem = stale.content.findBy(primaryKey, item.get(primaryKey)); + let staleItem = stale.content.findBy(primaryKey, item.get(primaryKey)); if (staleItem) { staleItem.setProperties(item); } else { diff --git a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js index d2ceed6a3aa..71a2bb709b5 100644 --- a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js +++ b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js @@ -291,7 +291,7 @@ const TopicTrackingState = EmberObject.extend({ if (split.length >= 4) { filter = split[split.length - 1]; // c/cat/subcat/6/l/latest - var category = Category.findSingleBySlug( + let category = Category.findSingleBySlug( split.splice(1, split.length - 4).join("/") ); this.set("filterCategory", category); diff --git a/app/assets/javascripts/discourse/app/models/user-badge.js b/app/assets/javascripts/discourse/app/models/user-badge.js index 304059d65db..0aaff3f561a 100644 --- a/app/assets/javascripts/discourse/app/models/user-badge.js +++ b/app/assets/javascripts/discourse/app/models/user-badge.js @@ -27,7 +27,7 @@ UserBadge.reopenClass({ if (json.users === undefined) { json.users = []; } - var users = {}; + let users = {}; json.users.forEach(function (userJson) { users[userJson.id] = User.create(userJson); }); @@ -36,7 +36,7 @@ UserBadge.reopenClass({ if (json.topics === undefined) { json.topics = []; } - var topics = {}; + let topics = {}; json.topics.forEach(function (topicJson) { topics[topicJson.id] = Topic.create(topicJson); }); @@ -45,13 +45,13 @@ UserBadge.reopenClass({ if (json.badges === undefined) { json.badges = []; } - var badges = {}; + let badges = {}; Badge.createFromJson(json).forEach(function (badge) { badges[badge.get("id")] = badge; }); // Create UserBadge object(s). - var userBadges = []; + let userBadges = []; if ("user_badge" in json) { userBadges = [json.user_badge]; } else { @@ -61,9 +61,9 @@ UserBadge.reopenClass({ } userBadges = userBadges.map(function (userBadgeJson) { - var userBadge = UserBadge.create(userBadgeJson); + let userBadge = UserBadge.create(userBadgeJson); - var grantedAtDate = Date.parse(userBadge.get("granted_at")); + let grantedAtDate = Date.parse(userBadge.get("granted_at")); userBadge.set("grantedAt", grantedAtDate); userBadge.set("badge", badges[userBadge.get("badge_id")]); @@ -102,7 +102,7 @@ UserBadge.reopenClass({ if (!username) { return Promise.resolve([]); } - var url = "/user-badges/" + username + ".json"; + let url = "/user-badges/" + username + ".json"; if (options && options.grouped) { url += "?grouped=true"; } diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index 7a0b562b43a..61f34556f66 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -342,7 +342,7 @@ const User = RestModel.extend({ data[s] = this.get(`user_option.${s}`); }); - var updatedState = {}; + let updatedState = {}; ["muted", "regular", "watched", "tracked", "watched_first_post"].forEach( (s) => { diff --git a/app/assets/javascripts/discourse/app/pre-initializers/register-dom-templates.js b/app/assets/javascripts/discourse/app/pre-initializers/register-dom-templates.js index 27b511eb532..d3f6dbe3c6f 100644 --- a/app/assets/javascripts/discourse/app/pre-initializers/register-dom-templates.js +++ b/app/assets/javascripts/discourse/app/pre-initializers/register-dom-templates.js @@ -3,8 +3,8 @@ export default { initialize: function () { $('script[type="text/x-handlebars"]').each(function () { - var $this = $(this); - var name = $this.attr("name") || $this.data("template-name"); + let $this = $(this); + let name = $this.attr("name") || $this.data("template-name"); if (window.console) { window.console.log( diff --git a/app/assets/javascripts/discourse/app/routes/build-category-route.js b/app/assets/javascripts/discourse/app/routes/build-category-route.js index 8672db77c12..5b77d14f82f 100644 --- a/app/assets/javascripts/discourse/app/routes/build-category-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-category-route.js @@ -157,7 +157,7 @@ export default (filterArg, params) => { canCreateTopic: canCreateTopic, }); - var topicOpts = { + let topicOpts = { model: topics, category, period: diff --git a/app/assets/javascripts/discourse/app/routes/full-page-search.js b/app/assets/javascripts/discourse/app/routes/full-page-search.js index f628bb7998c..3c4fe847153 100644 --- a/app/assets/javascripts/discourse/app/routes/full-page-search.js +++ b/app/assets/javascripts/discourse/app/routes/full-page-search.js @@ -30,7 +30,7 @@ export default DiscourseRoute.extend({ model(params) { const cached = getTransient("lastSearch"); - var args = { q: params.q }; + let args = { q: params.q }; if (params.context_id && !args.skip_context) { args.search_context = { type: params.context, diff --git a/app/assets/javascripts/discourse/app/routes/signup.js b/app/assets/javascripts/discourse/app/routes/signup.js index f46e3c544ef..89a6a04c7a9 100644 --- a/app/assets/javascripts/discourse/app/routes/signup.js +++ b/app/assets/javascripts/discourse/app/routes/signup.js @@ -5,7 +5,7 @@ const SignupRoute = buildStaticRoute("signup"); SignupRoute.reopen({ beforeModel() { - var canSignUp = this.controllerFor("application").get("canSignUp"); + let canSignUp = this.controllerFor("application").get("canSignUp"); if (!this.siteSettings.login_required) { this.replaceWith("discovery.latest").then((e) => { diff --git a/app/assets/javascripts/discourse/app/widgets/avatar-flair.js b/app/assets/javascripts/discourse/app/widgets/avatar-flair.js index 5aafe34de9f..450b8bb40f0 100644 --- a/app/assets/javascripts/discourse/app/widgets/avatar-flair.js +++ b/app/assets/javascripts/discourse/app/widgets/avatar-flair.js @@ -29,7 +29,7 @@ createWidget("avatar-flair", { }, buildAttributes(attrs) { - var style = ""; + let style = ""; if (!this.isIcon(attrs)) { style += "background-image: url(" + diff --git a/app/assets/javascripts/discourse/app/widgets/post-small-action.js b/app/assets/javascripts/discourse/app/widgets/post-small-action.js index 700ffef23ae..be5066e3d8b 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-small-action.js +++ b/app/assets/javascripts/discourse/app/widgets/post-small-action.js @@ -12,7 +12,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username) { const dt = new Date(createdAt); const when = autoUpdatingRelativeAge(dt, { format: "medium-with-ago" }); - var who = ""; + let who = ""; if (username) { if (actionCode === "invited_group" || actionCode === "removed_group") { who = `@${username}`; diff --git a/app/assets/javascripts/discourse/tests/acceptance/hamburger-menu-test.js b/app/assets/javascripts/discourse/tests/acceptance/hamburger-menu-test.js index 618315426ed..d073b449421 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/hamburger-menu-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/hamburger-menu-test.js @@ -6,22 +6,23 @@ import { import { click, visit } from "@ember/test-helpers"; import { test } from "qunit"; -acceptance("Opening the hamburger menu with some reviewables", function ( - needs -) { - needs.user(); - needs.pretender((server, helper) => { - server.get("/review/count.json", () => helper.response({ count: 3 })); - }); - test("As a staff member", async function (assert) { - updateCurrentUser({ moderator: true, admin: false }); +acceptance( + "Opening the hamburger menu with some reviewables", + function (needs) { + needs.user(); + needs.pretender((server, helper) => { + server.get("/review/count.json", () => helper.response({ count: 3 })); + }); + test("As a staff member", async function (assert) { + updateCurrentUser({ moderator: true, admin: false }); - await visit("/"); - await click(".hamburger-dropdown"); + await visit("/"); + await click(".hamburger-dropdown"); - assert.equal( - queryAll(".review .badge-notification.reviewables").text(), - "3" - ); - }); -}); + assert.equal( + queryAll(".review .badge-notification.reviewables").text(), + "3" + ); + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/acceptance/preferences-test.js b/app/assets/javascripts/discourse/tests/acceptance/preferences-test.js index c95e9559914..c87974cf1a6 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/preferences-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/preferences-test.js @@ -290,28 +290,29 @@ acceptance("Second Factor Backups", function (needs) { }); }); -acceptance("Avatar selector when selectable avatars is enabled", function ( - needs -) { - needs.user(); - needs.settings({ selectable_avatars_enabled: true }); - needs.pretender((server, helper) => { - server.get("/site/selectable-avatars.json", () => - helper.response([ - "https://www.discourse.org", - "https://meta.discourse.org", - ]) - ); - }); +acceptance( + "Avatar selector when selectable avatars is enabled", + function (needs) { + needs.user(); + needs.settings({ selectable_avatars_enabled: true }); + needs.pretender((server, helper) => { + server.get("/site/selectable-avatars.json", () => + helper.response([ + "https://www.discourse.org", + "https://meta.discourse.org", + ]) + ); + }); - test("selectable avatars", async function (assert) { - await visit("/u/eviltrout/preferences"); - await click(".pref-avatar .btn"); - assert.ok( - exists(".selectable-avatars", "opens the avatar selection modal") - ); - }); -}); + test("selectable avatars", async function (assert) { + await visit("/u/eviltrout/preferences"); + await click(".pref-avatar .btn"); + assert.ok( + exists(".selectable-avatars", "opens the avatar selection modal") + ); + }); + } +); acceptance("User Preferences when badges are disabled", function (needs) { needs.user(); diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js index 434e21cba10..8d0670b0c8d 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js @@ -1,9 +1,9 @@ import { acceptance, exists, + invisible, queryAll, updateCurrentUser, - invisible, } from "discourse/tests/helpers/qunit-helpers"; import { click, currentURL, visit } from "@ember/test-helpers"; import { test } from "qunit"; diff --git a/app/assets/javascripts/discourse/tests/integration/components/activation-controls-test.js b/app/assets/javascripts/discourse/tests/integration/components/activation-controls-test.js index d44c3981582..b97c72aecdc 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/activation-controls-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/activation-controls-test.js @@ -6,20 +6,21 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; -discourseModule("Integration | Component | activation-controls", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | activation-controls", + function (hooks) { + setupRenderingTest(hooks); - componentTest("hides change email button", { - template: `{{activation-controls}}`, - beforeEach() { - this.siteSettings.enable_local_logins = false; - this.siteSettings.email_editable = false; - }, + componentTest("hides change email button", { + template: `{{activation-controls}}`, + beforeEach() { + this.siteSettings.enable_local_logins = false; + this.siteSettings.email_editable = false; + }, - test(assert) { - assert.equal(queryAll("button.edit-email").length, 0); - }, - }); -}); + test(assert) { + assert.equal(queryAll("button.edit-email").length, 0); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js index 2503f89da92..c6408ba2aab 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js @@ -97,33 +97,33 @@ discourseModule("Integration | Component | d-editor", function (hooks) { }); } - testCase(`selecting the space before a word`, async function ( - assert, - textarea - ) { - textarea.selectionStart = 5; - textarea.selectionEnd = 7; + testCase( + `selecting the space before a word`, + async function (assert, textarea) { + textarea.selectionStart = 5; + textarea.selectionEnd = 7; - await click(`button.bold`); + await click(`button.bold`); - assert.equal(this.value, `hello **w**orld.`); - assert.equal(textarea.selectionStart, 8); - assert.equal(textarea.selectionEnd, 9); - }); + assert.equal(this.value, `hello **w**orld.`); + assert.equal(textarea.selectionStart, 8); + assert.equal(textarea.selectionEnd, 9); + } + ); - testCase(`selecting the space after a word`, async function ( - assert, - textarea - ) { - textarea.selectionStart = 0; - textarea.selectionEnd = 6; + testCase( + `selecting the space after a word`, + async function (assert, textarea) { + textarea.selectionStart = 0; + textarea.selectionEnd = 6; - await click(`button.bold`); + await click(`button.bold`); - assert.equal(this.value, `**hello** world.`); - assert.equal(textarea.selectionStart, 2); - assert.equal(textarea.selectionEnd, 7); - }); + assert.equal(this.value, `**hello** world.`); + assert.equal(textarea.selectionStart, 2); + assert.equal(textarea.selectionEnd, 7); + } + ); testCase(`bold button with no selection`, async function (assert, textarea) { await click(`button.bold`); @@ -149,37 +149,37 @@ discourseModule("Integration | Component | d-editor", function (hooks) { assert.equal(textarea.selectionEnd, 11); }); - testCase(`bold with a multiline selection`, async function ( - assert, - textarea - ) { - this.set("value", "hello\n\nworld\n\ntest."); + testCase( + `bold with a multiline selection`, + async function (assert, textarea) { + this.set("value", "hello\n\nworld\n\ntest."); - textarea.selectionStart = 0; - textarea.selectionEnd = 12; + textarea.selectionStart = 0; + textarea.selectionEnd = 12; - await click(`button.bold`); - assert.equal(this.value, `**hello**\n\n**world**\n\ntest.`); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 20); + await click(`button.bold`); + assert.equal(this.value, `**hello**\n\n**world**\n\ntest.`); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 20); - await click(`button.bold`); - assert.equal(this.value, `hello\n\nworld\n\ntest.`); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 12); - }); + await click(`button.bold`); + assert.equal(this.value, `hello\n\nworld\n\ntest.`); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 12); + } + ); - testCase(`italic button with no selection`, async function ( - assert, - textarea - ) { - await click(`button.italic`); - const example = I18n.t(`composer.italic_text`); - assert.equal(this.value, `hello world.*${example}*`); + testCase( + `italic button with no selection`, + async function (assert, textarea) { + await click(`button.italic`); + const example = I18n.t(`composer.italic_text`); + assert.equal(this.value, `hello world.*${example}*`); - assert.equal(textarea.selectionStart, 13); - assert.equal(textarea.selectionEnd, 13 + example.length); - }); + assert.equal(textarea.selectionStart, 13); + assert.equal(textarea.selectionEnd, 13 + example.length); + } + ); testCase(`italic button with a selection`, async function (assert, textarea) { textarea.selectionStart = 6; @@ -196,25 +196,25 @@ discourseModule("Integration | Component | d-editor", function (hooks) { assert.equal(textarea.selectionEnd, 11); }); - testCase(`italic with a multiline selection`, async function ( - assert, - textarea - ) { - this.set("value", "hello\n\nworld\n\ntest."); + testCase( + `italic with a multiline selection`, + async function (assert, textarea) { + this.set("value", "hello\n\nworld\n\ntest."); - textarea.selectionStart = 0; - textarea.selectionEnd = 12; + textarea.selectionStart = 0; + textarea.selectionEnd = 12; - await click(`button.italic`); - assert.equal(this.value, `*hello*\n\n*world*\n\ntest.`); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 16); + await click(`button.italic`); + assert.equal(this.value, `*hello*\n\n*world*\n\ntest.`); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 16); - await click(`button.italic`); - assert.equal(this.value, `hello\n\nworld\n\ntest.`); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 12); - }); + await click(`button.italic`); + assert.equal(this.value, `hello\n\nworld\n\ntest.`); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 12); + } + ); componentTest("advanced code", { template: "{{d-editor value=value}}", @@ -508,20 +508,20 @@ third line` assert.equal(this.value, "hello\n\nwor\n\nld.\n\n> Blockquote"); }); - testCase(`bullet button with no selection`, async function ( - assert, - textarea - ) { - const example = I18n.t("composer.list_item"); + testCase( + `bullet button with no selection`, + async function (assert, textarea) { + const example = I18n.t("composer.list_item"); - await click(`button.bullet`); - assert.equal(this.value, `hello world.\n\n* ${example}`); - assert.equal(textarea.selectionStart, 14); - assert.equal(textarea.selectionEnd, 16 + example.length); + await click(`button.bullet`); + assert.equal(this.value, `hello world.\n\n* ${example}`); + assert.equal(textarea.selectionStart, 14); + assert.equal(textarea.selectionEnd, 16 + example.length); - await click(`button.bullet`); - assert.equal(this.value, `hello world.\n\n${example}`); - }); + await click(`button.bullet`); + assert.equal(this.value, `hello world.\n\n${example}`); + } + ); testCase(`bullet button with a selection`, async function (assert, textarea) { textarea.selectionStart = 6; @@ -538,25 +538,25 @@ third line` assert.equal(textarea.selectionEnd, 12); }); - testCase(`bullet button with a multiple line selection`, async function ( - assert, - textarea - ) { - this.set("value", "* Hello\n\nWorld\n\nEvil"); + testCase( + `bullet button with a multiple line selection`, + async function (assert, textarea) { + this.set("value", "* Hello\n\nWorld\n\nEvil"); - textarea.selectionStart = 0; - textarea.selectionEnd = 20; + textarea.selectionStart = 0; + textarea.selectionEnd = 20; - await click(`button.bullet`); - assert.equal(this.value, "Hello\n\nWorld\n\nEvil"); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 18); + await click(`button.bullet`); + assert.equal(this.value, "Hello\n\nWorld\n\nEvil"); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 18); - await click(`button.bullet`); - assert.equal(this.value, "* Hello\n\n* World\n\n* Evil"); - assert.equal(textarea.selectionStart, 0); - assert.equal(textarea.selectionEnd, 24); - }); + await click(`button.bullet`); + assert.equal(this.value, "* Hello\n\n* World\n\n* Evil"); + assert.equal(textarea.selectionStart, 0); + assert.equal(textarea.selectionEnd, 24); + } + ); testCase(`list button with no selection`, async function (assert, textarea) { const example = I18n.t("composer.list_item"); @@ -633,23 +633,23 @@ third line` }, }); - testCase(`doesn't jump to bottom with long text`, async function ( - assert, - textarea - ) { - let longText = "hello world."; - for (let i = 0; i < 8; i++) { - longText = longText + longText; + testCase( + `doesn't jump to bottom with long text`, + async function (assert, textarea) { + let longText = "hello world."; + for (let i = 0; i < 8; i++) { + longText = longText + longText; + } + this.set("value", longText); + + $(textarea).scrollTop(0); + textarea.selectionStart = 3; + textarea.selectionEnd = 3; + + await click("button.bold"); + assert.equal($(textarea).scrollTop(), 0, "it stays scrolled up"); } - this.set("value", longText); - - $(textarea).scrollTop(0); - textarea.selectionStart = 3; - textarea.selectionEnd = 3; - - await click("button.bold"); - assert.equal($(textarea).scrollTop(), 0, "it stays scrolled up"); - }); + ); componentTest("emoji", { template: "{{d-editor value=value}}", diff --git a/app/assets/javascripts/discourse/tests/integration/components/date-time-input-range-test.js b/app/assets/javascripts/discourse/tests/integration/components/date-time-input-range-test.js index eade3cffdff..f7b2ca1af94 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/date-time-input-range-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/date-time-input-range-test.js @@ -24,23 +24,24 @@ function toTimeInput() { const DEFAULT_DATE_TIME = moment("2019-01-29 14:45"); -discourseModule("Integration | Component | date-time-input-range", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | date-time-input-range", + function (hooks) { + setupRenderingTest(hooks); - componentTest("default", { - template: `{{date-time-input-range from=from to=to}}`, + componentTest("default", { + template: `{{date-time-input-range from=from to=to}}`, - beforeEach() { - this.setProperties({ from: DEFAULT_DATE_TIME, to: null }); - }, + beforeEach() { + this.setProperties({ from: DEFAULT_DATE_TIME, to: null }); + }, - test(assert) { - assert.equal(fromDateInput().value, "January 29, 2019"); - assert.equal(fromTimeInput().dataset.name, "14:45"); - assert.equal(toDateInput().value, ""); - assert.equal(toTimeInput().dataset.name, "--:--"); - }, - }); -}); + test(assert) { + assert.equal(fromDateInput().value, "January 29, 2019"); + assert.equal(fromTimeInput().dataset.name, "14:45"); + assert.equal(toDateInput().value, ""); + assert.equal(toTimeInput().dataset.name, "--:--"); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js index 684ef966d14..bc3bc78a74a 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/secret-value-list-test.js @@ -8,98 +8,99 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import I18n from "I18n"; -discourseModule("Integration | Component | secret-value-list", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | secret-value-list", + function (hooks) { + setupRenderingTest(hooks); - componentTest("adding a value", { - template: "{{secret-value-list values=values}}", + componentTest("adding a value", { + template: "{{secret-value-list values=values}}", - async test(assert) { - this.set("values", "firstKey|FirstValue\nsecondKey|secondValue"); + async test(assert) { + this.set("values", "firstKey|FirstValue\nsecondKey|secondValue"); - await fillIn(".new-value-input.key", "thirdKey"); - await click(".add-value-btn"); + await fillIn(".new-value-input.key", "thirdKey"); + await click(".add-value-btn"); - assert.ok( - queryAll(".values .value").length === 2, - "it doesn't add the value to the list if secret is missing" - ); + assert.ok( + queryAll(".values .value").length === 2, + "it doesn't add the value to the list if secret is missing" + ); - await fillIn(".new-value-input.key", ""); - await fillIn(".new-value-input.secret", "thirdValue"); - await click(".add-value-btn"); + await fillIn(".new-value-input.key", ""); + await fillIn(".new-value-input.secret", "thirdValue"); + await click(".add-value-btn"); - assert.ok( - queryAll(".values .value").length === 2, - "it doesn't add the value to the list if key is missing" - ); + assert.ok( + queryAll(".values .value").length === 2, + "it doesn't add the value to the list if key is missing" + ); - await fillIn(".new-value-input.key", "thirdKey"); - await fillIn(".new-value-input.secret", "thirdValue"); - await click(".add-value-btn"); + await fillIn(".new-value-input.key", "thirdKey"); + await fillIn(".new-value-input.secret", "thirdValue"); + await click(".add-value-btn"); - assert.ok( - queryAll(".values .value").length === 3, - "it adds the value to the list of values" - ); + assert.ok( + queryAll(".values .value").length === 3, + "it adds the value to the list of values" + ); - assert.deepEqual( - this.values, - "firstKey|FirstValue\nsecondKey|secondValue\nthirdKey|thirdValue", - "it adds the value to the list of values" - ); - }, - }); + assert.deepEqual( + this.values, + "firstKey|FirstValue\nsecondKey|secondValue\nthirdKey|thirdValue", + "it adds the value to the list of values" + ); + }, + }); - componentTest("adding an invalid value", { - template: "{{secret-value-list values=values}}", + componentTest("adding an invalid value", { + template: "{{secret-value-list values=values}}", - async test(assert) { - await fillIn(".new-value-input.key", "someString"); - await fillIn(".new-value-input.secret", "keyWithAPipe|Hidden"); - await click(".add-value-btn"); + async test(assert) { + await fillIn(".new-value-input.key", "someString"); + await fillIn(".new-value-input.secret", "keyWithAPipe|Hidden"); + await click(".add-value-btn"); - assert.ok( - queryAll(".values .value").length === 0, - "it doesn't add the value to the list of values" - ); + assert.ok( + queryAll(".values .value").length === 0, + "it doesn't add the value to the list of values" + ); - assert.deepEqual( - this.values, - undefined, - "it doesn't add the value to the list of values" - ); + assert.deepEqual( + this.values, + undefined, + "it doesn't add the value to the list of values" + ); - assert.ok( - queryAll(".validation-error") - .html() - .indexOf(I18n.t("admin.site_settings.secret_list.invalid_input")) > - -1, - "it shows validation error" - ); - }, - }); + assert.ok( + queryAll(".validation-error") + .html() + .indexOf(I18n.t("admin.site_settings.secret_list.invalid_input")) > + -1, + "it shows validation error" + ); + }, + }); - componentTest("removing a value", { - template: "{{secret-value-list values=values}}", + componentTest("removing a value", { + template: "{{secret-value-list values=values}}", - async test(assert) { - this.set("values", "firstKey|FirstValue\nsecondKey|secondValue"); + async test(assert) { + this.set("values", "firstKey|FirstValue\nsecondKey|secondValue"); - await click(".values .value[data-index='0'] .remove-value-btn"); + await click(".values .value[data-index='0'] .remove-value-btn"); - assert.ok( - queryAll(".values .value").length === 1, - "it removes the value from the list of values" - ); + assert.ok( + queryAll(".values .value").length === 1, + "it removes the value from the list of values" + ); - assert.equal( - this.values, - "secondKey|secondValue", - "it removes the expected value" - ); - }, - }); -}); + assert.equal( + this.values, + "secondKey|secondValue", + "it removes the expected value" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-drop-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-drop-test.js index 4cc1a4b013a..b3611c36701 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-drop-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-drop-test.js @@ -47,313 +47,314 @@ function template(options = []) { `; } -discourseModule("Integration | Component | select-kit/category-drop", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/category-drop", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("caretUpIcon", { - template: ` + componentTest("caretUpIcon", { + template: ` {{category-drop category=value categories=content }} `, - async test(assert) { - const $header = this.subject.header().el(); + async test(assert) { + const $header = this.subject.header().el(); - assert.ok( - exists($header.find(`.d-icon-caret-right`)), - "it uses the correct default icon" - ); - }, - }); + assert.ok( + exists($header.find(`.d-icon-caret-right`)), + "it uses the correct default icon" + ); + }, + }); - componentTest("none", { - template: ` + componentTest("none", { + template: ` {{category-drop category=value categories=content }} `, - async test(assert) { - const text = this.subject.header().label(); - assert.equal( - text, - I18n.t("category.all").toLowerCase(), - "it uses the noneLabel" - ); - }, - }); + async test(assert) { + const text = this.subject.header().label(); + assert.equal( + text, + I18n.t("category.all").toLowerCase(), + "it uses the noneLabel" + ); + }, + }); - componentTest("[not staff - TL0] displayCategoryDescription", { - template: template(), + componentTest("[not staff - TL0] displayCategoryDescription", { + template: template(), - beforeEach() { - set(this.currentUser, "staff", false); - set(this.currentUser, "trust_level", 0); + beforeEach() { + set(this.currentUser, "staff", false); + set(this.currentUser, "trust_level", 0); - initCategories(this); - }, + initCategories(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const row = this.subject.rowByValue(this.category.id); - assert.ok( - exists(row.el().find(".category-desc")), - "it shows category description for newcomers" - ); - }, - }); + const row = this.subject.rowByValue(this.category.id); + assert.ok( + exists(row.el().find(".category-desc")), + "it shows category description for newcomers" + ); + }, + }); - componentTest("[not staff - TL1] displayCategoryDescription", { - template: template(), + componentTest("[not staff - TL1] displayCategoryDescription", { + template: template(), - beforeEach() { - set(this.currentUser, "moderator", false); - set(this.currentUser, "admin", false); - set(this.currentUser, "trust_level", 1); - initCategories(this); - }, + beforeEach() { + set(this.currentUser, "moderator", false); + set(this.currentUser, "admin", false); + set(this.currentUser, "trust_level", 1); + initCategories(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const row = this.subject.rowByValue(this.category.id); - assert.ok( - !exists(row.el().find(".category-desc")), - "it doesn't shows category description for TL0+" - ); - }, - }); + const row = this.subject.rowByValue(this.category.id); + assert.ok( + !exists(row.el().find(".category-desc")), + "it doesn't shows category description for TL0+" + ); + }, + }); - componentTest("[staff - TL0] displayCategoryDescription", { - template: template(), + componentTest("[staff - TL0] displayCategoryDescription", { + template: template(), - beforeEach() { - set(this.currentUser, "moderator", true); - set(this.currentUser, "trust_level", 0); + beforeEach() { + set(this.currentUser, "moderator", true); + set(this.currentUser, "trust_level", 0); - initCategories(this); - }, + initCategories(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const row = this.subject.rowByValue(this.category.id); - assert.ok( - !exists(row.el().find(".category-desc")), - "it doesn't show category description for staff" - ); - }, - }); + const row = this.subject.rowByValue(this.category.id); + assert.ok( + !exists(row.el().find(".category-desc")), + "it doesn't show category description for staff" + ); + }, + }); - componentTest("hideParentCategory (default: false)", { - template: template(), + componentTest("hideParentCategory (default: false)", { + template: template(), - beforeEach() { - initCategories(this); - }, + beforeEach() { + initCategories(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const row = this.subject.rowByValue(this.category.id); - assert.equal(row.value(), this.category.id); - assert.equal(this.category.parent_category_id, null); - }, - }); + const row = this.subject.rowByValue(this.category.id); + assert.equal(row.value(), this.category.id); + assert.equal(this.category.parent_category_id, null); + }, + }); - componentTest("hideParentCategory (true)", { - template: template(["hideParentCategory=true"]), - - beforeEach() { - initCategoriesWithParentCategory(this); - }, - - async test(assert) { - await this.subject.expand(); - - const parentRow = this.subject.rowByValue(this.parentCategory.id); - assert.notOk(parentRow.exists(), "the parent row is not showing"); - - const childCategory = this.categories.firstObject; - const childCategoryId = childCategory.id; - const childRow = this.subject.rowByValue(childCategoryId); - assert.ok(childRow.exists(), "the child row is showing"); - - const $categoryStatus = childRow.el().find(".category-status"); - assert.ok($categoryStatus.text().trim().match(/^spec/)); - }, - }); - - componentTest("allow_uncategorized_topics (true)", { - template: template(), - - beforeEach() { - this.siteSettings.allow_uncategorized_topics = true; - initCategories(this); - }, - - async test(assert) { - await this.subject.expand(); - - const uncategorizedCategoryId = this.site.uncategorized_category_id; - const row = this.subject.rowByValue(uncategorizedCategoryId); - assert.ok(row.exists(), "the uncategorized row is showing"); - }, - }); - - componentTest("allow_uncategorized_topics (false)", { - template: template(), - - beforeEach() { - this.siteSettings.allow_uncategorized_topics = false; - initCategories(this); - }, - - async test(assert) { - await this.subject.expand(); - - const uncategorizedCategoryId = this.site.uncategorized_category_id; - const row = this.subject.rowByValue(uncategorizedCategoryId); - assert.notOk(row.exists(), "the uncategorized row is not showing"); - }, - }); - - componentTest("countSubcategories (default: false)", { - template: template(), - - beforeEach() { - initCategories(this); - }, - - async test(assert) { - await this.subject.expand(); - - const category = Category.findById(7); - const row = this.subject.rowByValue(category.id); - const topicCount = row.el().find(".topic-count").text().trim(); - - assert.equal( - topicCount, - "× 481", - "it doesn't include the topic count of subcategories" - ); - }, - }); - - componentTest("countSubcategories (true)", { - template: template(["countSubcategories=true"]), - - beforeEach() { - initCategories(this); - }, - - async test(assert) { - await this.subject.expand(); - - const category = Category.findById(7); - const row = this.subject.rowByValue(category.id); - const topicCount = row.el().find(".topic-count").text().trim(); - - assert.equal( - topicCount, - "× 584", - "it includes the topic count of subcategories" - ); - }, - }); - - componentTest("shortcuts:default", { - template: template(), - - beforeEach() { - initCategories(this); - this.set("category", null); - }, - - async test(assert) { - await this.subject.expand(); - - assert.equal( - this.subject.rowByIndex(0).value(), - this.categories.firstObject.id, - "Shortcuts are not prepended when no category is selected" - ); - }, - }); - - componentTest("shortcuts:category is set", { - template: template(), - - beforeEach() { - initCategories(this); - }, - - async test(assert) { - await this.subject.expand(); - - assert.equal(this.subject.rowByIndex(0).value(), ALL_CATEGORIES_ID); - }, - }); - - componentTest("shortcuts with parentCategory/subCategory=true:default", { - template: template(["subCategory=true"]), - - beforeEach() { - initCategoriesWithParentCategory(this); - }, - - async test(assert) { - await this.subject.expand(); - - assert.equal(this.subject.rowByIndex(0).value(), NO_CATEGORIES_ID); - }, - }); - - componentTest( - "shortcuts with parentCategory/subCategory=true:category is selected", - { - template: template(["subCategory=true"]), + componentTest("hideParentCategory (true)", { + template: template(["hideParentCategory=true"]), beforeEach() { initCategoriesWithParentCategory(this); - this.set("category", this.categories.firstObject); + }, + + async test(assert) { + await this.subject.expand(); + + const parentRow = this.subject.rowByValue(this.parentCategory.id); + assert.notOk(parentRow.exists(), "the parent row is not showing"); + + const childCategory = this.categories.firstObject; + const childCategoryId = childCategory.id; + const childRow = this.subject.rowByValue(childCategoryId); + assert.ok(childRow.exists(), "the child row is showing"); + + const $categoryStatus = childRow.el().find(".category-status"); + assert.ok($categoryStatus.text().trim().match(/^spec/)); + }, + }); + + componentTest("allow_uncategorized_topics (true)", { + template: template(), + + beforeEach() { + this.siteSettings.allow_uncategorized_topics = true; + initCategories(this); + }, + + async test(assert) { + await this.subject.expand(); + + const uncategorizedCategoryId = this.site.uncategorized_category_id; + const row = this.subject.rowByValue(uncategorizedCategoryId); + assert.ok(row.exists(), "the uncategorized row is showing"); + }, + }); + + componentTest("allow_uncategorized_topics (false)", { + template: template(), + + beforeEach() { + this.siteSettings.allow_uncategorized_topics = false; + initCategories(this); + }, + + async test(assert) { + await this.subject.expand(); + + const uncategorizedCategoryId = this.site.uncategorized_category_id; + const row = this.subject.rowByValue(uncategorizedCategoryId); + assert.notOk(row.exists(), "the uncategorized row is not showing"); + }, + }); + + componentTest("countSubcategories (default: false)", { + template: template(), + + beforeEach() { + initCategories(this); + }, + + async test(assert) { + await this.subject.expand(); + + const category = Category.findById(7); + const row = this.subject.rowByValue(category.id); + const topicCount = row.el().find(".topic-count").text().trim(); + + assert.equal( + topicCount, + "× 481", + "it doesn't include the topic count of subcategories" + ); + }, + }); + + componentTest("countSubcategories (true)", { + template: template(["countSubcategories=true"]), + + beforeEach() { + initCategories(this); + }, + + async test(assert) { + await this.subject.expand(); + + const category = Category.findById(7); + const row = this.subject.rowByValue(category.id); + const topicCount = row.el().find(".topic-count").text().trim(); + + assert.equal( + topicCount, + "× 584", + "it includes the topic count of subcategories" + ); + }, + }); + + componentTest("shortcuts:default", { + template: template(), + + beforeEach() { + initCategories(this); + this.set("category", null); + }, + + async test(assert) { + await this.subject.expand(); + + assert.equal( + this.subject.rowByIndex(0).value(), + this.categories.firstObject.id, + "Shortcuts are not prepended when no category is selected" + ); + }, + }); + + componentTest("shortcuts:category is set", { + template: template(), + + beforeEach() { + initCategories(this); }, async test(assert) { await this.subject.expand(); assert.equal(this.subject.rowByIndex(0).value(), ALL_CATEGORIES_ID); - assert.equal(this.subject.rowByIndex(1).value(), NO_CATEGORIES_ID); }, - } - ); + }); - componentTest("category url", { - template: template(), + componentTest("shortcuts with parentCategory/subCategory=true:default", { + template: template(["subCategory=true"]), - beforeEach() { - initCategoriesWithParentCategory(this); - sinon.stub(DiscourseURL, "routeTo"); - }, + beforeEach() { + initCategoriesWithParentCategory(this); + }, - async test(assert) { - await this.subject.expand(); - await this.subject.selectRowByValue(26); + async test(assert) { + await this.subject.expand(); - assert.ok( - DiscourseURL.routeTo.calledWith("/c/feature/spec/26"), - "it builds a correct URL" - ); - }, - }); -}); + assert.equal(this.subject.rowByIndex(0).value(), NO_CATEGORIES_ID); + }, + }); + + componentTest( + "shortcuts with parentCategory/subCategory=true:category is selected", + { + template: template(["subCategory=true"]), + + beforeEach() { + initCategoriesWithParentCategory(this); + this.set("category", this.categories.firstObject); + }, + + async test(assert) { + await this.subject.expand(); + + assert.equal(this.subject.rowByIndex(0).value(), ALL_CATEGORIES_ID); + assert.equal(this.subject.rowByIndex(1).value(), NO_CATEGORIES_ID); + }, + } + ); + + componentTest("category url", { + template: template(), + + beforeEach() { + initCategoriesWithParentCategory(this); + sinon.stub(DiscourseURL, "routeTo"); + }, + + async test(assert) { + await this.subject.expand(); + await this.subject.selectRowByValue(26); + + assert.ok( + DiscourseURL.routeTo.calledWith("/c/feature/spec/26"), + "it builds a correct URL" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/combo-box-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/combo-box-test.js index fbd9e4cc03d..67176a1818a 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/combo-box-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/combo-box-test.js @@ -24,17 +24,17 @@ const setDefaultState = (ctx, options) => { ctx.setProperties(properties); }; -discourseModule("Integration | Component | select-kit/combo-box", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/combo-box", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("options.clearable", { - template: ` + componentTest("options.clearable", { + template: ` {{combo-box value=value content=content @@ -43,36 +43,36 @@ discourseModule("Integration | Component | select-kit/combo-box", function ( }} `, - beforeEach() { - setDefaultState(this, { - clearable: true, - onChange: (value) => { - this.set("value", value); - }, - }); - }, + beforeEach() { + setDefaultState(this, { + clearable: true, + onChange: (value) => { + this.set("value", value); + }, + }); + }, - async test(assert) { - const $header = this.subject.header(); + async test(assert) { + const $header = this.subject.header(); - assert.ok( - exists($header.el().find(".btn-clear")), - "it shows the clear button" - ); - assert.equal($header.value(), DEFAULT_VALUE); + assert.ok( + exists($header.el().find(".btn-clear")), + "it shows the clear button" + ); + assert.equal($header.value(), DEFAULT_VALUE); - await click($header.el().find(".btn-clear")); + await click($header.el().find(".btn-clear")); - assert.notOk( - exists($header.el().find(".btn-clear")), - "it hides the clear button" - ); - assert.equal($header.value(), null); - }, - }); + assert.notOk( + exists($header.el().find(".btn-clear")), + "it hides the clear button" + ); + assert.equal($header.value(), null); + }, + }); - componentTest("options.{caretUpIcon,caretDownIcon}", { - template: ` + componentTest("options.{caretUpIcon,caretDownIcon}", { + template: ` {{combo-box value=value content=content @@ -83,27 +83,28 @@ discourseModule("Integration | Component | select-kit/combo-box", function ( }} `, - beforeEach() { - setDefaultState(this, { - caretUpIcon: "pencil-alt", - caretDownIcon: "trash-alt", - }); - }, + beforeEach() { + setDefaultState(this, { + caretUpIcon: "pencil-alt", + caretDownIcon: "trash-alt", + }); + }, - async test(assert) { - const $header = this.subject.header().el(); + async test(assert) { + const $header = this.subject.header().el(); - assert.ok( - exists($header.find(`.d-icon-${this.caretDownIcon}`)), - "it uses the icon provided" - ); + assert.ok( + exists($header.find(`.d-icon-${this.caretDownIcon}`)), + "it uses the icon provided" + ); - await this.subject.expand(); + await this.subject.expand(); - assert.ok( - exists($header.find(`.d-icon-${this.caretUpIcon}`)), - "it uses the icon provided" - ); - }, - }); -}); + assert.ok( + exists($header.find(`.d-icon-${this.caretUpIcon}`)), + "it uses the icon provided" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/list-setting-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/list-setting-test.js index d7dfbe6a3f5..0999e83e381 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/list-setting-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/list-setting-test.js @@ -16,31 +16,32 @@ function template(options = []) { `; } -discourseModule("Integration | Component | select-kit/list-setting", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/list-setting", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("default", { - template: template(), + componentTest("default", { + template: template(), - beforeEach() { - this.set("value", ["bold", "italic"]); - this.set("choices", ["bold", "italic", "underline"]); - }, + beforeEach() { + this.set("value", ["bold", "italic"]); + this.set("choices", ["bold", "italic", "underline"]); + }, - async test(assert) { - assert.equal(this.subject.header().name(), "bold,italic"); - assert.equal(this.subject.header().value(), "bold,italic"); + async test(assert) { + assert.equal(this.subject.header().name(), "bold,italic"); + assert.equal(this.subject.header().value(), "bold,italic"); - await this.subject.expand(); + await this.subject.expand(); - assert.equal(this.subject.rows().length, 1); - assert.equal(this.subject.rowByIndex(0).value(), "underline"); - }, - }); -}); + assert.equal(this.subject.rows().length, 1); + assert.equal(this.subject.rowByIndex(0).value(), "underline"); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js index 503966d994b..38c934338dc 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js @@ -33,42 +33,43 @@ const setDefaultState = (ctx, options) => { ctx.setProperties(properties); }; -discourseModule("Integration | Component | select-kit/multi-select", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/multi-select", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("content", { - template: template(), + componentTest("content", { + template: template(), - beforeEach() { - setDefaultState(this); - }, + beforeEach() { + setDefaultState(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const content = this.subject.displayedContent(); - assert.equal(content.length, 3, "it shows rows"); - assert.equal( - content[0].name, - this.content.firstObject.name, - "it has the correct name" - ); - assert.equal( - content[0].id, - this.content.firstObject.id, - "it has the correct value" - ); - assert.equal( - this.subject.header().value(), - null, - "it doesn't set a value from the content" - ); - }, - }); -}); + const content = this.subject.displayedContent(); + assert.equal(content.length, 3, "it shows rows"); + assert.equal( + content[0].name, + this.content.firstObject.name, + "it has the correct name" + ); + assert.equal( + content[0].id, + this.content.firstObject.id, + "it has the correct value" + ); + assert.equal( + this.subject.header().value(), + null, + "it doesn't set a value from the content" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js index ac9c4ee1b63..8deb9d73d6c 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js @@ -44,103 +44,106 @@ const setDefaultState = (ctx, options) => { ctx.setProperties(properties); }; -discourseModule("Integration | Component | select-kit/single-select", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/single-select", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("content", { - template: "{{single-select content=content}}", + componentTest("content", { + template: "{{single-select content=content}}", - beforeEach() { - setDefaultState(this); - }, + beforeEach() { + setDefaultState(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const content = this.subject.displayedContent(); - assert.equal(content.length, 3, "it shows rows"); - assert.equal( - content[0].name, - this.content.firstObject.name, - "it has the correct name" - ); - assert.equal( - content[0].id, - this.content.firstObject.id, - "it has the correct value" - ); - assert.equal( - this.subject.header().value(), - null, - "it doesn't set a value from the content" - ); - }, - }); + const content = this.subject.displayedContent(); + assert.equal(content.length, 3, "it shows rows"); + assert.equal( + content[0].name, + this.content.firstObject.name, + "it has the correct name" + ); + assert.equal( + content[0].id, + this.content.firstObject.id, + "it has the correct value" + ); + assert.equal( + this.subject.header().value(), + null, + "it doesn't set a value from the content" + ); + }, + }); - componentTest("value", { - template: template(), + componentTest("value", { + template: template(), - beforeEach() { - setDefaultState(this); - }, + beforeEach() { + setDefaultState(this); + }, - test(assert) { - assert.equal( - this.subject.header().value(this.content), - 1, - "it selects the correct content to display" - ); - }, - }); + test(assert) { + assert.equal( + this.subject.header().value(this.content), + 1, + "it selects the correct content to display" + ); + }, + }); - componentTest("options.filterable", { - template: template(["filterable=filterable"]), + componentTest("options.filterable", { + template: template(["filterable=filterable"]), - beforeEach() { - setDefaultState(this, { filterable: true }); - }, + beforeEach() { + setDefaultState(this, { filterable: true }); + }, - async test(assert) { - await this.subject.expand(); - assert.ok(this.subject.filter().exists(), "it shows the filter"); + async test(assert) { + await this.subject.expand(); + assert.ok(this.subject.filter().exists(), "it shows the filter"); - const filter = this.subject.displayedContent()[1].name; - await this.subject.fillInFilter(filter); - assert.equal( - this.subject.displayedContent()[0].name, - filter, - "it filters the list" - ); - }, - }); + const filter = this.subject.displayedContent()[1].name; + await this.subject.fillInFilter(filter); + assert.equal( + this.subject.displayedContent()[0].name, + filter, + "it filters the list" + ); + }, + }); - componentTest("options.limitMatches", { - template: template(["limitMatches=limitMatches", "filterable=filterable"]), + componentTest("options.limitMatches", { + template: template([ + "limitMatches=limitMatches", + "filterable=filterable", + ]), - beforeEach() { - setDefaultState(this, { limitMatches: 1, filterable: true }); - }, + beforeEach() { + setDefaultState(this, { limitMatches: 1, filterable: true }); + }, - async test(assert) { - await this.subject.expand(); - await this.subject.fillInFilter("ba"); + async test(assert) { + await this.subject.expand(); + await this.subject.fillInFilter("ba"); - assert.equal( - this.subject.displayedContent().length, - 1, - "it returns only 1 result" - ); - }, - }); + assert.equal( + this.subject.displayedContent().length, + 1, + "it returns only 1 result" + ); + }, + }); - componentTest("valueAttribute (deprecated)", { - template: ` + componentTest("valueAttribute (deprecated)", { + template: ` {{single-select value=value content=content @@ -148,200 +151,201 @@ discourseModule("Integration | Component | select-kit/single-select", function ( }} `, - beforeEach() { - this.set("value", "normal"); + beforeEach() { + this.set("value", "normal"); - const content = [ - { name: "Smallest", value: "smallest" }, - { name: "Smaller", value: "smaller" }, - { name: "Normal", value: "normal" }, - { name: "Larger", value: "larger" }, - { name: "Largest", value: "largest" }, - ]; - this.set("content", content); - }, + const content = [ + { name: "Smallest", value: "smallest" }, + { name: "Smaller", value: "smaller" }, + { name: "Normal", value: "normal" }, + { name: "Larger", value: "larger" }, + { name: "Largest", value: "largest" }, + ]; + this.set("content", content); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - assert.equal(this.subject.selectedRow().value(), this.value); - }, - }); + assert.equal(this.subject.selectedRow().value(), this.value); + }, + }); - componentTest("none:string", { - template: template(['none="test.none"']), + componentTest("none:string", { + template: template(['none="test.none"']), - beforeEach() { - I18n.translations[I18n.locale].js.test = { none: "(default)" }; - setDefaultState(this, { value: 1 }); - }, + beforeEach() { + I18n.translations[I18n.locale].js.test = { none: "(default)" }; + setDefaultState(this, { value: 1 }); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const noneRow = this.subject.rowByIndex(0); - assert.equal(noneRow.value(), null); - assert.equal(noneRow.name(), I18n.t("test.none")); - }, - }); + const noneRow = this.subject.rowByIndex(0); + assert.equal(noneRow.value(), null); + assert.equal(noneRow.name(), I18n.t("test.none")); + }, + }); - componentTest("none:object", { - template: template(["none=none"]), + componentTest("none:object", { + template: template(["none=none"]), - beforeEach() { - setDefaultState(this, { none: { value: null, name: "(default)" } }); - }, + beforeEach() { + setDefaultState(this, { none: { value: null, name: "(default)" } }); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const noneRow = this.subject.rowByIndex(0); - assert.equal(noneRow.value(), null); - assert.equal(noneRow.name(), "(default)"); - }, - }); + const noneRow = this.subject.rowByIndex(0); + assert.equal(noneRow.value(), null); + assert.equal(noneRow.name(), "(default)"); + }, + }); - componentTest("content is a basic array", { - template: template(['none="test.none"']), + componentTest("content is a basic array", { + template: template(['none="test.none"']), - beforeEach() { - I18n.translations[I18n.locale].js.test = { none: "(default)" }; - setDefaultState(this, { - nameProperty: null, - valueProperty: null, - value: "foo", - content: ["foo", "bar", "baz"], - }); - }, + beforeEach() { + I18n.translations[I18n.locale].js.test = { none: "(default)" }; + setDefaultState(this, { + nameProperty: null, + valueProperty: null, + value: "foo", + content: ["foo", "bar", "baz"], + }); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - const noneRow = this.subject.rowByIndex(0); - assert.equal(noneRow.value(), I18n.t("test.none")); - assert.equal(noneRow.name(), I18n.t("test.none")); - assert.equal(this.value, "foo"); + const noneRow = this.subject.rowByIndex(0); + assert.equal(noneRow.value(), I18n.t("test.none")); + assert.equal(noneRow.name(), I18n.t("test.none")); + assert.equal(this.value, "foo"); - await this.subject.selectRowByIndex(0); + await this.subject.selectRowByIndex(0); - assert.equal(this.value, null); - }, - }); + assert.equal(this.value, null); + }, + }); - componentTest("selected value can be 0", { - template: template(), + componentTest("selected value can be 0", { + template: template(), - beforeEach() { - setDefaultState(this, { - value: 1, - content: [ - { id: 0, name: "foo" }, - { id: 1, name: "bar" }, - ], - }); - }, + beforeEach() { + setDefaultState(this, { + value: 1, + content: [ + { id: 0, name: "foo" }, + { id: 1, name: "bar" }, + ], + }); + }, - async test(assert) { - assert.equal(this.subject.header().value(), 1); + async test(assert) { + assert.equal(this.subject.header().value(), 1); - await this.subject.expand(); - await this.subject.selectRowByValue(0); + await this.subject.expand(); + await this.subject.selectRowByValue(0); - assert.equal(this.subject.header().value(), 0); - }, - }); + assert.equal(this.subject.header().value(), 0); + }, + }); - componentTest("prevents propagating click event on header", { - template: - "{{#d-button icon='times' action=onClick}}{{single-select options=(hash preventsClickPropagation=true) value=value content=content}}{{/d-button}}", + componentTest("prevents propagating click event on header", { + template: + "{{#d-button icon='times' action=onClick}}{{single-select options=(hash preventsClickPropagation=true) value=value content=content}}{{/d-button}}", - beforeEach() { - this.setProperties({ - onClick: () => this.set("value", "foo"), - content: DEFAULT_CONTENT, - value: DEFAULT_VALUE, - }); - }, + beforeEach() { + this.setProperties({ + onClick: () => this.set("value", "foo"), + content: DEFAULT_CONTENT, + value: DEFAULT_VALUE, + }); + }, - async test(assert) { - assert.equal(this.value, DEFAULT_VALUE); - await this.subject.expand(); - assert.equal(this.value, DEFAULT_VALUE); - }, - }); + async test(assert) { + assert.equal(this.value, DEFAULT_VALUE); + await this.subject.expand(); + assert.equal(this.value, DEFAULT_VALUE); + }, + }); - componentTest("labelProperty", { - template: - '{{single-select labelProperty="foo" value=value content=content}}', + componentTest("labelProperty", { + template: + '{{single-select labelProperty="foo" value=value content=content}}', - beforeEach() { - this.setProperties({ - content: [{ id: 1, name: "john", foo: "JACKSON" }], - value: 1, - }); - }, + beforeEach() { + this.setProperties({ + content: [{ id: 1, name: "john", foo: "JACKSON" }], + value: 1, + }); + }, - async test(assert) { - assert.equal(this.subject.header().label(), "JACKSON"); + async test(assert) { + assert.equal(this.subject.header().label(), "JACKSON"); - await this.subject.expand(); + await this.subject.expand(); - const row = this.subject.rowByValue(1); + const row = this.subject.rowByValue(1); - assert.equal(row.label(), "JACKSON"); - }, - }); + assert.equal(row.label(), "JACKSON"); + }, + }); - componentTest("titleProperty", { - template: - '{{single-select titleProperty="foo" value=value content=content}}', + componentTest("titleProperty", { + template: + '{{single-select titleProperty="foo" value=value content=content}}', - beforeEach() { - this.setProperties({ - content: [{ id: 1, name: "john", foo: "JACKSON" }], - value: 1, - }); - }, + beforeEach() { + this.setProperties({ + content: [{ id: 1, name: "john", foo: "JACKSON" }], + value: 1, + }); + }, - async test(assert) { - assert.equal(this.subject.header().title(), "JACKSON"); + async test(assert) { + assert.equal(this.subject.header().title(), "JACKSON"); - await this.subject.expand(); + await this.subject.expand(); - const row = this.subject.rowByValue(1); + const row = this.subject.rowByValue(1); - assert.equal(row.title(), "JACKSON"); - }, - }); + assert.equal(row.title(), "JACKSON"); + }, + }); - componentTest("langProperty", { - template: - '{{single-select langProperty="foo" value=value content=content}}', + componentTest("langProperty", { + template: + '{{single-select langProperty="foo" value=value content=content}}', - beforeEach() { - this.setProperties({ - content: [{ id: 1, name: "john", foo: "be" }], - value: null, - }); - }, + beforeEach() { + this.setProperties({ + content: [{ id: 1, name: "john", foo: "be" }], + value: null, + }); + }, - async test(assert) { - assert.equal( - this.subject.header().el()[0].querySelector(".selected-name").lang, - "" - ); + async test(assert) { + assert.equal( + this.subject.header().el()[0].querySelector(".selected-name").lang, + "" + ); - await this.subject.expand(); + await this.subject.expand(); - const row = this.subject.rowByValue(1); - assert.equal(row.el()[0].lang, "be"); + const row = this.subject.rowByValue(1); + assert.equal(row.el()[0].lang, "be"); - await this.subject.selectRowByValue(1); + await this.subject.selectRowByValue(1); - assert.equal( - this.subject.header().el()[0].querySelector(".selected-name").lang, - "be" - ); - }, - }); -}); + assert.equal( + this.subject.header().el()[0].querySelector(".selected-name").lang, + "be" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/tag-drop-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/tag-drop-test.js index 55df881fdf1..5b6ca63707d 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/tag-drop-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/tag-drop-test.js @@ -36,63 +36,64 @@ function template(options = []) { `; } -discourseModule("Integration | Component | select-kit/tag-drop", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/tag-drop", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); + hooks.beforeEach(function () { + this.set("subject", selectKit()); - const site = Site.current(); - set(site, "top_tags", ["jeff", "neil", "arpit", "régis"]); + const site = Site.current(); + set(site, "top_tags", ["jeff", "neil", "arpit", "régis"]); - const response = (object) => { - return [200, { "Content-Type": "application/json" }, object]; - }; + const response = (object) => { + return [200, { "Content-Type": "application/json" }, object]; + }; - pretender.get("/tags/filter/search", (params) => { - if (params.queryParams.q === "rég") { - return response({ - results: [{ id: "régis", text: "régis", count: 2, pm_count: 0 }], - }); - } else if (params.queryParams.q === "dav") { - return response({ - results: [{ id: "David", text: "David", count: 2, pm_count: 0 }], - }); - } + pretender.get("/tags/filter/search", (params) => { + if (params.queryParams.q === "rég") { + return response({ + results: [{ id: "régis", text: "régis", count: 2, pm_count: 0 }], + }); + } else if (params.queryParams.q === "dav") { + return response({ + results: [{ id: "David", text: "David", count: 2, pm_count: 0 }], + }); + } + }); }); - }); - componentTest("default", { - template: template(["tagId=tagId"]), + componentTest("default", { + template: template(["tagId=tagId"]), - beforeEach() { - initTags(this); - }, + beforeEach() { + initTags(this); + }, - async test(assert) { - await this.subject.expand(); + async test(assert) { + await this.subject.expand(); - assert.ok(true); - // const row = this.subject.rowByValue(this.category.id); - // assert.ok( - // exists(row.el().find(".category-desc")), - // "it shows category description for newcomers" - // ); + assert.ok(true); + // const row = this.subject.rowByValue(this.category.id); + // assert.ok( + // exists(row.el().find(".category-desc")), + // "it shows category description for newcomers" + // ); - const content = this.subject.displayedContent(); + const content = this.subject.displayedContent(); - assert.equal( - content[0].name, - I18n.t("tagging.selector_no_tags"), - "it has the translated label for no-tags" - ); - assert.equal( - content[1].name, - I18n.t("tagging.selector_all_tags"), - "it has the correct label for all-tags" - ); - }, - }); -}); + assert.equal( + content[0].name, + I18n.t("tagging.selector_no_tags"), + "it has the translated label for no-tags" + ); + assert.equal( + content[1].name, + I18n.t("tagging.selector_all_tags"), + "it has the correct label for all-tags" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/user-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/user-chooser-test.js index 8eae6bf75b2..7066ee74f16 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/user-chooser-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/user-chooser-test.js @@ -4,37 +4,38 @@ import componentTest, { import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; -discourseModule("Integration | Component | select-kit/user-chooser", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | select-kit/user-chooser", + function (hooks) { + setupRenderingTest(hooks); - hooks.beforeEach(function () { - this.set("subject", selectKit()); - }); + hooks.beforeEach(function () { + this.set("subject", selectKit()); + }); - componentTest("displays usernames", { - template: `{{user-chooser value=value}}`, + componentTest("displays usernames", { + template: `{{user-chooser value=value}}`, - beforeEach() { - this.set("value", ["bob", "martin"]); - }, + beforeEach() { + this.set("value", ["bob", "martin"]); + }, - async test(assert) { - assert.equal(this.subject.header().name(), "bob,martin"); - }, - }); + async test(assert) { + assert.equal(this.subject.header().name(), "bob,martin"); + }, + }); - componentTest("can remove a username", { - template: `{{user-chooser value=value}}`, + componentTest("can remove a username", { + template: `{{user-chooser value=value}}`, - beforeEach() { - this.set("value", ["bob", "martin"]); - }, + beforeEach() { + this.set("value", ["bob", "martin"]); + }, - async test(assert) { - await this.subject.deselectItem("bob"); - assert.equal(this.subject.header().name(), "martin"); - }, - }); -}); + async test(assert) { + await this.subject.deselectItem("bob"); + assert.equal(this.subject.header().name(), "martin"); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/actions-summary-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/actions-summary-test.js index 794c95338b7..9afee06d238 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/actions-summary-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/actions-summary-test.js @@ -6,29 +6,30 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; -discourseModule("Integration | Component | Widget | actions-summary", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | actions-summary", + function (hooks) { + setupRenderingTest(hooks); - componentTest("post deleted", { - template: '{{mount-widget widget="actions-summary" args=args}}', - beforeEach() { - this.set("args", { - deleted_at: "2016-01-01", - deletedByUsername: "eviltrout", - deletedByAvatarTemplate: "/images/avatar.png", - }); - }, - test(assert) { - assert.ok( - queryAll(".post-action .d-icon-far-trash-alt").length === 1, - "it has the deleted icon" - ); - assert.ok( - queryAll(".avatar[title=eviltrout]").length === 1, - "it has the deleted by avatar" - ); - }, - }); -}); + componentTest("post deleted", { + template: '{{mount-widget widget="actions-summary" args=args}}', + beforeEach() { + this.set("args", { + deleted_at: "2016-01-01", + deletedByUsername: "eviltrout", + deletedByAvatarTemplate: "/images/avatar.png", + }); + }, + test(assert) { + assert.ok( + queryAll(".post-action .d-icon-far-trash-alt").length === 1, + "it has the deleted icon" + ); + assert.ok( + queryAll(".avatar[title=eviltrout]").length === 1, + "it has the deleted by avatar" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/avatar-flair-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/avatar-flair-test.js index 49a11aa97d9..3267c811134 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/avatar-flair-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/avatar-flair-test.js @@ -6,41 +6,42 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; -discourseModule("Integration | Component | Widget | avatar-flair", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | avatar-flair", + function (hooks) { + setupRenderingTest(hooks); - componentTest("avatar flair with an icon", { - template: '{{mount-widget widget="avatar-flair" args=args}}', - beforeEach() { - this.set("args", { - primary_group_flair_url: "fa-bars", - primary_group_flair_bg_color: "CC0000", - primary_group_flair_color: "FFFFFF", - }); - }, - test(assert) { - assert.ok(queryAll(".avatar-flair").length, "it has the tag"); - assert.ok(queryAll("svg.d-icon-bars").length, "it has the svg icon"); - assert.equal( - queryAll(".avatar-flair").attr("style"), - "background-color: #CC0000; color: #FFFFFF; ", - "it has styles" - ); - }, - }); + componentTest("avatar flair with an icon", { + template: '{{mount-widget widget="avatar-flair" args=args}}', + beforeEach() { + this.set("args", { + primary_group_flair_url: "fa-bars", + primary_group_flair_bg_color: "CC0000", + primary_group_flair_color: "FFFFFF", + }); + }, + test(assert) { + assert.ok(queryAll(".avatar-flair").length, "it has the tag"); + assert.ok(queryAll("svg.d-icon-bars").length, "it has the svg icon"); + assert.equal( + queryAll(".avatar-flair").attr("style"), + "background-color: #CC0000; color: #FFFFFF; ", + "it has styles" + ); + }, + }); - componentTest("avatar flair with an image", { - template: '{{mount-widget widget="avatar-flair" args=args}}', - beforeEach() { - this.set("args", { - primary_group_flair_url: "/images/avatar.png", - }); - }, - test(assert) { - assert.ok(queryAll(".avatar-flair").length, "it has the tag"); - assert.ok(queryAll("svg").length === 0, "it does not have an svg icon"); - }, - }); -}); + componentTest("avatar flair with an image", { + template: '{{mount-widget widget="avatar-flair" args=args}}', + beforeEach() { + this.set("args", { + primary_group_flair_url: "/images/avatar.png", + }); + }, + test(assert) { + assert.ok(queryAll(".avatar-flair").length, "it has the tag"); + assert.ok(queryAll("svg").length === 0, "it does not have an svg icon"); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/hamburger-menu-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/hamburger-menu-test.js index 43638125ea7..8eb98821e80 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/hamburger-menu-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/hamburger-menu-test.js @@ -12,252 +12,256 @@ let mutedCategoryIds = []; let unreadCategoryIds = []; let categoriesByCount = []; -discourseModule("Integration | Component | Widget | hamburger-menu", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | hamburger-menu", + function (hooks) { + setupRenderingTest(hooks); - componentTest("prioritize faq", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("prioritize faq", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.siteSettings.faq_url = "http://example.com/faq"; - this.currentUser.set("read_faq", false); - }, + beforeEach() { + this.siteSettings.faq_url = "http://example.com/faq"; + this.currentUser.set("read_faq", false); + }, - test(assert) { - assert.ok(queryAll(".faq-priority").length); - assert.ok(!queryAll(".faq-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".faq-priority").length); + assert.ok(!queryAll(".faq-link").length); + }, + }); - componentTest("prioritize faq - user has read", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("prioritize faq - user has read", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.siteSettings.faq_url = "http://example.com/faq"; - this.currentUser.set("read_faq", true); - }, + beforeEach() { + this.siteSettings.faq_url = "http://example.com/faq"; + this.currentUser.set("read_faq", true); + }, - test(assert) { - assert.ok(!queryAll(".faq-priority").length); - assert.ok(queryAll(".faq-link").length); - }, - }); + test(assert) { + assert.ok(!queryAll(".faq-priority").length); + assert.ok(queryAll(".faq-link").length); + }, + }); - componentTest("staff menu - not staff", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("staff menu - not staff", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.currentUser.set("staff", false); - }, + beforeEach() { + this.currentUser.set("staff", false); + }, - test(assert) { - assert.ok(!queryAll(".admin-link").length); - }, - }); + test(assert) { + assert.ok(!queryAll(".admin-link").length); + }, + }); - componentTest("staff menu - moderator", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("staff menu - moderator", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.currentUser.set("moderator", true); - }, + beforeEach() { + this.currentUser.set("moderator", true); + }, - test(assert) { - assert.ok(queryAll(".admin-link").length); - assert.ok(queryAll(".review").length); - assert.ok(!queryAll(".settings-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".admin-link").length); + assert.ok(queryAll(".review").length); + assert.ok(!queryAll(".settings-link").length); + }, + }); - componentTest("staff menu - admin", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("staff menu - admin", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.currentUser.setProperties({ admin: true }); - }, + beforeEach() { + this.currentUser.setProperties({ admin: true }); + }, - test(assert) { - assert.ok(queryAll(".settings-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".settings-link").length); + }, + }); - componentTest("logged in links", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("logged in links", { + template: '{{mount-widget widget="hamburger-menu"}}', - test(assert) { - assert.ok(queryAll(".new-topics-link").length); - assert.ok(queryAll(".unread-topics-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".new-topics-link").length); + assert.ok(queryAll(".unread-topics-link").length); + }, + }); - componentTest("general links", { - template: '{{mount-widget widget="hamburger-menu"}}', - anonymous: true, + componentTest("general links", { + template: '{{mount-widget widget="hamburger-menu"}}', + anonymous: true, - test(assert) { - assert.ok(queryAll("li[class='']").length === 0); - assert.ok(queryAll(".latest-topics-link").length); - assert.ok(!queryAll(".new-topics-link").length); - assert.ok(!queryAll(".unread-topics-link").length); - assert.ok(queryAll(".top-topics-link").length); - assert.ok(queryAll(".badge-link").length); - assert.ok(queryAll(".category-link").length > 0); - }, - }); + test(assert) { + assert.ok(queryAll("li[class='']").length === 0); + assert.ok(queryAll(".latest-topics-link").length); + assert.ok(!queryAll(".new-topics-link").length); + assert.ok(!queryAll(".unread-topics-link").length); + assert.ok(queryAll(".top-topics-link").length); + assert.ok(queryAll(".badge-link").length); + assert.ok(queryAll(".category-link").length > 0); + }, + }); - let maxCategoriesToDisplay; + let maxCategoriesToDisplay; - componentTest("top categories - anonymous", { - template: '{{mount-widget widget="hamburger-menu"}}', - anonymous: true, + componentTest("top categories - anonymous", { + template: '{{mount-widget widget="hamburger-menu"}}', + anonymous: true, - beforeEach() { - this.siteSettings.header_dropdown_category_count = 8; - }, + beforeEach() { + this.siteSettings.header_dropdown_category_count = 8; + }, - test(assert) { - assert.equal(queryAll(".category-link").length, 8); - assert.equal( - queryAll(".category-link .category-name").text(), - this.site - .get("categoriesByCount") - .slice(0, 8) - .map((c) => c.name) - .join("") - ); - }, - }); + test(assert) { + assert.equal(queryAll(".category-link").length, 8); + assert.equal( + queryAll(".category-link .category-name").text(), + this.site + .get("categoriesByCount") + .slice(0, 8) + .map((c) => c.name) + .join("") + ); + }, + }); - componentTest("top categories - allow_uncategorized_topics", { - template: '{{mount-widget widget="hamburger-menu"}}', - anonymous: true, + componentTest("top categories - allow_uncategorized_topics", { + template: '{{mount-widget widget="hamburger-menu"}}', + anonymous: true, - beforeEach() { - this.siteSettings.allow_uncategorized_topics = false; - this.siteSettings.header_dropdown_category_count = 8; - }, + beforeEach() { + this.siteSettings.allow_uncategorized_topics = false; + this.siteSettings.header_dropdown_category_count = 8; + }, - test(assert) { - assert.equal(queryAll(".category-link").length, 8); - assert.equal( - queryAll(".category-link .category-name").text(), - this.site - .get("categoriesByCount") - .filter((c) => c.name !== "uncategorized") - .slice(0, 8) - .map((c) => c.name) - .join("") - ); - }, - }); + test(assert) { + assert.equal(queryAll(".category-link").length, 8); + assert.equal( + queryAll(".category-link .category-name").text(), + this.site + .get("categoriesByCount") + .filter((c) => c.name !== "uncategorized") + .slice(0, 8) + .map((c) => c.name) + .join("") + ); + }, + }); - componentTest("top categories", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("top categories", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.siteSettings.header_dropdown_category_count = 8; - maxCategoriesToDisplay = this.siteSettings.header_dropdown_category_count; - categoriesByCount = this.site.get("categoriesByCount").slice(); - categoriesByCount.every((c) => { - if (!topCategoryIds.includes(c.id)) { - if (mutedCategoryIds.length === 0) { - mutedCategoryIds.push(c.id); - c.set("notification_level", NotificationLevels.MUTED); - } else if (unreadCategoryIds.length === 0) { - unreadCategoryIds.push(c.id); - for (let i = 0; i < 5; i++) { - c.topicTrackingState.states["t123" + i] = { - category_id: c.id, - last_read_post_number: 1, - highest_post_number: 2, - notification_level: NotificationLevels.TRACKING, - }; + beforeEach() { + this.siteSettings.header_dropdown_category_count = 8; + maxCategoriesToDisplay = this.siteSettings + .header_dropdown_category_count; + categoriesByCount = this.site.get("categoriesByCount").slice(); + categoriesByCount.every((c) => { + if (!topCategoryIds.includes(c.id)) { + if (mutedCategoryIds.length === 0) { + mutedCategoryIds.push(c.id); + c.set("notification_level", NotificationLevels.MUTED); + } else if (unreadCategoryIds.length === 0) { + unreadCategoryIds.push(c.id); + for (let i = 0; i < 5; i++) { + c.topicTrackingState.states["t123" + i] = { + category_id: c.id, + last_read_post_number: 1, + highest_post_number: 2, + notification_level: NotificationLevels.TRACKING, + }; + } + } else { + unreadCategoryIds.splice(0, 0, c.id); + for (let i = 0; i < 10; i++) { + c.topicTrackingState.states["t321" + i] = { + category_id: c.id, + last_read_post_number: null, + }; + } + return false; } - } else { - unreadCategoryIds.splice(0, 0, c.id); - for (let i = 0; i < 10; i++) { - c.topicTrackingState.states["t321" + i] = { - category_id: c.id, - last_read_post_number: null, - }; - } - return false; } - } - return true; - }); - this.currentUser.set("top_category_ids", topCategoryIds); - }, + return true; + }); + this.currentUser.set("top_category_ids", topCategoryIds); + }, - test(assert) { - assert.equal(queryAll(".category-link").length, maxCategoriesToDisplay); + test(assert) { + assert.equal(queryAll(".category-link").length, maxCategoriesToDisplay); - categoriesByCount = categoriesByCount.filter( - (c) => !mutedCategoryIds.includes(c.id) - ); - let ids = [ - ...unreadCategoryIds, - ...topCategoryIds, - ...categoriesByCount.map((c) => c.id), - ] - .uniq() - .slice(0, maxCategoriesToDisplay); + categoriesByCount = categoriesByCount.filter( + (c) => !mutedCategoryIds.includes(c.id) + ); + let ids = [ + ...unreadCategoryIds, + ...topCategoryIds, + ...categoriesByCount.map((c) => c.id), + ] + .uniq() + .slice(0, maxCategoriesToDisplay); - assert.equal( - queryAll(".category-link .category-name").text(), - ids.map((i) => categoriesByCount.find((c) => c.id === i).name).join("") - ); - }, - }); + assert.equal( + queryAll(".category-link .category-name").text(), + ids + .map((i) => categoriesByCount.find((c) => c.id === i).name) + .join("") + ); + }, + }); - componentTest("badges link - disabled", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("badges link - disabled", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.siteSettings.enable_badges = false; - }, + beforeEach() { + this.siteSettings.enable_badges = false; + }, - test(assert) { - assert.ok(!queryAll(".badge-link").length); - }, - }); + test(assert) { + assert.ok(!queryAll(".badge-link").length); + }, + }); - componentTest("badges link", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("badges link", { + template: '{{mount-widget widget="hamburger-menu"}}', - test(assert) { - assert.ok(queryAll(".badge-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".badge-link").length); + }, + }); - componentTest("user directory link", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("user directory link", { + template: '{{mount-widget widget="hamburger-menu"}}', - test(assert) { - assert.ok(queryAll(".user-directory-link").length); - }, - }); + test(assert) { + assert.ok(queryAll(".user-directory-link").length); + }, + }); - componentTest("user directory link - disabled", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("user directory link - disabled", { + template: '{{mount-widget widget="hamburger-menu"}}', - beforeEach() { - this.siteSettings.enable_user_directory = false; - }, + beforeEach() { + this.siteSettings.enable_user_directory = false; + }, - test(assert) { - assert.ok(!queryAll(".user-directory-link").length); - }, - }); + test(assert) { + assert.ok(!queryAll(".user-directory-link").length); + }, + }); - componentTest("general links", { - template: '{{mount-widget widget="hamburger-menu"}}', + componentTest("general links", { + template: '{{mount-widget widget="hamburger-menu"}}', - test(assert) { - assert.ok(queryAll(".about-link").length); - assert.ok(queryAll(".keyboard-shortcuts-link").length); - }, - }); -}); + test(assert) { + assert.ok(queryAll(".about-link").length); + assert.ok(queryAll(".keyboard-shortcuts-link").length); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/home-logo-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/home-logo-test.js index bf5d3d36842..c9d2932549d 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/home-logo-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/home-logo-test.js @@ -14,240 +14,241 @@ const darkLogo = "/images/d-logo-sketch.png?dark"; const title = "Cool Forum"; const prefersDark = "(prefers-color-scheme: dark)"; -discourseModule("Integration | Component | Widget | home-logo", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | home-logo", + function (hooks) { + setupRenderingTest(hooks); - componentTest("basics", { - template: '{{mount-widget widget="home-logo" args=args}}', - skip: true, - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_small_url = smallLogo; - this.siteSettings.title = title; - this.set("args", { minimized: false }); - }, + componentTest("basics", { + template: '{{mount-widget widget="home-logo" args=args}}', + skip: true, + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_small_url = smallLogo; + this.siteSettings.title = title; + this.set("args", { minimized: false }); + }, - test(assert) { - assert.ok(queryAll(".title").length === 1); + test(assert) { + assert.ok(queryAll(".title").length === 1); - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), bigLogo); - assert.equal(queryAll("#site-logo").attr("alt"), title); - }, - }); + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), bigLogo); + assert.equal(queryAll("#site-logo").attr("alt"), title); + }, + }); - componentTest("basics - minimized", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_small_url = smallLogo; - this.siteSettings.title = title; - this.set("args", { minimized: true }); - }, + componentTest("basics - minimized", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_small_url = smallLogo; + this.siteSettings.title = title; + this.set("args", { minimized: true }); + }, - test(assert) { - assert.ok(queryAll("img.logo-small").length === 1); - assert.equal(queryAll("img.logo-small").attr("src"), smallLogo); - assert.equal(queryAll("img.logo-small").attr("alt"), title); - assert.equal(queryAll("img.logo-small").attr("width"), 36); - }, - }); + test(assert) { + assert.ok(queryAll("img.logo-small").length === 1); + assert.equal(queryAll("img.logo-small").attr("src"), smallLogo); + assert.equal(queryAll("img.logo-small").attr("alt"), title); + assert.equal(queryAll("img.logo-small").attr("width"), 36); + }, + }); - componentTest("no logo", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = ""; - this.siteSettings.site_logo_small_url = ""; - this.siteSettings.title = title; - this.set("args", { minimized: false }); - }, + componentTest("no logo", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = ""; + this.siteSettings.site_logo_small_url = ""; + this.siteSettings.title = title; + this.set("args", { minimized: false }); + }, - test(assert) { - assert.ok(queryAll("h1#site-text-logo.text-logo").length === 1); - assert.equal(queryAll("#site-text-logo").text(), title); - }, - }); + test(assert) { + assert.ok(queryAll("h1#site-text-logo.text-logo").length === 1); + assert.equal(queryAll("#site-text-logo").text(), title); + }, + }); - componentTest("no logo - minimized", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = ""; - this.siteSettings.site_logo_small_url = ""; - this.siteSettings.title = title; - this.set("args", { minimized: true }); - }, + componentTest("no logo - minimized", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = ""; + this.siteSettings.site_logo_small_url = ""; + this.siteSettings.title = title; + this.set("args", { minimized: true }); + }, - test(assert) { - assert.ok(queryAll(".d-icon-home").length === 1); - }, - }); + test(assert) { + assert.ok(queryAll(".d-icon-home").length === 1); + }, + }); - componentTest("mobile logo", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_mobile_logo_url = mobileLogo; - this.siteSettings.site_logo_small_url = smallLogo; - this.site.mobileView = true; - }, + componentTest("mobile logo", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_mobile_logo_url = mobileLogo; + this.siteSettings.site_logo_small_url = smallLogo; + this.site.mobileView = true; + }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-mobile").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), mobileLogo); - }, - }); + test(assert) { + assert.ok(queryAll("img#site-logo.logo-mobile").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), mobileLogo); + }, + }); - componentTest("mobile without logo", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.site.mobileView = true; - }, + componentTest("mobile without logo", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.site.mobileView = true; + }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), bigLogo); - }, - }); + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), bigLogo); + }, + }); - componentTest("logo with dark mode alternative", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_dark_url = darkLogo; - Session.currentProp("darkModeAvailable", true); - }, - afterEach() { - Session.currentProp("darkModeAvailable", null); - }, + componentTest("logo with dark mode alternative", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_dark_url = darkLogo; + Session.currentProp("darkModeAvailable", true); + }, + afterEach() { + Session.currentProp("darkModeAvailable", null); + }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), bigLogo); + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), bigLogo); - assert.equal( - queryAll("picture source").attr("media"), - prefersDark, - "includes dark mode media attribute" - ); - assert.equal( - queryAll("picture source").attr("srcset"), - darkLogo, - "includes dark mode alternative logo source" - ); - }, - }); + assert.equal( + queryAll("picture source").attr("media"), + prefersDark, + "includes dark mode media attribute" + ); + assert.equal( + queryAll("picture source").attr("srcset"), + darkLogo, + "includes dark mode alternative logo source" + ); + }, + }); - componentTest("mobile logo with dark mode alternative", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_mobile_logo_url = mobileLogo; - this.siteSettings.site_mobile_logo_dark_url = darkLogo; - Session.currentProp("darkModeAvailable", true); + componentTest("mobile logo with dark mode alternative", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_mobile_logo_url = mobileLogo; + this.siteSettings.site_mobile_logo_dark_url = darkLogo; + Session.currentProp("darkModeAvailable", true); - this.site.mobileView = true; - }, - afterEach() { - Session.currentProp("darkModeAvailable", null); - }, + this.site.mobileView = true; + }, + afterEach() { + Session.currentProp("darkModeAvailable", null); + }, - test(assert) { - assert.equal(queryAll("#site-logo").attr("src"), mobileLogo); + test(assert) { + assert.equal(queryAll("#site-logo").attr("src"), mobileLogo); - assert.equal( - queryAll("picture source").attr("media"), - prefersDark, - "includes dark mode media attribute" - ); - assert.equal( - queryAll("picture source").attr("srcset"), - darkLogo, - "includes dark mode alternative logo source" - ); - }, - }); + assert.equal( + queryAll("picture source").attr("media"), + prefersDark, + "includes dark mode media attribute" + ); + assert.equal( + queryAll("picture source").attr("srcset"), + darkLogo, + "includes dark mode alternative logo source" + ); + }, + }); - componentTest("dark mode enabled but no dark logo set", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_dark_url = ""; - Session.currentProp("darkModeAvailable", true); - }, - afterEach() { - Session.currentProp("darkModeAvailable", null); - }, + componentTest("dark mode enabled but no dark logo set", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_dark_url = ""; + Session.currentProp("darkModeAvailable", true); + }, + afterEach() { + Session.currentProp("darkModeAvailable", null); + }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), bigLogo); - assert.ok( - queryAll("picture").length === 0, - "does not include alternative logo" - ); - }, - }); + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), bigLogo); + assert.ok( + queryAll("picture").length === 0, + "does not include alternative logo" + ); + }, + }); - componentTest("dark logo set but no dark mode", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_dark_url = darkLogo; - }, + componentTest("dark logo set but no dark mode", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_dark_url = darkLogo; + }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal(queryAll("#site-logo").attr("src"), bigLogo); - assert.ok( - queryAll("picture").length === 0, - "does not include alternative logo" - ); - }, - }); + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal(queryAll("#site-logo").attr("src"), bigLogo); + assert.ok( + queryAll("picture").length === 0, + "does not include alternative logo" + ); + }, + }); - componentTest("dark color scheme and dark logo set", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_dark_url = darkLogo; - Session.currentProp("defaultColorSchemeIsDark", true); - }, - afterEach() { - Session.currentProp("defaultColorSchemeIsDark", null); - }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal( - queryAll("#site-logo").attr("src"), - darkLogo, - "uses dark logo" - ); - assert.ok( - queryAll("picture").length === 0, - "does not add dark mode alternative" - ); - }, - }); + componentTest("dark color scheme and dark logo set", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_dark_url = darkLogo; + Session.currentProp("defaultColorSchemeIsDark", true); + }, + afterEach() { + Session.currentProp("defaultColorSchemeIsDark", null); + }, + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal( + queryAll("#site-logo").attr("src"), + darkLogo, + "uses dark logo" + ); + assert.ok( + queryAll("picture").length === 0, + "does not add dark mode alternative" + ); + }, + }); - componentTest("dark color scheme and dark logo not set", { - template: '{{mount-widget widget="home-logo" args=args}}', - beforeEach() { - this.siteSettings.site_logo_url = bigLogo; - this.siteSettings.site_logo_dark_url = ""; - Session.currentProp("defaultColorSchemeIsDark", true); - }, - afterEach() { - Session.currentProp("defaultColorSchemeIsDark", null); - }, - test(assert) { - assert.ok(queryAll("img#site-logo.logo-big").length === 1); - assert.equal( - queryAll("#site-logo").attr("src"), - bigLogo, - "uses regular logo on dark scheme if no dark logo" - ); - }, - }); -}); + componentTest("dark color scheme and dark logo not set", { + template: '{{mount-widget widget="home-logo" args=args}}', + beforeEach() { + this.siteSettings.site_logo_url = bigLogo; + this.siteSettings.site_logo_dark_url = ""; + Session.currentProp("defaultColorSchemeIsDark", true); + }, + afterEach() { + Session.currentProp("defaultColorSchemeIsDark", null); + }, + test(assert) { + assert.ok(queryAll("img#site-logo.logo-big").length === 1); + assert.equal( + queryAll("#site-logo").attr("src"), + bigLogo, + "uses regular logo on dark scheme if no dark logo" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/post-links-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/post-links-test.js index 6a24877b12c..e8287519c84 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/post-links-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-links-test.js @@ -7,59 +7,91 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import { click } from "@ember/test-helpers"; -discourseModule("Integration | Component | Widget | post-links", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | post-links", + function (hooks) { + setupRenderingTest(hooks); - componentTest("duplicate links", { - template: '{{mount-widget widget="post-links" args=args}}', - beforeEach() { - this.set("args", { - id: 2, - links: [ - { - title: "Evil Trout Link", - url: "http://eviltrout.com", - reflection: true, - }, - { - title: "Evil Trout Link", - url: "http://dupe.eviltrout.com", - reflection: true, - }, - ], - }); - }, - test(assert) { - assert.equal( - queryAll(".post-links a.track-link").length, - 1, - "it hides the dupe link" - ); - }, - }); + componentTest("duplicate links", { + template: '{{mount-widget widget="post-links" args=args}}', + beforeEach() { + this.set("args", { + id: 2, + links: [ + { + title: "Evil Trout Link", + url: "http://eviltrout.com", + reflection: true, + }, + { + title: "Evil Trout Link", + url: "http://dupe.eviltrout.com", + reflection: true, + }, + ], + }); + }, + test(assert) { + assert.equal( + queryAll(".post-links a.track-link").length, + 1, + "it hides the dupe link" + ); + }, + }); - componentTest("collapsed links", { - template: '{{mount-widget widget="post-links" args=args}}', - beforeEach() { - this.set("args", { - id: 1, - links: [ - { title: "Link 1", url: "http://eviltrout.com?1", reflection: true }, - { title: "Link 2", url: "http://eviltrout.com?2", reflection: true }, - { title: "Link 3", url: "http://eviltrout.com?3", reflection: true }, - { title: "Link 4", url: "http://eviltrout.com?4", reflection: true }, - { title: "Link 5", url: "http://eviltrout.com?5", reflection: true }, - { title: "Link 6", url: "http://eviltrout.com?6", reflection: true }, - { title: "Link 7", url: "http://eviltrout.com?7", reflection: true }, - ], - }); - }, - async test(assert) { - assert.ok(queryAll(".expand-links").length === 1, "collapsed by default"); - await click("a.expand-links"); - assert.equal(queryAll(".post-links a.track-link").length, 7); - }, - }); -}); + componentTest("collapsed links", { + template: '{{mount-widget widget="post-links" args=args}}', + beforeEach() { + this.set("args", { + id: 1, + links: [ + { + title: "Link 1", + url: "http://eviltrout.com?1", + reflection: true, + }, + { + title: "Link 2", + url: "http://eviltrout.com?2", + reflection: true, + }, + { + title: "Link 3", + url: "http://eviltrout.com?3", + reflection: true, + }, + { + title: "Link 4", + url: "http://eviltrout.com?4", + reflection: true, + }, + { + title: "Link 5", + url: "http://eviltrout.com?5", + reflection: true, + }, + { + title: "Link 6", + url: "http://eviltrout.com?6", + reflection: true, + }, + { + title: "Link 7", + url: "http://eviltrout.com?7", + reflection: true, + }, + ], + }); + }, + async test(assert) { + assert.ok( + queryAll(".expand-links").length === 1, + "collapsed by default" + ); + await click("a.expand-links"); + assert.equal(queryAll(".post-links a.track-link").length, 7); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/post-menu-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/post-menu-test.js index a497cae817e..53f10c31fe9 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/post-menu-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-menu-test.js @@ -7,48 +7,49 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import { withPluginApi } from "discourse/lib/plugin-api"; -discourseModule("Integration | Component | Widget | post-menu", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | post-menu", + function (hooks) { + setupRenderingTest(hooks); - componentTest("add extra button", { - template: '{{mount-widget widget="post-menu" args=args}}', - beforeEach() { - this.set("args", {}); - withPluginApi("0.8", (api) => { - api.addPostMenuButton("coffee", () => { - return { - action: "drinkCoffee", - icon: "coffee", - className: "hot-coffee", - title: "coffee.title", - position: "first", - }; + componentTest("add extra button", { + template: '{{mount-widget widget="post-menu" args=args}}', + beforeEach() { + this.set("args", {}); + withPluginApi("0.8", (api) => { + api.addPostMenuButton("coffee", () => { + return { + action: "drinkCoffee", + icon: "coffee", + className: "hot-coffee", + title: "coffee.title", + position: "first", + }; + }); }); - }); - }, - async test(assert) { - assert.ok( - queryAll(".actions .extra-buttons .hot-coffee").length === 1, - "It renders extra button" - ); - }, - }); + }, + async test(assert) { + assert.ok( + queryAll(".actions .extra-buttons .hot-coffee").length === 1, + "It renders extra button" + ); + }, + }); - componentTest("remove extra button", { - template: '{{mount-widget widget="post-menu" args=args}}', - beforeEach() { - this.set("args", {}); - withPluginApi("0.8", (api) => { - api.removePostMenuButton("coffee"); - }); - }, - async test(assert) { - assert.ok( - queryAll(".actions .extra-buttons .hot-coffee").length === 0, - "It doesn't removes coffee button" - ); - }, - }); -}); + componentTest("remove extra button", { + template: '{{mount-widget widget="post-menu" args=args}}', + beforeEach() { + this.set("args", {}); + withPluginApi("0.8", (api) => { + api.removePostMenuButton("coffee"); + }); + }, + async test(assert) { + assert.ok( + queryAll(".actions .extra-buttons .hot-coffee").length === 0, + "It doesn't removes coffee button" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/post-stream-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/post-stream-test.js index 5d4ce3ff92c..1005000f04b 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/post-stream-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-stream-test.js @@ -21,136 +21,137 @@ function postStreamTest(name, attrs) { }); } -discourseModule("Integration | Component | Widget | post-stream", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | post-stream", + function (hooks) { + setupRenderingTest(hooks); - postStreamTest("basics", { - posts() { - const site = this.container.lookup("site:main"); - const topic = Topic.create(); - topic.set("details.created_by", { id: 123 }); - return [ - Post.create({ - topic, - id: 1, - post_number: 1, - user_id: 123, - primary_group_name: "trout", - avatar_template: "/images/avatar.png", - }), - Post.create({ - topic, - id: 2, - post_number: 2, - post_type: site.get("post_types.moderator_action"), - }), - Post.create({ topic, id: 3, post_number: 3, hidden: true }), - Post.create({ - topic, - id: 4, - post_number: 4, - post_type: site.get("post_types.whisper"), - }), - Post.create({ - topic, - id: 5, - post_number: 5, - wiki: true, - via_email: true, - }), - Post.create({ - topic, - id: 6, - post_number: 6, - via_email: true, - is_auto_generated: true, - }), - ]; - }, + postStreamTest("basics", { + posts() { + const site = this.container.lookup("site:main"); + const topic = Topic.create(); + topic.set("details.created_by", { id: 123 }); + return [ + Post.create({ + topic, + id: 1, + post_number: 1, + user_id: 123, + primary_group_name: "trout", + avatar_template: "/images/avatar.png", + }), + Post.create({ + topic, + id: 2, + post_number: 2, + post_type: site.get("post_types.moderator_action"), + }), + Post.create({ topic, id: 3, post_number: 3, hidden: true }), + Post.create({ + topic, + id: 4, + post_number: 4, + post_type: site.get("post_types.whisper"), + }), + Post.create({ + topic, + id: 5, + post_number: 5, + wiki: true, + via_email: true, + }), + Post.create({ + topic, + id: 6, + post_number: 6, + via_email: true, + is_auto_generated: true, + }), + ]; + }, - test(assert) { - assert.equal(queryAll(".post-stream").length, 1); - assert.equal(queryAll(".topic-post").length, 6, "renders all posts"); + test(assert) { + assert.equal(queryAll(".post-stream").length, 1); + assert.equal(queryAll(".topic-post").length, 6, "renders all posts"); - // look for special class bindings - assert.equal( - queryAll(".topic-post:nth-of-type(1).topic-owner").length, - 1, - "it applies the topic owner class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(1).group-trout").length, - 1, - "it applies the primary group class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(1).regular").length, - 1, - "it applies the regular class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(2).moderator").length, - 1, - "it applies the moderator class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(3).post-hidden").length, - 1, - "it applies the hidden class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(4).whisper").length, - 1, - "it applies the whisper class" - ); - assert.equal( - queryAll(".topic-post:nth-of-type(5).wiki").length, - 1, - "it applies the wiki class" - ); + // look for special class bindings + assert.equal( + queryAll(".topic-post:nth-of-type(1).topic-owner").length, + 1, + "it applies the topic owner class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(1).group-trout").length, + 1, + "it applies the primary group class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(1).regular").length, + 1, + "it applies the regular class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(2).moderator").length, + 1, + "it applies the moderator class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(3).post-hidden").length, + 1, + "it applies the hidden class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(4).whisper").length, + 1, + "it applies the whisper class" + ); + assert.equal( + queryAll(".topic-post:nth-of-type(5).wiki").length, + 1, + "it applies the wiki class" + ); - // it renders an article for the body with appropriate attributes - assert.equal(queryAll("article#post_2").length, 1); - assert.equal(queryAll('article[data-user-id="123"]').length, 1); - assert.equal(queryAll('article[data-post-id="3"]').length, 1); - assert.equal(queryAll("article#post_5.via-email").length, 1); - assert.equal(queryAll("article#post_6.is-auto-generated").length, 1); + // it renders an article for the body with appropriate attributes + assert.equal(queryAll("article#post_2").length, 1); + assert.equal(queryAll('article[data-user-id="123"]').length, 1); + assert.equal(queryAll('article[data-post-id="3"]').length, 1); + assert.equal(queryAll("article#post_5.via-email").length, 1); + assert.equal(queryAll("article#post_6.is-auto-generated").length, 1); - assert.equal( - queryAll("article:nth-of-type(1) .main-avatar").length, - 1, - "renders the main avatar" - ); - }, - }); + assert.equal( + queryAll("article:nth-of-type(1) .main-avatar").length, + 1, + "renders the main avatar" + ); + }, + }); - postStreamTest("deleted posts", { - posts() { - const topic = Topic.create(); - topic.set("details.created_by", { id: 123 }); - return [ - Post.create({ - topic, - id: 1, - post_number: 1, - deleted_at: new Date().toString(), - }), - ]; - }, + postStreamTest("deleted posts", { + posts() { + const topic = Topic.create(); + topic.set("details.created_by", { id: 123 }); + return [ + Post.create({ + topic, + id: 1, + post_number: 1, + deleted_at: new Date().toString(), + }), + ]; + }, - test(assert) { - assert.equal( - queryAll(".topic-post.deleted").length, - 1, - "it applies the deleted class" - ); - assert.equal( - queryAll(".deleted-user-avatar").length, - 1, - "it has the trash avatar" - ); - }, - }); -}); + test(assert) { + assert.equal( + queryAll(".topic-post.deleted").length, + 1, + "it applies the deleted class" + ); + assert.equal( + queryAll(".deleted-user-avatar").length, + 1, + "it has the trash avatar" + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/poster-name-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/poster-name-test.js index 0c2a15ba768..725ba460602 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/poster-name-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/poster-name-test.js @@ -6,74 +6,75 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; -discourseModule("Integration | Component | Widget | poster-name", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | poster-name", + function (hooks) { + setupRenderingTest(hooks); - componentTest("basic rendering", { - template: '{{mount-widget widget="poster-name" args=args}}', - beforeEach() { - this.set("args", { - username: "eviltrout", - usernameUrl: "/u/eviltrout", - name: "Robin Ward", - user_title: "Trout Master", - }); - }, - test(assert) { - assert.ok(queryAll(".names").length); - assert.ok(queryAll("span.username").length); - assert.ok(queryAll('a[data-user-card="eviltrout"]').length); - assert.equal(queryAll(".username a").text(), "eviltrout"); - assert.equal(queryAll(".full-name a").text(), "Robin Ward"); - assert.equal(queryAll(".user-title").text(), "Trout Master"); - }, - }); + componentTest("basic rendering", { + template: '{{mount-widget widget="poster-name" args=args}}', + beforeEach() { + this.set("args", { + username: "eviltrout", + usernameUrl: "/u/eviltrout", + name: "Robin Ward", + user_title: "Trout Master", + }); + }, + test(assert) { + assert.ok(queryAll(".names").length); + assert.ok(queryAll("span.username").length); + assert.ok(queryAll('a[data-user-card="eviltrout"]').length); + assert.equal(queryAll(".username a").text(), "eviltrout"); + assert.equal(queryAll(".full-name a").text(), "Robin Ward"); + assert.equal(queryAll(".user-title").text(), "Trout Master"); + }, + }); - componentTest("extra classes and glyphs", { - template: '{{mount-widget widget="poster-name" args=args}}', - beforeEach() { - this.set("args", { - username: "eviltrout", - usernameUrl: "/u/eviltrout", - staff: true, - admin: true, - moderator: true, - new_user: true, - primary_group_name: "fish", - }); - }, - test(assert) { - assert.ok(queryAll("span.staff").length); - assert.ok(queryAll("span.admin").length); - assert.ok(queryAll("span.moderator").length); - assert.ok(queryAll(".d-icon-shield-alt").length); - assert.ok(queryAll("span.new-user").length); - assert.ok(queryAll("span.fish").length); - }, - }); + componentTest("extra classes and glyphs", { + template: '{{mount-widget widget="poster-name" args=args}}', + beforeEach() { + this.set("args", { + username: "eviltrout", + usernameUrl: "/u/eviltrout", + staff: true, + admin: true, + moderator: true, + new_user: true, + primary_group_name: "fish", + }); + }, + test(assert) { + assert.ok(queryAll("span.staff").length); + assert.ok(queryAll("span.admin").length); + assert.ok(queryAll("span.moderator").length); + assert.ok(queryAll(".d-icon-shield-alt").length); + assert.ok(queryAll("span.new-user").length); + assert.ok(queryAll("span.fish").length); + }, + }); - componentTest("disable display name on posts", { - template: '{{mount-widget widget="poster-name" args=args}}', - beforeEach() { - this.siteSettings.display_name_on_posts = false; - this.set("args", { username: "eviltrout", name: "Robin Ward" }); - }, - test(assert) { - assert.equal(queryAll(".full-name").length, 0); - }, - }); + componentTest("disable display name on posts", { + template: '{{mount-widget widget="poster-name" args=args}}', + beforeEach() { + this.siteSettings.display_name_on_posts = false; + this.set("args", { username: "eviltrout", name: "Robin Ward" }); + }, + test(assert) { + assert.equal(queryAll(".full-name").length, 0); + }, + }); - componentTest("doesn't render a name if it's similar to the username", { - template: '{{mount-widget widget="poster-name" args=args}}', - beforeEach() { - this.siteSettings.prioritize_username_in_ux = true; - this.siteSettings.display_name_on_posts = true; - this.set("args", { username: "eviltrout", name: "evil-trout" }); - }, - test(assert) { - assert.equal(queryAll(".second").length, 0); - }, - }); -}); + componentTest("doesn't render a name if it's similar to the username", { + template: '{{mount-widget widget="poster-name" args=args}}', + beforeEach() { + this.siteSettings.prioritize_username_in_ux = true; + this.siteSettings.display_name_on_posts = true; + this.set("args", { username: "eviltrout", name: "evil-trout" }); + }, + test(assert) { + assert.equal(queryAll(".second").length, 0); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/small-user-list-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/small-user-list-test.js index 20ae8b1206e..95316703f72 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/small-user-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/small-user-list-test.js @@ -6,25 +6,26 @@ import { queryAll, } from "discourse/tests/helpers/qunit-helpers"; -discourseModule("Integration | Component | Widget | small-user-list", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | small-user-list", + function (hooks) { + setupRenderingTest(hooks); - componentTest("renders avatars and support for unknown", { - template: '{{mount-widget widget="small-user-list" args=args}}', - beforeEach() { - this.set("args", { - users: [ - { id: 456, username: "eviltrout" }, - { id: 457, username: "someone", unknown: true }, - ], - }); - }, - async test(assert) { - assert.ok(queryAll('[data-user-card="eviltrout"]').length === 1); - assert.ok(queryAll('[data-user-card="someone"]').length === 0); - assert.ok(queryAll(".unknown").length, "includes unkown user"); - }, - }); -}); + componentTest("renders avatars and support for unknown", { + template: '{{mount-widget widget="small-user-list" args=args}}', + beforeEach() { + this.set("args", { + users: [ + { id: 456, username: "eviltrout" }, + { id: 457, username: "someone", unknown: true }, + ], + }); + }, + async test(assert) { + assert.ok(queryAll('[data-user-card="eviltrout"]').length === 1); + assert.ok(queryAll('[data-user-card="someone"]').length === 0); + assert.ok(queryAll(".unknown").length, "includes unkown user"); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/topic-status-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/topic-status-test.js index 89fce7aeb15..f8e8377eb0a 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/topic-status-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/topic-status-test.js @@ -7,41 +7,42 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import TopicStatusIcons from "discourse/helpers/topic-status-icons"; -discourseModule("Integration | Component | Widget | topic-status", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | topic-status", + function (hooks) { + setupRenderingTest(hooks); - componentTest("basics", { - template: '{{mount-widget widget="topic-status" args=args}}', - beforeEach(store) { - this.set("args", { - topic: store.createRecord("topic", { closed: true }), - disableActions: true, - }); - }, - test(assert) { - assert.ok(queryAll(".topic-status .d-icon-lock").length); - }, - }); + componentTest("basics", { + template: '{{mount-widget widget="topic-status" args=args}}', + beforeEach(store) { + this.set("args", { + topic: store.createRecord("topic", { closed: true }), + disableActions: true, + }); + }, + test(assert) { + assert.ok(queryAll(".topic-status .d-icon-lock").length); + }, + }); - componentTest("extendability", { - template: '{{mount-widget widget="topic-status" args=args}}', - beforeEach(store) { - TopicStatusIcons.addObject([ - "has_accepted_answer", - "far-check-square", - "solved", - ]); - this.set("args", { - topic: store.createRecord("topic", { - has_accepted_answer: true, - }), - disableActions: true, - }); - }, - test(assert) { - assert.ok(queryAll(".topic-status .d-icon-far-check-square").length); - }, - }); -}); + componentTest("extendability", { + template: '{{mount-widget widget="topic-status" args=args}}', + beforeEach(store) { + TopicStatusIcons.addObject([ + "has_accepted_answer", + "far-check-square", + "solved", + ]); + this.set("args", { + topic: store.createRecord("topic", { + has_accepted_answer: true, + }), + disableActions: true, + }); + }, + test(assert) { + assert.ok(queryAll(".topic-status .d-icon-far-check-square").length); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js index afe1ad3bf68..232745f9356 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js @@ -10,226 +10,227 @@ import I18n from "I18n"; import { click } from "@ember/test-helpers"; import sinon from "sinon"; -discourseModule("Integration | Component | Widget | user-menu", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | user-menu", + function (hooks) { + setupRenderingTest(hooks); - componentTest("basics", { - template: '{{mount-widget widget="user-menu"}}', + componentTest("basics", { + template: '{{mount-widget widget="user-menu"}}', - test(assert) { - assert.ok(queryAll(".user-menu").length); - assert.ok(queryAll(".user-preferences-link").length); - assert.ok(queryAll(".user-notifications-link").length); - assert.ok(queryAll(".user-bookmarks-link").length); - assert.ok(queryAll(".quick-access-panel").length); - assert.ok(queryAll(".notifications-dismiss").length); - }, - }); + test(assert) { + assert.ok(queryAll(".user-menu").length); + assert.ok(queryAll(".user-preferences-link").length); + assert.ok(queryAll(".user-notifications-link").length); + assert.ok(queryAll(".user-bookmarks-link").length); + assert.ok(queryAll(".quick-access-panel").length); + assert.ok(queryAll(".notifications-dismiss").length); + }, + }); - componentTest("notifications", { - template: '{{mount-widget widget="user-menu"}}', + componentTest("notifications", { + template: '{{mount-widget widget="user-menu"}}', - async test(assert) { - const $links = queryAll(".quick-access-panel li a"); + async test(assert) { + const $links = queryAll(".quick-access-panel li a"); - assert.equal($links.length, 5); - assert.ok($links[0].href.includes("/t/a-slug/123")); + assert.equal($links.length, 5); + assert.ok($links[0].href.includes("/t/a-slug/123")); - assert.ok( - $links[1].href.includes( - "/u/eviltrout/notifications/likes-received?acting_username=aquaman" - ) - ); + assert.ok( + $links[1].href.includes( + "/u/eviltrout/notifications/likes-received?acting_username=aquaman" + ) + ); - assert.equal( - $links[1].text, - `aquaman ${I18n.t("notifications.liked_consolidated_description", { - count: 5, - })}` - ); - - assert.ok($links[2].href.includes("/u/test2/messages/group/test")); - assert.ok( - $links[2].innerHTML.includes( - I18n.t("notifications.group_message_summary", { + assert.equal( + $links[1].text, + `aquaman ${I18n.t("notifications.liked_consolidated_description", { count: 5, - group_name: "test", - }) - ) - ); + })}` + ); - assert.ok($links[3].href.includes("/u/test1")); - assert.ok( - $links[3].innerHTML.includes( - I18n.t("notifications.invitee_accepted", { username: "test1" }) - ) - ); + assert.ok($links[2].href.includes("/u/test2/messages/group/test")); + assert.ok( + $links[2].innerHTML.includes( + I18n.t("notifications.group_message_summary", { + count: 5, + group_name: "test", + }) + ) + ); - assert.ok($links[4].href.includes("/g/test")); - assert.ok( - $links[4].innerHTML.includes( - I18n.t("notifications.membership_request_accepted", { - group_name: "test", - }) - ) - ); + assert.ok($links[3].href.includes("/u/test1")); + assert.ok( + $links[3].innerHTML.includes( + I18n.t("notifications.invitee_accepted", { username: "test1" }) + ) + ); - const routeToStub = sinon.stub(DiscourseURL, "routeTo"); - await click(".user-notifications-link"); - assert.ok( - routeToStub.calledWith( - queryAll(".user-notifications-link").data("url") - ), - "a second click should redirect to the full notifications page" - ); - }, - }); + assert.ok($links[4].href.includes("/g/test")); + assert.ok( + $links[4].innerHTML.includes( + I18n.t("notifications.membership_request_accepted", { + group_name: "test", + }) + ) + ); - componentTest("log out", { - template: '{{mount-widget widget="user-menu" logout=(action "logout")}}', + const routeToStub = sinon.stub(DiscourseURL, "routeTo"); + await click(".user-notifications-link"); + assert.ok( + routeToStub.calledWith( + queryAll(".user-notifications-link").data("url") + ), + "a second click should redirect to the full notifications page" + ); + }, + }); - beforeEach() { - this.on("logout", () => (this.loggedOut = true)); - }, + componentTest("log out", { + template: '{{mount-widget widget="user-menu" logout=(action "logout")}}', - async test(assert) { - await click(".user-preferences-link"); + beforeEach() { + this.on("logout", () => (this.loggedOut = true)); + }, - assert.ok(queryAll(".logout").length); + async test(assert) { + await click(".user-preferences-link"); - await click(".logout button"); - assert.ok(this.loggedOut); - }, - }); + assert.ok(queryAll(".logout").length); - componentTest("private messages - disabled", { - template: '{{mount-widget widget="user-menu"}}', - beforeEach() { - this.siteSettings.enable_personal_messages = false; - }, + await click(".logout button"); + assert.ok(this.loggedOut); + }, + }); - test(assert) { - assert.ok(!queryAll(".user-pms-link").length); - }, - }); + componentTest("private messages - disabled", { + template: '{{mount-widget widget="user-menu"}}', + beforeEach() { + this.siteSettings.enable_personal_messages = false; + }, - componentTest("private messages - enabled", { - template: '{{mount-widget widget="user-menu"}}', - beforeEach() { - this.siteSettings.enable_personal_messages = true; - }, + test(assert) { + assert.ok(!queryAll(".user-pms-link").length); + }, + }); - async test(assert) { - const userPmsLink = queryAll(".user-pms-link").data("url"); - assert.ok(userPmsLink); - await click(".user-pms-link"); + componentTest("private messages - enabled", { + template: '{{mount-widget widget="user-menu"}}', + beforeEach() { + this.siteSettings.enable_personal_messages = true; + }, - const message = queryAll(".quick-access-panel li a")[0]; - assert.ok(message); + async test(assert) { + const userPmsLink = queryAll(".user-pms-link").data("url"); + assert.ok(userPmsLink); + await click(".user-pms-link"); - assert.ok( - message.href.includes("/t/bug-can-not-render-emoji-properly/174/2"), - "should link to the next unread post" - ); - assert.ok( - message.innerHTML.includes("mixtape"), - "should include the last poster's username" - ); - assert.ok( - message.innerHTML.match(//), - "should correctly render emoji in message title" - ); + const message = queryAll(".quick-access-panel li a")[0]; + assert.ok(message); - const routeToStub = sinon.stub(DiscourseURL, "routeTo"); - await click(".user-pms-link"); - assert.ok( - routeToStub.calledWith(userPmsLink), - "a second click should redirect to the full private messages page" - ); - }, - }); + assert.ok( + message.href.includes("/t/bug-can-not-render-emoji-properly/174/2"), + "should link to the next unread post" + ); + assert.ok( + message.innerHTML.includes("mixtape"), + "should include the last poster's username" + ); + assert.ok( + message.innerHTML.match(//), + "should correctly render emoji in message title" + ); - componentTest("bookmarks", { - template: '{{mount-widget widget="user-menu"}}', + const routeToStub = sinon.stub(DiscourseURL, "routeTo"); + await click(".user-pms-link"); + assert.ok( + routeToStub.calledWith(userPmsLink), + "a second click should redirect to the full private messages page" + ); + }, + }); - async test(assert) { - await click(".user-bookmarks-link"); + componentTest("bookmarks", { + template: '{{mount-widget widget="user-menu"}}', - const bookmark = queryAll(".quick-access-panel li a")[0]; - assert.ok(bookmark); + async test(assert) { + await click(".user-bookmarks-link"); - assert.ok(bookmark.href.includes("/t/yelling-topic-title/119")); - assert.ok( - bookmark.innerHTML.includes("someguy"), - "should include the last poster's username" - ); - assert.ok( - bookmark.innerHTML.match(//), - "should correctly render emoji in bookmark title" - ); + const bookmark = queryAll(".quick-access-panel li a")[0]; + assert.ok(bookmark); - const routeToStub = sinon.stub(DiscourseURL, "routeTo"); - await click(".user-bookmarks-link"); - assert.ok( - routeToStub.calledWith(queryAll(".user-bookmarks-link").data("url")), - "a second click should redirect to the full bookmarks page" - ); - }, - }); + assert.ok(bookmark.href.includes("/t/yelling-topic-title/119")); + assert.ok( + bookmark.innerHTML.includes("someguy"), + "should include the last poster's username" + ); + assert.ok( + bookmark.innerHTML.match(//), + "should correctly render emoji in bookmark title" + ); - componentTest("anonymous", { - template: - '{{mount-widget widget="user-menu" toggleAnonymous=(action "toggleAnonymous")}}', + const routeToStub = sinon.stub(DiscourseURL, "routeTo"); + await click(".user-bookmarks-link"); + assert.ok( + routeToStub.calledWith(queryAll(".user-bookmarks-link").data("url")), + "a second click should redirect to the full bookmarks page" + ); + }, + }); - beforeEach() { - this.currentUser.setProperties({ is_anonymous: false, trust_level: 3 }); - this.siteSettings.allow_anonymous_posting = true; - this.siteSettings.anonymous_posting_min_trust_level = 3; + componentTest("anonymous", { + template: + '{{mount-widget widget="user-menu" toggleAnonymous=(action "toggleAnonymous")}}', - this.on("toggleAnonymous", () => (this.anonymous = true)); - }, + beforeEach() { + this.currentUser.setProperties({ is_anonymous: false, trust_level: 3 }); + this.siteSettings.allow_anonymous_posting = true; + this.siteSettings.anonymous_posting_min_trust_level = 3; - async test(assert) { - await click(".user-preferences-link"); - assert.ok(queryAll(".enable-anonymous").length); + this.on("toggleAnonymous", () => (this.anonymous = true)); + }, - await click(".enable-anonymous"); - assert.ok(this.anonymous); - }, - }); + async test(assert) { + await click(".user-preferences-link"); + assert.ok(queryAll(".enable-anonymous").length); - componentTest("anonymous - disabled", { - template: '{{mount-widget widget="user-menu"}}', + await click(".enable-anonymous"); + assert.ok(this.anonymous); + }, + }); - beforeEach() { - this.siteSettings.allow_anonymous_posting = false; - }, + componentTest("anonymous - disabled", { + template: '{{mount-widget widget="user-menu"}}', - async test(assert) { - await click(".user-preferences-link"); - assert.ok(!queryAll(".enable-anonymous").length); - }, - }); + beforeEach() { + this.siteSettings.allow_anonymous_posting = false; + }, - componentTest("anonymous - switch back", { - template: - '{{mount-widget widget="user-menu" toggleAnonymous=(action "toggleAnonymous")}}', + async test(assert) { + await click(".user-preferences-link"); + assert.ok(!queryAll(".enable-anonymous").length); + }, + }); - beforeEach() { - this.currentUser.setProperties({ is_anonymous: true }); - this.siteSettings.allow_anonymous_posting = true; + componentTest("anonymous - switch back", { + template: + '{{mount-widget widget="user-menu" toggleAnonymous=(action "toggleAnonymous")}}', - this.on("toggleAnonymous", () => (this.anonymous = false)); - }, + beforeEach() { + this.currentUser.setProperties({ is_anonymous: true }); + this.siteSettings.allow_anonymous_posting = true; - async test(assert) { - await click(".user-preferences-link"); - assert.ok(queryAll(".disable-anonymous").length); + this.on("toggleAnonymous", () => (this.anonymous = false)); + }, - await click(".disable-anonymous"); - assert.notOk(this.anonymous); - }, - }); -}); + async test(assert) { + await click(".user-preferences-link"); + assert.ok(queryAll(".disable-anonymous").length); + + await click(".disable-anonymous"); + assert.notOk(this.anonymous); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/widget-dropdown-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/widget-dropdown-test.js index 9e2642a16ae..f17e92981cf 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/widget-dropdown-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/widget-dropdown-test.js @@ -60,79 +60,79 @@ const TEMPLATE = ` ) }}`; -discourseModule("Integration | Component | Widget | widget-dropdown", function ( - hooks -) { - setupRenderingTest(hooks); +discourseModule( + "Integration | Component | Widget | widget-dropdown", + function (hooks) { + setupRenderingTest(hooks); - componentTest("dropdown id", { - template: TEMPLATE, + componentTest("dropdown id", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - test(assert) { - assert.ok(exists("#my-dropdown")); - }, - }); + test(assert) { + assert.ok(exists("#my-dropdown")); + }, + }); - componentTest("label", { - template: TEMPLATE, + componentTest("label", { + template: TEMPLATE, - _translations: I18n.translations, + _translations: I18n.translations, - beforeEach() { - I18n.translations = { en: { js: { foo: "FooBaz" } } }; - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + I18n.translations = { en: { js: { foo: "FooBaz" } } }; + this.setProperties(DEFAULT_CONTENT); + }, - afterEach() { - I18n.translations = this._translations; - }, + afterEach() { + I18n.translations = this._translations; + }, - test(assert) { - assert.equal(headerLabel(), "FooBaz"); - }, - }); + test(assert) { + assert.equal(headerLabel(), "FooBaz"); + }, + }); - componentTest("translatedLabel", { - template: TEMPLATE, + componentTest("translatedLabel", { + template: TEMPLATE, - _translations: I18n.translations, + _translations: I18n.translations, - beforeEach() { - I18n.translations = { en: { js: { foo: "FooBaz" } } }; - this.setProperties(DEFAULT_CONTENT); - this.set("translatedLabel", "BazFoo"); - }, + beforeEach() { + I18n.translations = { en: { js: { foo: "FooBaz" } } }; + this.setProperties(DEFAULT_CONTENT); + this.set("translatedLabel", "BazFoo"); + }, - afterEach() { - I18n.translations = this._translations; - }, + afterEach() { + I18n.translations = this._translations; + }, - test(assert) { - assert.equal(headerLabel(), this.translatedLabel); - }, - }); + test(assert) { + assert.equal(headerLabel(), this.translatedLabel); + }, + }); - componentTest("content", { - template: TEMPLATE, + componentTest("content", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - await toggle(); - assert.equal(rowById(1).dataset.id, 1, "it creates rows"); - assert.equal(rowById(2).dataset.id, 2, "it creates rows"); - assert.equal(rowById(3).dataset.id, 3, "it creates rows"); - }, - }); + async test(assert) { + await toggle(); + assert.equal(rowById(1).dataset.id, 1, "it creates rows"); + assert.equal(rowById(2).dataset.id, 2, "it creates rows"); + assert.equal(rowById(3).dataset.id, 3, "it creates rows"); + }, + }); - componentTest("onChange action", { - template: ` + componentTest("onChange action", { + template: `
{{mount-widget widget="widget-dropdown" @@ -145,204 +145,205 @@ discourseModule("Integration | Component | Widget | widget-dropdown", function ( }} `, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); + beforeEach() { + this.setProperties(DEFAULT_CONTENT); - this.on( - "onChange", - (item) => (this._element.querySelector("#test").innerText = item.id) - ); - }, + this.on( + "onChange", + (item) => (this._element.querySelector("#test").innerText = item.id) + ); + }, - async test(assert) { - await toggle(); - await clickRowById(2); - assert.equal( - queryAll("#test").text(), - 2, - "it calls the onChange actions" - ); - }, - }); + async test(assert) { + await toggle(); + await clickRowById(2); + assert.equal( + queryAll("#test").text(), + 2, + "it calls the onChange actions" + ); + }, + }); - componentTest("can be opened and closed", { - template: TEMPLATE, + componentTest("can be opened and closed", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - assert.ok(exists("#my-dropdown.closed")); - assert.ok(!exists("#my-dropdown .widget-dropdown-body")); - await toggle(); - assert.equal(rowById(2).innerText.trim(), "FooBar"); - assert.ok(exists("#my-dropdown.opened")); - assert.ok(exists("#my-dropdown .widget-dropdown-body")); - await toggle(); - assert.ok(exists("#my-dropdown.closed")); - assert.ok(!exists("#my-dropdown .widget-dropdown-body")); - }, - }); + async test(assert) { + assert.ok(exists("#my-dropdown.closed")); + assert.ok(!exists("#my-dropdown .widget-dropdown-body")); + await toggle(); + assert.equal(rowById(2).innerText.trim(), "FooBar"); + assert.ok(exists("#my-dropdown.opened")); + assert.ok(exists("#my-dropdown .widget-dropdown-body")); + await toggle(); + assert.ok(exists("#my-dropdown.closed")); + assert.ok(!exists("#my-dropdown .widget-dropdown-body")); + }, + }); - componentTest("icon", { - template: TEMPLATE, + componentTest("icon", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - this.set("icon", "times"); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + this.set("icon", "times"); + }, - test(assert) { - assert.ok(exists(header().querySelector(".d-icon-times"))); - }, - }); + test(assert) { + assert.ok(exists(header().querySelector(".d-icon-times"))); + }, + }); - componentTest("class", { - template: TEMPLATE, + componentTest("class", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - this.set("class", "activated"); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + this.set("class", "activated"); + }, - test(assert) { - assert.ok(exists("#my-dropdown.activated")); - }, - }); + test(assert) { + assert.ok(exists("#my-dropdown.activated")); + }, + }); - componentTest("content with translatedLabel", { - template: TEMPLATE, + componentTest("content with translatedLabel", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - await toggle(); - assert.equal(rowById(2).innerText.trim(), "FooBar"); - }, - }); + async test(assert) { + await toggle(); + assert.equal(rowById(2).innerText.trim(), "FooBar"); + }, + }); - componentTest("content with label", { - template: TEMPLATE, + componentTest("content with label", { + template: TEMPLATE, - _translations: I18n.translations, + _translations: I18n.translations, - beforeEach() { - I18n.translations = { en: { js: { foo: "FooBaz" } } }; - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + I18n.translations = { en: { js: { foo: "FooBaz" } } }; + this.setProperties(DEFAULT_CONTENT); + }, - afterEach() { - I18n.translations = this._translations; - }, + afterEach() { + I18n.translations = this._translations; + }, - async test(assert) { - await toggle(); - assert.equal(rowById(1).innerText.trim(), "FooBaz"); - }, - }); + async test(assert) { + await toggle(); + assert.equal(rowById(1).innerText.trim(), "FooBaz"); + }, + }); - componentTest("content with icon", { - template: TEMPLATE, + componentTest("content with icon", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - await toggle(); - assert.ok(exists(rowById(3).querySelector(".d-icon-times"))); - }, - }); + async test(assert) { + await toggle(); + assert.ok(exists(rowById(3).querySelector(".d-icon-times"))); + }, + }); - componentTest("content with html", { - template: TEMPLATE, + componentTest("content with html", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - await toggle(); - assert.equal(rowById(4).innerHTML.trim(), "baz"); - }, - }); + async test(assert) { + await toggle(); + assert.equal(rowById(4).innerHTML.trim(), "baz"); + }, + }); - componentTest("separator", { - template: TEMPLATE, + componentTest("separator", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + }, - async test(assert) { - await toggle(); - assert.ok( - queryAll( - "#my-dropdown .widget-dropdown-item:nth-child(3)" - )[0].classList.contains("separator") - ); - }, - }); + async test(assert) { + await toggle(); + assert.ok( + queryAll( + "#my-dropdown .widget-dropdown-item:nth-child(3)" + )[0].classList.contains("separator") + ); + }, + }); - componentTest("hides widget if no content", { - template: TEMPLATE, + componentTest("hides widget if no content", { + template: TEMPLATE, - beforeEach() { - this.setProperties({ content: null, label: "foo" }); - }, + beforeEach() { + this.setProperties({ content: null, label: "foo" }); + }, - test(assert) { - assert.notOk(exists("#my-dropdown .widget-dropdown-header")); - assert.notOk(exists("#my-dropdown .widget-dropdown-body")); - }, - }); + test(assert) { + assert.notOk(exists("#my-dropdown .widget-dropdown-header")); + assert.notOk(exists("#my-dropdown .widget-dropdown-body")); + }, + }); - componentTest("headerClass option", { - template: TEMPLATE, + componentTest("headerClass option", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - this.set("options", { headerClass: "btn-small and-text" }); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + this.set("options", { headerClass: "btn-small and-text" }); + }, - test(assert) { - assert.ok(header().classList.contains("widget-dropdown-header")); - assert.ok(header().classList.contains("btn-small")); - assert.ok(header().classList.contains("and-text")); - }, - }); + test(assert) { + assert.ok(header().classList.contains("widget-dropdown-header")); + assert.ok(header().classList.contains("btn-small")); + assert.ok(header().classList.contains("and-text")); + }, + }); - componentTest("bodyClass option", { - template: TEMPLATE, + componentTest("bodyClass option", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - this.set("options", { bodyClass: "gigantic and-yet-small" }); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + this.set("options", { bodyClass: "gigantic and-yet-small" }); + }, - async test(assert) { - await toggle(); - assert.ok(body().classList.contains("widget-dropdown-body")); - assert.ok(body().classList.contains("gigantic")); - assert.ok(body().classList.contains("and-yet-small")); - }, - }); + async test(assert) { + await toggle(); + assert.ok(body().classList.contains("widget-dropdown-body")); + assert.ok(body().classList.contains("gigantic")); + assert.ok(body().classList.contains("and-yet-small")); + }, + }); - componentTest("caret option", { - template: TEMPLATE, + componentTest("caret option", { + template: TEMPLATE, - beforeEach() { - this.setProperties(DEFAULT_CONTENT); - this.set("options", { caret: true }); - }, + beforeEach() { + this.setProperties(DEFAULT_CONTENT); + this.set("options", { caret: true }); + }, - test(assert) { - assert.ok( - exists("#my-dropdown .widget-dropdown-header .d-icon-caret-down") - ); - }, - }); -}); + test(assert) { + assert.ok( + exists("#my-dropdown .widget-dropdown-header .d-icon-caret-down") + ); + }, + }); + } +); diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 39f97ab8b7d..10924acedc3 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -33,9 +33,9 @@ const Modal = Plugin.Constructor; function AcceptanceModal(option, _relatedTarget) { return this.each(function () { - var $this = $(this); - var data = $this.data("bs.modal"); - var options = $.extend( + let $this = $(this); + let data = $this.data("bs.modal"); + let options = $.extend( {}, Modal.DEFAULTS, $this.data(), @@ -202,8 +202,8 @@ export default function setupTests(app, container) { // Load ES6 tests function getUrlParameter(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); - var results = regex.exec(location.search); + let regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); + let results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); diff --git a/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js b/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js index decaab7f4af..155af390152 100644 --- a/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js +++ b/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js @@ -5,8 +5,8 @@ let originalTemplates; let resolver; function lookupTemplate(assert, name, expectedTemplate, message) { - var parseName = resolver.parseName(name); - var result = resolver.resolveTemplate(parseName); + let parseName = resolver.parseName(name); + let result = resolver.resolveTemplate(parseName); assert.equal(result, expectedTemplate, message); } diff --git a/app/assets/javascripts/discourse/tests/unit/lib/click-track-test.js b/app/assets/javascripts/discourse/tests/unit/lib/click-track-test.js index de2f56eed36..14b0b66d81e 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/click-track-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/click-track-test.js @@ -154,7 +154,7 @@ module("Unit | Utility | click-track", function (hooks) { assert.notOk(track(generateClickEventOn("a"))); - var $link = fixture("a").first(); + let $link = fixture("a").first(); assert.ok($link.hasClass("no-href")); assert.equal($link.data("href"), "http://www.google.com/"); assert.blank($link.attr("href")); @@ -178,7 +178,7 @@ module("Unit | Utility | click-track", function (hooks) { function badgeClickCount(assert, id, expected) { track(generateClickEventOn("#" + id)); - var $badge = $("span.badge", fixture("#" + id).first()); + let $badge = $("span.badge", fixture("#" + id).first()); assert.equal(parseInt($badge.html(), 10), expected); } @@ -200,7 +200,7 @@ module("Unit | Utility | click-track", function (hooks) { function testOpenInANewTab(description, clickEventModifier) { test(description, async function (assert) { - var clickEvent = generateClickEventOn("a"); + let clickEvent = generateClickEventOn("a"); clickEventModifier(clickEvent); assert.ok(track(clickEvent)); assert.notOk(clickEvent.defaultPrevented); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js b/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js index 216e42cd630..e8d7cd3db90 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/computed-test.js @@ -45,7 +45,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("propertyEqual", function (assert) { - var t = EmberObject.extend({ + let t = EmberObject.extend({ same: propertyEqual("cookies", "biscuits"), }).create({ cookies: 10, @@ -58,7 +58,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("propertyNotEqual", function (assert) { - var t = EmberObject.extend({ + let t = EmberObject.extend({ diff: propertyNotEqual("cookies", "biscuits"), }).create({ cookies: 10, @@ -71,7 +71,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("fmt", function (assert) { - var t = EmberObject.extend({ + let t = EmberObject.extend({ exclaimyUsername: fmt("username", "!!! %@ !!!"), multiple: fmt("username", "mood", "%@ is %@"), }).create({ @@ -105,7 +105,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("i18n", function (assert) { - var t = EmberObject.extend({ + let t = EmberObject.extend({ exclaimyUsername: i18n("username", "!!! %@ !!!"), multiple: i18n("username", "mood", "%@ is %@"), }).create({ @@ -139,7 +139,7 @@ discourseModule("Unit | Utility | computed", function (hooks) { }); test("url", function (assert) { - var t, testClass; + let t, testClass; testClass = EmberObject.extend({ userUrl: url("username", "/u/%@"), diff --git a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js index fa7faff0fc5..71cc9bc95a4 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js @@ -159,7 +159,7 @@ discourseModule("Unit | Utility | formatter", function (hooks) { assert.equal(formatDays(-500), shortDateYear(-500)); assert.equal(formatDays(-365 * 2 - 1), shortDateYear(-365 * 2 - 1)); // one leap year - var originalValue = this.siteSettings.relative_date_duration; + let originalValue = this.siteSettings.relative_date_duration; this.siteSettings.relative_date_duration = 7; assert.equal(formatDays(7), "7d"); assert.equal(formatDays(8), shortDate(8)); @@ -203,9 +203,9 @@ discourseModule("Unit | Utility | formatter", function (hooks) { }); test("autoUpdatingRelativeAge", function (assert) { - var d = moment().subtract(1, "day").toDate(); + let d = moment().subtract(1, "day").toDate(); - var $elem = $(autoUpdatingRelativeAge(d)); + let $elem = $(autoUpdatingRelativeAge(d)); assert.equal($elem.data("format"), "tiny"); assert.equal($elem.data("time"), d.getTime()); assert.equal($elem.attr("title"), undefined); @@ -233,8 +233,8 @@ discourseModule("Unit | Utility | formatter", function (hooks) { }); test("updateRelativeAge", function (assert) { - var d = new Date(); - var $elem = $(autoUpdatingRelativeAge(d)); + let d = new Date(); + let $elem = $(autoUpdatingRelativeAge(d)); $elem.data("time", d.getTime() - 2 * 60 * 1000); updateRelativeAge($elem); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js index 25b6121bdaf..02be685e6b5 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/uploads-test.js @@ -194,7 +194,7 @@ discourseModule("Unit | Utility | uploads", function () { test("isImage", function (assert) { ["png", "webp", "jpg", "jpeg", "gif", "ico"].forEach((extension) => { - var image = "image." + extension; + let image = "image." + extension; assert.ok(isImage(image), image + " is recognized as an image"); assert.ok( isImage("http://foo.bar/path/to/" + image), diff --git a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js index e76b27877d4..6739b729a79 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js @@ -71,7 +71,7 @@ discourseModule("Unit | Utilities", function () { }); test("avatarUrl", function (assert) { - var rawSize = getRawSize; + let rawSize = getRawSize; assert.blank(avatarUrl("", "tiny"), "no template returns blank"); assert.equal( avatarUrl("/fake/template/{size}.png", "tiny"), @@ -85,7 +85,7 @@ discourseModule("Unit | Utilities", function () { ); }); - var setDevicePixelRatio = function (value) { + let setDevicePixelRatio = function (value) { if (Object.defineProperty && !window.hasOwnProperty("devicePixelRatio")) { Object.defineProperty(window, "devicePixelRatio", { value: 2 }); } else { @@ -94,10 +94,10 @@ discourseModule("Unit | Utilities", function () { }; test("avatarImg", function (assert) { - var oldRatio = window.devicePixelRatio; + let oldRatio = window.devicePixelRatio; setDevicePixelRatio(2); - var avatarTemplate = "/path/to/avatar/{size}.png"; + let avatarTemplate = "/path/to/avatar/{size}.png"; assert.equal( avatarImg({ avatarTemplate: avatarTemplate, size: "tiny" }), "", @@ -164,7 +164,7 @@ discourseModule("Unit | Utilities", function () { }); test("caretRowCol", function (assert) { - var textarea = document.createElement("textarea"); + let textarea = document.createElement("textarea"); const content = document.createTextNode("01234\n56789\n012345"); textarea.appendChild(content); document.body.appendChild(textarea); diff --git a/app/assets/javascripts/discourse/tests/unit/mixins/singleton-test.js b/app/assets/javascripts/discourse/tests/unit/mixins/singleton-test.js index b142e52042e..0a2e29d0e5f 100644 --- a/app/assets/javascripts/discourse/tests/unit/mixins/singleton-test.js +++ b/app/assets/javascripts/discourse/tests/unit/mixins/singleton-test.js @@ -4,10 +4,10 @@ import Singleton from "discourse/mixins/singleton"; module("Unit | Mixin | singleton", function () { test("current", function (assert) { - var DummyModel = EmberObject.extend({}); + let DummyModel = EmberObject.extend({}); DummyModel.reopenClass(Singleton); - var current = DummyModel.current(); + let current = DummyModel.current(); assert.present(current, "current returns the current instance"); assert.equal( current, @@ -22,9 +22,9 @@ module("Unit | Mixin | singleton", function () { }); test("currentProp reading", function (assert) { - var DummyModel = EmberObject.extend({}); + let DummyModel = EmberObject.extend({}); DummyModel.reopenClass(Singleton); - var current = DummyModel.current(); + let current = DummyModel.current(); assert.blank( DummyModel.currentProp("evil"), @@ -39,14 +39,14 @@ module("Unit | Mixin | singleton", function () { }); test("currentProp writing", function (assert) { - var DummyModel = EmberObject.extend({}); + let DummyModel = EmberObject.extend({}); DummyModel.reopenClass(Singleton); assert.blank( DummyModel.currentProp("adventure"), "by default attributes are blank" ); - var result = DummyModel.currentProp("adventure", "time"); + let result = DummyModel.currentProp("adventure", "time"); assert.equal(result, "time", "it returns the new value"); assert.equal( DummyModel.currentProp("adventure"), @@ -70,7 +70,7 @@ module("Unit | Mixin | singleton", function () { }); test("createCurrent", function (assert) { - var Shoe = EmberObject.extend({}); + let Shoe = EmberObject.extend({}); Shoe.reopenClass(Singleton, { createCurrent: function () { return Shoe.create({ toes: 5 }); @@ -85,7 +85,7 @@ module("Unit | Mixin | singleton", function () { }); test("createCurrent that returns null", function (assert) { - var Missing = EmberObject.extend({}); + let Missing = EmberObject.extend({}); Missing.reopenClass(Singleton, { createCurrent: function () { return null; diff --git a/app/assets/javascripts/discourse/tests/unit/models/post-test.js b/app/assets/javascripts/discourse/tests/unit/models/post-test.js index b85d5762b7d..82b5e528057 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/post-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/post-test.js @@ -18,13 +18,13 @@ function buildPost(args) { module("Unit | Model | post", function () { test("defaults", function (assert) { - var post = Post.create({ id: 1 }); + let post = Post.create({ id: 1 }); assert.blank(post.get("deleted_at"), "it has no deleted_at by default"); assert.blank(post.get("deleted_by"), "there is no deleted_by by default"); }); test("new_user", function (assert) { - var post = Post.create({ trust_level: 0 }); + let post = Post.create({ trust_level: 0 }); assert.ok(post.get("new_user"), "post is from a new user"); post.set("trust_level", 1); @@ -32,7 +32,7 @@ module("Unit | Model | post", function () { }); test("firstPost", function (assert) { - var post = Post.create({ post_number: 1 }); + let post = Post.create({ post_number: 1 }); assert.ok(post.get("firstPost"), "it's the first post"); post.set("post_number", 10); @@ -40,7 +40,7 @@ module("Unit | Model | post", function () { }); test("updateFromPost", function (assert) { - var post = Post.create({ + let post = Post.create({ post_number: 1, raw: "hello world", }); diff --git a/app/assets/javascripts/discourse/tests/unit/models/rest-model-test.js b/app/assets/javascripts/discourse/tests/unit/models/rest-model-test.js index 8fe391217d8..b549826f1ad 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/rest-model-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/rest-model-test.js @@ -15,7 +15,7 @@ module("Unit | Model | rest-model", function () { }, }); - var g = Grape.create({ store, percent: 0.4 }); + let g = Grape.create({ store, percent: 0.4 }); assert.equal(g.get("inverse"), 0.6, "it runs `munge` on `create`"); }); diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js index 8cbe7b06b5f..4e11fe03243 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/topic-details-test.js @@ -9,13 +9,13 @@ function buildDetails(id) { module("Unit | Model | topic-details", function () { test("defaults", function (assert) { - var details = buildDetails(1234); + let details = buildDetails(1234); assert.present(details, "the details are present by default"); assert.ok(!details.get("loaded"), "details are not loaded by default"); }); test("updateFromJson", function (assert) { - var details = buildDetails(1234); + let details = buildDetails(1234); details.updateFromJson({ allowed_users: [{ username: "eviltrout" }], diff --git a/app/assets/javascripts/discourse/tests/unit/models/user-action-test.js b/app/assets/javascripts/discourse/tests/unit/models/user-action-test.js index 9b6518c3de2..50cd70e739c 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/user-action-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/user-action-test.js @@ -3,7 +3,7 @@ import UserAction from "discourse/models/user-action"; module("Unit | Model | user-action", function () { test("collapsing likes", function (assert) { - var actions = UserAction.collapseStream([ + let actions = UserAction.collapseStream([ UserAction.create({ action_type: UserAction.TYPES.likes_given, topic_id: 1, diff --git a/app/assets/javascripts/discourse/tests/unit/models/user-stream-test.js b/app/assets/javascripts/discourse/tests/unit/models/user-stream-test.js index 9fdeb815a61..8ba20c9cc6f 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/user-stream-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/user-stream-test.js @@ -4,8 +4,8 @@ import UserAction from "discourse/models/user-action"; module("Unit | Model | user-stream", function () { test("basics", function (assert) { - var user = User.create({ id: 1, username: "eviltrout" }); - var stream = user.get("stream"); + let user = User.create({ id: 1, username: "eviltrout" }); + let stream = user.get("stream"); assert.present(stream, "a user has a stream by default"); assert.equal( stream.get("user"), @@ -25,8 +25,8 @@ module("Unit | Model | user-stream", function () { }); test("filterParam", function (assert) { - var user = User.create({ id: 1, username: "eviltrout" }); - var stream = user.get("stream"); + let user = User.create({ id: 1, username: "eviltrout" }); + let stream = user.get("stream"); // defaults to posts/topics assert.equal(stream.get("filterParam"), "4,5"); diff --git a/app/assets/javascripts/discourse/tests/unit/models/user-test.js b/app/assets/javascripts/discourse/tests/unit/models/user-test.js index d17725a6f84..0b95967b12f 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/user-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/user-test.js @@ -7,7 +7,7 @@ import sinon from "sinon"; module("Unit | Model | user", function () { test("staff", function (assert) { - var user = User.create({ id: 1, username: "eviltrout" }); + let user = User.create({ id: 1, username: "eviltrout" }); assert.ok(!user.get("staff"), "user is not staff"); @@ -19,7 +19,7 @@ module("Unit | Model | user", function () { }); test("searchContext", function (assert) { - var user = User.create({ id: 1, username: "EvilTrout" }); + let user = User.create({ id: 1, username: "EvilTrout" }); assert.deepEqual( user.get("searchContext"), @@ -29,7 +29,7 @@ module("Unit | Model | user", function () { }); test("isAllowedToUploadAFile", function (assert) { - var user = User.create({ trust_level: 0, admin: true }); + let user = User.create({ trust_level: 0, admin: true }); assert.ok( user.isAllowedToUploadAFile("image"), "admin can always upload a file" diff --git a/app/assets/javascripts/embed-application.js b/app/assets/javascripts/embed-application.js index 4ba6a082fa7..f71ac900ef2 100644 --- a/app/assets/javascripts/embed-application.js +++ b/app/assets/javascripts/embed-application.js @@ -9,11 +9,11 @@ } function clickPostLink(e) { - var postId = e.target.getAttribute("data-link-to-post"); + let postId = e.target.getAttribute("data-link-to-post"); if (postId) { - var postElement = document.getElementById("post-" + postId); + let postElement = document.getElementById("post-" + postId); if (postElement) { - var rect = postElement.getBoundingClientRect(); + let rect = postElement.getBoundingClientRect(); if (rect && rect.top) { postUp({ type: "discourse-scroll", top: rect.top }); e.preventDefault(); @@ -25,9 +25,9 @@ window.onload = function () { // get state info from data attribute - var embedState = document.querySelector("[data-embed-state]"); - var state = "unknown"; - var embedId = null; + let embedState = document.querySelector("[data-embed-state]"); + let state = "unknown"; + let embedId = null; if (embedState) { state = embedState.getAttribute("data-embed-state"); embedId = embedState.getAttribute("data-embed-id"); @@ -41,7 +41,7 @@ embedId, }); - var postLinks = document.querySelectorAll("a[data-link-to-post]"), + let postLinks = document.querySelectorAll("a[data-link-to-post]"), i; for (i = 0; i < postLinks.length; i++) { @@ -49,15 +49,15 @@ } // Make sure all links in the iframe point to _blank - var cookedLinks = document.querySelectorAll(".cooked a"); + let cookedLinks = document.querySelectorAll(".cooked a"); for (i = 0; i < cookedLinks.length; i++) { cookedLinks[i].target = "_blank"; } // Adjust all names - var names = document.querySelectorAll(".username a"); + let names = document.querySelectorAll(".username a"); for (i = 0; i < names.length; i++) { - var username = names[i].innerHTML; + let username = names[i].innerHTML; if (username) { /* global BreakString */ names[i].innerHTML = new BreakString(username).break(); diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js index 4160d7986dc..c9d2c714a40 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js @@ -191,7 +191,7 @@ function findInlineCloseTag(state, openTag, start, max) { } function applyBBCode(state, startLine, endLine, silent, md) { - var nextLine, + let nextLine, oldParent, oldLineMax, rule, diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js index cd246286896..069a88c2f32 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/helpers.js @@ -15,7 +15,7 @@ export default null; // based off https://github.com/markdown-it/markdown-it-emoji/blob/master/dist/markdown-it-emoji.js // export function textReplace(state, callback, skipAllLinks) { - var i, + let i, j, l, tokens, diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/html-img.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/html-img.js index 596c45ad7f0..e876499a252 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/html-img.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/html-img.js @@ -5,7 +5,7 @@ const REGEX = /^\s*$/i; function rule(state, startLine, endLine) { - var nextLine, + let nextLine, token, lineText, pos = state.bMarks[startLine] + state.tShift[startLine], diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/newline.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/newline.js index 1de6a74a36f..5781c9df203 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/newline.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/newline.js @@ -5,7 +5,7 @@ // this is a freedom patch, so careful, may break on updates function newline(state, silent) { - var token, + let token, pmax, max, pos = state.pos; diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/paragraph.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/paragraph.js index a44a0214d72..79c51667691 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/paragraph.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/paragraph.js @@ -4,7 +4,7 @@ // link starts with a space, so we can bypass a onebox // this is a freedom patch, so careful, may break on updates function paragraph(state, startLine /*, endLine*/) { - var content, + let content, terminate, i, l, diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/quotes.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/quotes.js index c7e0dc9ca71..45dc70ebcd0 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/quotes.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/quotes.js @@ -113,7 +113,7 @@ const rule = { if (offTopicQuote) { const topicInfo = options.getTopicInfo(topicId); if (topicInfo) { - var href = topicInfo.href; + let href = topicInfo.href; if (postNumber > 0) { href += "/" + postNumber; } diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/resize-controls.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/resize-controls.js index 63bf3f7059b..8b342446112 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/resize-controls.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/resize-controls.js @@ -90,8 +90,8 @@ export function setup(helper) { const imageIndex = token.attrIndex("index-image"); if (scaleIndex !== -1) { - var selectedScale = token.attrs[scaleIndex][1]; - var index = token.attrs[imageIndex][1]; + let selectedScale = token.attrs[scaleIndex][1]; + let index = token.attrs[imageIndex][1]; let result = ""; result += oldRule(tokens, idx, options, env, slf); diff --git a/app/assets/javascripts/wizard/test/acceptance/wizard-test.js b/app/assets/javascripts/wizard/test/acceptance/wizard-test.js index 4c00de28106..7f935e4fb46 100644 --- a/app/assets/javascripts/wizard/test/acceptance/wizard-test.js +++ b/app/assets/javascripts/wizard/test/acceptance/wizard-test.js @@ -3,7 +3,7 @@ import { module, test } from "qunit"; import { run } from "@ember/runloop"; import startApp from "wizard/test/helpers/start-app"; -var wizard; +let wizard; module("Acceptance: wizard", { beforeEach() { wizard = startApp(); diff --git a/app/assets/javascripts/wizard/test/test_helper.js b/app/assets/javascripts/wizard/test/test_helper.js index 05d0eb3c9f0..3aec94db05c 100644 --- a/app/assets/javascripts/wizard/test/test_helper.js +++ b/app/assets/javascripts/wizard/test/test_helper.js @@ -25,7 +25,7 @@ //= require test-shims // Trick JSHint into allow document.write -var d = document; +let d = document; d.write( '
' ); @@ -40,14 +40,14 @@ if (window.Logster) { } Ember.Test.adapter = window.QUnitAdapter.create(); -var createPretendServer = requirejs( +let createPretendServer = requirejs( "wizard/test/wizard-pretender", null, null, false ).default; -var server; +let server; QUnit.testStart(function () { server = createPretendServer(); }); @@ -56,8 +56,8 @@ QUnit.testDone(function () { server.shutdown(); }); -var _testApp = requirejs("wizard/test/helpers/start-app").default(); -var _buildResolver = requirejs("discourse-common/resolver").buildResolver; +let _testApp = requirejs("wizard/test/helpers/start-app").default(); +let _buildResolver = requirejs("discourse-common/resolver").buildResolver; window.setResolver(_buildResolver("wizard").create({ namespace: _testApp })); Object.keys(requirejs.entries).forEach(function (entry) { diff --git a/package.json b/package.json index 784cb2e636b..9dad6d2d8ed 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "bootstrap": "v3.4.1", "chart.js": "2.9.3", "chartjs-plugin-datalabels": "^0.7.0", - "eslint-config-discourse": "^1.1.5", + "eslint-config-discourse": "^1.1.8", "handlebars": "^4.7.0", "highlight.js": "https://github.com/highlightjs/highlight.js", "intersection-observer": "^0.5.1", diff --git a/plugins/lazy-yt/assets/javascripts/lazyYT.js b/plugins/lazy-yt/assets/javascripts/lazyYT.js index d131a7924ab..8078671868c 100644 --- a/plugins/lazy-yt/assets/javascripts/lazyYT.js +++ b/plugins/lazy-yt/assets/javascripts/lazyYT.js @@ -15,7 +15,7 @@ "use strict"; function setUp($el, settings) { - var width = $el.data("width"), + let width = $el.data("width"), height = $el.data("height"), ratio = $el.data("ratio") ? $el.data("ratio") : settings.default_ratio, id = $el.data("youtube-id"), @@ -88,7 +88,7 @@ innerHtml.push(""); // .html5-title-text-wrapper innerHtml.push(""); // end of Video title .html5-info-bar - var prefetchedThumbnail = $el[0].querySelector(".ytp-thumbnail-image"); + let prefetchedThumbnail = $el[0].querySelector(".ytp-thumbnail-image"); $el .css({ @@ -158,15 +158,15 @@ } $.fn.lazyYT = function (newSettings) { - var defaultSettings = { + let defaultSettings = { default_ratio: "16:9", callback: null, // ToDO execute callback if given container_class: "lazyYT-container", }; - var settings = $.extend(defaultSettings, newSettings); + let settings = $.extend(defaultSettings, newSettings); return this.each(function () { - var $el = $(this).addClass(settings.container_class); + let $el = $(this).addClass(settings.container_class); setUp($el, settings); }); }; diff --git a/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 b/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 index 9f0d033b79f..e004aefa759 100644 --- a/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 +++ b/plugins/poll/assets/javascripts/lib/discourse-markdown/poll.js.es6 @@ -302,7 +302,7 @@ export function setup(helper) { * http://www.opensource.org/licenses/bsd-license */ function md5cycle(x, k) { - var a = x[0], + let a = x[0], b = x[1], c = x[2], d = x[3]; @@ -406,14 +406,14 @@ function md51(s) { // Converts the string to UTF-8 "bytes" s = unescape(encodeURI(s)); - var n = s.length, + let n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i; for (i = 64; i <= s.length; i += 64) { md5cycle(state, md5blk(s.substring(i - 64, i))); } s = s.substring(i - 64); - var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; for (i = 0; i < s.length; i++) { tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3); } @@ -431,7 +431,7 @@ function md51(s) { function md5blk(s) { /* I figured global was faster. */ - var md5blks = [], + let md5blks = [], i; /* Andy King said do it this way. */ for (i = 0; i < 64; i += 4) { md5blks[i >> 2] = @@ -443,10 +443,10 @@ function md5blk(s) { return md5blks; } -var hex_chr = "0123456789abcdef".split(""); +let hex_chr = "0123456789abcdef".split(""); function rhex(n) { - var s = "", + let s = "", j = 0; for (; j < 4; j++) { s += hex_chr[(n >> (j * 8 + 4)) & 0x0f] + hex_chr[(n >> (j * 8)) & 0x0f]; @@ -455,7 +455,7 @@ function rhex(n) { } function hex(x) { - for (var i = 0; i < x.length; i++) { + for (let i = 0; i < x.length; i++) { x[i] = rhex(x[i]); } return x.join(""); diff --git a/plugins/poll/assets/javascripts/lib/even-round.js.es6 b/plugins/poll/assets/javascripts/lib/even-round.js.es6 index 93c1226b7a7..cd8bf345931 100644 --- a/plugins/poll/assets/javascripts/lib/even-round.js.es6 +++ b/plugins/poll/assets/javascripts/lib/even-round.js.es6 @@ -4,7 +4,7 @@ function sumsUpTo100(percentages) { } export default function (percentages) { - var decimals = percentages.map((a) => a % 1); + let decimals = percentages.map((a) => a % 1); const sumOfDecimals = Math.ceil(decimals.reduce((a, b) => a + b)); // compensate error by adding 1 to n items with the greatest decimal part for (let i = 0, max = decimals.length; i < sumOfDecimals && i < max; i++) { diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 index fa983631732..5972107295a 100644 --- a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 +++ b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 @@ -553,7 +553,7 @@ function pieChartConfig(data, labels, opts = {}) { } function stripHtml(html) { - var doc = new DOMParser().parseFromString(html, "text/html"); + let doc = new DOMParser().parseFromString(html, "text/html"); return doc.body.textContent || ""; } diff --git a/test/run-qunit.js b/test/run-qunit.js index 018b14b31b4..9438b34679f 100644 --- a/test/run-qunit.js +++ b/test/run-qunit.js @@ -5,7 +5,7 @@ // Requires chrome-launcher and chrome-remote-interface from npm // An up-to-date version of chrome is also required -var args = process.argv.slice(2); +let args = process.argv.slice(2); if (args.length < 1 || args.length > 3) { console.log("Usage: node run-qunit.js "); @@ -128,9 +128,9 @@ async function runAllTests() { } const timeout = parseInt(args[1] || 300000, 10); - var start = Date.now(); + let start = Date.now(); - var interval; + let interval; let runTests = async function () { if (Date.now() > start + timeout) { @@ -218,7 +218,7 @@ function logQUnit() { return; } - var msg = "\n Assertion Failed:"; + let msg = "\n Assertion Failed:"; if (context.message) { msg += " " + context.message; } @@ -256,7 +256,7 @@ function logQUnit() { console.log("\n"); } - var stats = [ + let stats = [ "Time: " + context.runtime + "ms", "Total: " + context.total, "Passed: " + context.passed, diff --git a/yarn.lock b/yarn.lock index 4156ac08613..a25b5e3e1b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -935,10 +935,10 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-config-discourse@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-1.1.5.tgz#29e274eeccd3071d86aaa9333c6550ceeb23b1cd" - integrity sha512-/2DgKfIAKRHP+ktNvYCvK2z0NVmgpMe4le1HcrXtj0EzRswqsUN1kbaU81X3cnG4iEuKxyf0n0Hp+2kHuneatg== +eslint-config-discourse@^1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-1.1.8.tgz#c297831876811ea08203aa348d1ba2a963b2ae78" + integrity sha512-ZSQfhliiO5Cfa7WcKoMkN4wW/1rBJpecpMJpfjiFsElfgPj4EV4Pzksi5CvFnRbJDoZh6DYYrQfO+tW062VOUA== dependencies: babel-eslint "^10.1.0" ember-template-lint "^2.11.0" @@ -948,7 +948,7 @@ eslint-config-discourse@^1.1.5: eslint-plugin-ember "^6.10.0" eslint-plugin-lodash "^7.1.0" eslint-plugin-node "^8.0.0" - prettier "2.1.2" + prettier "2.2.1" eslint-plugin-discourse-ember@latest: version "0.0.3" @@ -2345,10 +2345,10 @@ pretender@^1.6: fake-xml-http-request "^1.6.0" route-recognizer "^0.3.3" -prettier@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5" - integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg== +prettier@2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" + integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== process-nextick-args@~2.0.0: version "2.0.1"