DEV: prettier 2.2.1 (#11862)

This commit is contained in:
Joffrey JAFFEUX 2021-01-27 12:39:20 +01:00 committed by GitHub
parent 7be556fc19
commit c6a1042950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
117 changed files with 2495 additions and 2433 deletions

View File

@ -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

View File

@ -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

View File

@ -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: [
{

View File

@ -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;
});

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -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"));
}

View File

@ -2,10 +2,10 @@
//Copyright (c) 2007-2009, MIT Style License <browser-update.org/LICENSE.txt>
(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 = "<div>" + t + "</div>";
// 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

View File

@ -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);
};

View File

@ -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);

View File

@ -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;
}

View File

@ -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];

View File

@ -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;

View File

@ -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 =

View File

@ -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));
},
};

View File

@ -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();
},
};

View File

@ -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) {

View File

@ -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;

View File

@ -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);
}
)
);
}

View File

@ -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 {

View File

@ -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([
{

View File

@ -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) {

View File

@ -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);

View File

@ -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]);

View File

@ -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;
},

View File

@ -727,7 +727,7 @@ export default Controller.extend({
}
}
var staged = false;
let staged = false;
// TODO: This should not happen in model
const imageSizes = {};

View File

@ -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 &&

View File

@ -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 });
}
},

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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 "<span class='" + classes + "' " + style + "></span>";
}
@ -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

View File

@ -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,

View File

@ -1,13 +1,13 @@
import { htmlHelper } from "discourse-common/lib/helpers";
function renderSpinner(cssClass) {
var html = "<div class='spinner";
let html = "<div class='spinner";
if (cssClass) {
html += " " + cssClass;
}
return html + "'></div>";
}
var spinnerHTML = renderSpinner();
let spinnerHTML = renderSpinner();
export default htmlHelper((params) => {
const hash = params.hash;

View File

@ -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(/\/$/, "");

View File

@ -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) {

View File

@ -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;

View File

@ -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) };

View File

@ -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);
}

View File

@ -1,5 +1,5 @@
// for android we test webkit
var hiddenProperty =
let hiddenProperty =
document.hidden !== undefined
? "hidden"
: document.webkitHidden !== undefined

View File

@ -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);

View File

@ -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();
};

View File

@ -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,

View File

@ -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) {

View File

@ -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.");
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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);

View File

@ -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";
}

View File

@ -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) => {

View File

@ -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(

View File

@ -157,7 +157,7 @@ export default (filterArg, params) => {
canCreateTopic: canCreateTopic,
});
var topicOpts = {
let topicOpts = {
model: topics,
category,
period:

View File

@ -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,

View File

@ -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) => {

View File

@ -29,7 +29,7 @@ createWidget("avatar-flair", {
},
buildAttributes(attrs) {
var style = "";
let style = "";
if (!this.isIcon(attrs)) {
style +=
"background-image: url(" +

View File

@ -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 = `<a class="mention-group" href="/g/${username}">@${username}</a>`;

View File

@ -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"
);
});
}
);

View File

@ -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();

View File

@ -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";

View File

@ -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);
},
});
}
);

View File

@ -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}}",

View File

@ -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, "--:--");
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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");
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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");
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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");
},
});
}
);

View File

@ -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);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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"
);
},
});
}
);

View File

@ -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);
},
});
}
);

View File

@ -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");
},
});
}
);

View File

@ -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);
},
});
}
);

View File

@ -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(/<img.*class="emoji".*>/),
"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(/<img.*class="emoji".*>/),
"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(/<img.*class="emoji".*>/),
"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(/<img.*class="emoji".*>/),
"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);
},
});
}
);

View File

@ -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: `
<div id="test"></div>
{{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(), "<span><b>baz</b></span>");
},
});
async test(assert) {
await toggle();
assert.equal(rowById(4).innerHTML.trim(), "<span><b>baz</b></span>");
},
});
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")
);
},
});
}
);

View File

@ -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, " "));

View File

@ -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);
}

View File

@ -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);

View File

@ -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/%@"),

View File

@ -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);

View File

@ -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),

View File

@ -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" }),
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar'>",
@ -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);

View File

@ -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;

View File

@ -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",
});

View File

@ -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`");
});

View File

@ -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" }],

View File

@ -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,

View File

@ -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");

View File

@ -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"

Some files were not shown because too many files have changed in this diff Show More