Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix various minor issues in core frontend tests (#39274)

Jarek Radosz49af23796984
diff --git a/frontend/discourse/admin/components/admin-report-stacked-chart.gjs b/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
index 8dac4a7735d..72656f80cd4 100644
--- a/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
+++ b/frontend/discourse/admin/components/admin-report-stacked-chart.gjs
@@ -210,7 +210,7 @@ export default class AdminReportStackedChart extends Component {
sampleSize: 5,
maxRotation: 25,
minRotation: 0,
- step: 1,
+ stepSize: 1,
},
},
x: {
diff --git a/frontend/discourse/admin/controllers/admin-search-logs/term.js b/frontend/discourse/admin/controllers/admin-search-logs/term.js
index 1452cd13cb4..a6431b67c6e 100644
--- a/frontend/discourse/admin/controllers/admin-search-logs/term.js
+++ b/frontend/discourse/admin/controllers/admin-search-logs/term.js
@@ -48,14 +48,12 @@ export default class AdminSearchLogsTermController extends Controller {
},
},
scales: {
- y: [
- {
- display: true,
- ticks: {
- stepSize: 1,
- },
+ y: {
+ display: true,
+ ticks: {
+ stepSize: 1,
},
- ],
+ },
},
},
};
diff --git a/frontend/discourse/app/services/header.js b/frontend/discourse/app/services/header.js
index 51ab699ca0d..d1235ca8158 100644
--- a/frontend/discourse/app/services/header.js
+++ b/frontend/discourse/app/services/header.js
@@ -105,7 +105,7 @@ export default class Header extends Service {
// eslint-disable-next-line no-console
console.error(
`Invalid button to hide: ${button}, valid buttons are: ${VALID_HEADER_BUTTONS_TO_HIDE.join(
- ","
+ ", "
)}`
);
} else {
diff --git a/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js b/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js
index 6c38fbe3d38..f541d678189 100644
--- a/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js
+++ b/frontend/discourse/tests/acceptance/admin-sidebar-section-test.js
@@ -1,5 +1,6 @@
import { click, fillIn, findAll, visit } from "@ember/test-helpers";
import { test } from "qunit";
+import sinon from "sinon";
import { AUTO_GROUPS } from "discourse/lib/constants";
import { withPluginApi } from "discourse/lib/plugin-api";
import PreloadStore from "discourse/lib/preload-store";
@@ -397,10 +398,14 @@ acceptance("Admin Sidebar - Plugin Icons", function (needs) {
});
test("setAdminPluginIcon with falsy icon is ignored and keeps default gear icon", async function (assert) {
+ const stub = sinon.stub(console, "warn");
+
withPluginApi((api) => {
api.setAdminPluginIcon("discourse-calendar", "");
});
+ assert.true(stub.calledWith("", "An icon must be provided!"));
+
await visit("/admin");
await click(".sidebar-toggle-all-sections");
@@ -409,6 +414,8 @@ acceptance("Admin Sidebar - Plugin Icons", function (needs) {
".sidebar-section[data-section-name='admin-plugins'] .sidebar-section-link-wrapper[data-list-item-name='admin_plugin_discourse-calendar'] .d-icon-gear"
)
.exists("default gear icon is displayed when falsy icon is provided");
+
+ stub.restore();
});
});
diff --git a/frontend/discourse/tests/acceptance/category-edit-test.js b/frontend/discourse/tests/acceptance/category-edit-test.js
index 8197d6bf6a1..6033ff1b5a9 100644
--- a/frontend/discourse/tests/acceptance/category-edit-test.js
+++ b/frontend/discourse/tests/acceptance/category-edit-test.js
@@ -111,7 +111,6 @@ acceptance("Category Edit", function (needs) {
assert.deepEqual(payload.allowed_tags, ["monkey"]);
assert.deepEqual(payload.allowed_tag_groups, ["TagGroup1"]);
- await allowedTagGroupChooser.collapse();
await allowedTagChooser.expand();
await allowedTagChooser.deselectItemByName("monkey");
diff --git a/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js b/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js
index 6ca4ed0d224..8dd12580909 100644
--- a/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js
+++ b/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js
@@ -244,6 +244,8 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) {
});
test("cancelling uploads clears the placeholders out", async function (assert) {
+ const consoleErrorStub = sinon.stub(console, "error");
+
await visit("/");
await click("#create-topic");
await fillIn(".d-editor-input", "The image:\n");
@@ -278,6 +280,13 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) {
appEvents.trigger("composer:add-files", [image, image2]);
});
await click("#cancel-file-upload");
+
+ assert.true(
+ consoleErrorStub.calledWithMatch("[Uppy]"),
+ "Uppy logs the cancelled uploads to the console"
+ );
+
+ consoleErrorStub.restore();
});
test("should insert a newline before and after an image when pasting in the end of the line", async function (assert) {
@@ -498,6 +507,8 @@ acceptance("Uppy Composer Attachment - Upload Error", function (needs) {
});
test("should show an error message for the failed upload", async function (assert) {
+ const consoleErrorStub = sinon.stub(console, "error");
+
await visit("/");
await click("#create-topic");
await fillIn(".d-editor-input", "The image:\n");
@@ -512,8 +523,13 @@ acceptance("Uppy Composer Attachment - Upload Error", function (needs) {
"There was an error uploading the file, the gif was way too cool.",
"shows the error message from the server"
);
+ assert.true(
+ consoleErrorStub.calledWithMatch("[Uppy]"),
+ "Uppy logs the upload failure to the console"
+ );
await click(".dialog-footer .btn-primary");
+ consoleErrorStub.restore();
done();
});
@@ -539,6 +555,8 @@ acceptance(
});
test("should show a consolidated message for multiple failed uploads", async function (assert) {
+ const consoleErrorStub = sinon.stub(console, "error");
+
await visit("/");
await click("#create-topic");
const appEvents = getOwner(this).lookup("service:app-events");
@@ -556,8 +574,14 @@ acceptance(
"Sorry, there was an error uploading meme1.png and meme2.png. Please try again.",
"it should show a consolidated error dialog"
);
+ // eslint-disable-next-line qunit/no-conditional-assertions
+ assert.true(
+ consoleErrorStub.calledWithMatch("[Uppy]"),
+ "Uppy logs the upload failures to the console"
+ );
await click(".dialog-footer .btn-primary");
+ consoleErrorStub.restore();
done();
}
diff --git a/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js b/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js
index 9dfa014c322..3d319c3ef7f 100644
--- a/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js
+++ b/frontend/discourse/tests/acceptance/edit-category-topic-template-test.js
@@ -45,8 +45,8 @@ acceptance(
name: "bug",
can_edit: true,
category_type_site_settings: {},
- permissions: [],
...putData,
+ permissions: [],
},
});
});
@@ -150,8 +150,8 @@ acceptance("Admin - Legacy edit category topic template", function (needs) {
name: "bug",
can_edit: true,
category_type_site_settings: {},
- permissions: [],
...putData,
+ permissions: [],
},
});
});
diff --git a/frontend/discourse/tests/acceptance/tag-groups-test.js b/frontend/discourse/tests/acceptance/tag-groups-test.js
index 3c986714b5c..8aa6197f487 100644
--- a/frontend/discourse/tests/acceptance/tag-groups-test.js
+++ b/frontend/discourse/tests/acceptance/tag-groups-test.js
@@ -20,7 +20,9 @@ acceptance("Tag Groups", function (needs) {
};
server.post("/tag_groups", () => helper.response(tagGroups));
- server.get("/forum/tag_groups", () => helper.response(tagGroups));
+ server.get("/forum/tag_groups", () =>
+ helper.response({ tag_groups: [tagGroups.tag_group] })
+ );
server.get("/groups/search.json", () => {
return helper.response([
{
diff --git a/frontend/discourse/tests/acceptance/user-test.js b/frontend/discourse/tests/acceptance/user-test.js
index 97c132fbc86..b7b81716e75 100644
--- a/frontend/discourse/tests/acceptance/user-test.js
+++ b/frontend/discourse/tests/acceptance/user-test.js
@@ -7,6 +7,7 @@ import {
visit,
} from "@ember/test-helpers";
import { test } from "qunit";
+import sinon from "sinon";
import { cloneJSON } from "discourse/lib/object";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import {
@@ -343,9 +344,18 @@ acceptance("User - Invalid view_user_route setting", function (needs) {
});
test("It defaults to summary", async function (assert) {
+ const stub = sinon.stub(console, "error");
+
await visit("/u/eviltrout");
assert.strictEqual(currentRouteName(), "user.summary");
+ assert.true(
+ stub.calledWith(
+ "Invalid value for view_user_route 'user.X'. Falling back to 'summary'."
+ )
+ );
+
+ stub.restore();
});
});
diff --git a/frontend/discourse/tests/helpers/store-pretender.js b/frontend/discourse/tests/helpers/store-pretender.js
index dbc0edb0f1a..6f4d3ed3141 100644
--- a/frontend/discourse/tests/helpers/store-pretender.js
+++ b/frontend/discourse/tests/helpers/store-pretender.js
@@ -12,14 +12,7 @@ const fruits = [
{ id: 1, name: "apple", farmer_id: 1, color_ids: [1, 2], category_id: 4 },
{ id: 2, name: "banana", farmer_id: 1, color_ids: [3], category_id: 3 },
{ id: 3, name: "grape", farmer_id: 2, color_ids: [2], category_id: 5 },
- {
- id: 4,
- name: "orange",
- farmer_id: null,
- color_ids: [2],
- category_id: 5,
- other_fruit_ids: { apple: 1, banana: 2 },
- },
+ { id: 4, name: "orange", farmer_id: null, color_ids: [2], category_id: 5 },
];
const farmers = [
diff --git a/frontend/discourse/tests/integration/components/async-content-test.gjs b/frontend/discourse/tests/integration/components/async-content-test.gjs
index fd7009fadee..f92c9ab1cd6 100644
--- a/frontend/discourse/tests/integration/components/async-content-test.gjs
+++ b/frontend/discourse/tests/integration/components/async-content-test.gjs
@@ -6,6 +6,7 @@ import { click, render, waitFor } from "@ember/test-helpers";
import { TrackedAsyncData } from "ember-async-data";
import { module, test } from "qunit";
import { Promise as RsvpPromise } from "rsvp";
+import sinon from "sinon";
import AsyncContent from "discourse/components/async-content";
import DialogHolder from "discourse/dialog-holder/components/dialog-holder";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
@@ -231,6 +232,7 @@ module("Integration | Component | AsyncContent", function (hooks) {
});
test("it does not display the block if the promise fails", async function (assert) {
+ const stub = sinon.stub(console, "error");
const promise = Promise.reject("error");
await render(
@@ -246,6 +248,9 @@ module("Integration | Component | AsyncContent", function (hooks) {
);
assert.dom(".content").doesNotExist();
+ assert.true(stub.calledWith("error"));
+
+ stub.restore();
});
});
@@ -305,6 +310,7 @@ module("Integration | Component | AsyncContent", function (hooks) {
});
test("it does not display the block if the promise fails", async function (assert) {
+ const stub = sinon.stub(console, "error");
const promise = Promise.reject("error");
await render(
@@ -320,11 +326,15 @@ module("Integration | Component | AsyncContent", function (hooks) {
);
assert.dom(".empty").doesNotExist();
+ assert.true(stub.calledWith("error"));
+
+ stub.restore();
});
});
module("<:error>", function () {
test("it displays an inline error when the block is not provided", async function (assert) {
+ const stub = sinon.stub(console, "error");
const promise = Promise.reject("error");
await render(
@@ -333,9 +343,13 @@ module("Integration | Component | AsyncContent", function (hooks) {
assert.dom(".alert-error").exists();
assert.dom(".alert-error").hasText("Sorry, an error has occurred.");
+ assert.true(stub.calledWith("error"));
+
+ stub.restore();
});
test("it displays a popup error dialog when the block is not provided", async function (assert) {
+ const stub = sinon.stub(console, "error");
const promise = Promise.reject("error");
await render(
@@ -347,6 +361,9 @@ module("Integration | Component | AsyncContent", function (hooks) {
assert.dom(".dialog-body").exists();
assert.dom(".dialog-body").hasText("Sorry, an error has occurred.");
+ assert.true(stub.calledWith("error"));
+
+ stub.restore();
});
test("it displays the block when the promise is rejected", async function (assert) {
@@ -369,6 +386,7 @@ module("Integration | Component | AsyncContent", function (hooks) {
});
test("it passes the inline error message as a component when the promise is rejected", async function (assert) {
+ const stub = sinon.stub(console, "error");
const promise = Promise.reject("error");
await render(
@@ -387,6 +405,9 @@ module("Integration | Component | AsyncContent", function (hooks) {
assert.dom(".alert-error").exists();
assert.dom(".alert-error").hasText("Sorry, an error has occurred.");
+ assert.true(stub.calledWith("error"));
+
+ stub.restore();
});
test("it does not display the block when the promise is resolved", async function (assert) {
diff --git a/frontend/discourse/tests/integration/components/block-outlet-test.gjs b/frontend/discourse/tests/integration/components/block-outlet-test.gjs
index 858ee3dda48..11b0e56461f 100644
--- a/frontend/discourse/tests/integration/components/block-outlet-test.gjs
+++ b/frontend/discourse/tests/integration/components/block-outlet-test.gjs
@@ -260,6 +260,8 @@ module("Integration | Blocks | BlockOutlet", function (hooks) {
module("authorization and security", function () {
test("throws when @block component used directly in template", async function (assert) {
+ const stub = sinon.stub(console, "error");
+
@block("direct-usage-block")
class DirectUsageBlock extends Component {
<template>
@@ -278,6 +280,9 @@ module("Integration | Blocks | BlockOutlet", function (hooks) {
errorThrown?.message?.includes("cannot be used directly in templates"),
"throws authorization error"
);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
+ stub.restore();
});
});
@@ -1631,6 +1636,7 @@ module("Integration | Blocks | BlockOutlet", function (hooks) {
module("error handling", function () {
test("outlet continues rendering other blocks when one block throws", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errorCaught = null;
setupOnerror((error) => {
errorCaught = error;
@@ -1671,6 +1677,9 @@ module("Integration | Blocks | BlockOutlet", function (hooks) {
errorCaught?.message?.includes("Block render error"),
"error message is correct"
);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
+ stub.restore();
});
test("block with invalid condition type shows warning in dev mode", async function (assert) {
diff --git a/frontend/discourse/tests/integration/components/interpolated-translation-test.gjs b/frontend/discourse/tests/integration/components/interpolated-translation-test.gjs
index 4a085d1a611..c0923d0e4e1 100644
--- a/frontend/discourse/tests/integration/components/interpolated-translation-test.gjs
+++ b/frontend/discourse/tests/integration/components/interpolated-translation-test.gjs
@@ -7,6 +7,7 @@ import {
setupOnerror,
} from "@ember/test-helpers";
import { module, test } from "qunit";
+import sinon from "sinon";
import InterpolatedTranslation from "discourse/components/interpolated-translation";
import UserLink from "discourse/components/user-link";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
@@ -79,6 +80,7 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
});
test("throws an error on simple translation without placeholders", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errors = 0;
setupOnerror((error) => {
@@ -95,10 +97,14 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
);
assert.strictEqual(errors, 1);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
resetOnerror();
+ stub.restore();
});
test("renders translation with string options only", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errors = 0;
setupOnerror((error) => {
@@ -120,7 +126,10 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
);
assert.strictEqual(errors, 1);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
resetOnerror();
+ stub.restore();
});
test("renders translation with both string options and component placeholders", async function (assert) {
@@ -166,6 +175,7 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
});
test("handles missing translation key gracefully", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errors = 0;
setupOnerror((error) => {
@@ -185,10 +195,14 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
assert.dom().hasText("[fr.nonexistent_key]");
assert.strictEqual(errors, 1);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
resetOnerror();
+ stub.restore();
});
test("handles placeholder not provided in template", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errors = 0;
setupOnerror((error) => {
assert.true(error instanceof I18nMissingInterpolationArgument);
@@ -204,13 +218,17 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
await render(<template><InterpolatedTranslation @key="hello" /></template>);
assert.strictEqual(errors, 1);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
resetOnerror();
+ stub.restore();
// Should render the placeholder string since no component was provided
assert.dom().includesText("Bonjour, [missing %{username} placeholder]");
});
test("handles empty placeholder provided in template", async function (assert) {
+ const stub = sinon.stub(console, "error");
let errors = 0;
setupOnerror((error) => {
assert.true(error instanceof Error);
@@ -230,7 +248,10 @@ module("Integration | Component | InterpolatedTranslation", function (hooks) {
);
assert.strictEqual(errors, 1);
+ assert.true(stub.calledWithMatch("Error occurred:"));
+
resetOnerror();
+ stub.restore();
});
test("correctly re-renders when args change", async function (assert) {
diff --git a/frontend/discourse/tests/unit/lib/block-outlet-test.js b/frontend/discourse/tests/unit/lib/block-outlet-test.js
index e70c9e3e070..2cf54394a48 100644
--- a/frontend/discourse/tests/unit/lib/block-outlet-test.js
+++ b/frontend/discourse/tests/unit/lib/block-outlet-test.js
@@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import { getOwner } from "@ember/owner";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
+import sinon from "sinon";
import { block } from "discourse/blocks";
import { _renderBlocks } from "discourse/blocks/block-outlet";
import BlockGroup from "discourse/blocks/builtin/block-group";
@@ -148,6 +149,8 @@ module("Unit | Lib | block-outlet", function (hooks) {
});
test("sets blockMetadata with deniedOutlets", function (assert) {
+ const stub = sinon.stub(console, "warn");
+
@block("metadata-denied-outlets", {
deniedOutlets: ["modal-*", "tooltip-*"],
})
@@ -157,9 +160,23 @@ module("Unit | Lib | block-outlet", function (hooks) {
"modal-*",
"tooltip-*",
]);
+ assert.true(
+ stub.calledWithMatch(
+ '[Blocks] Block "metadata-denied-outlets": deniedOutlets pattern "modal-*" does not match any registered outlet.'
+ )
+ );
+ assert.true(
+ stub.calledWithMatch(
+ '[Blocks] Block "metadata-denied-outlets": deniedOutlets pattern "tooltip-*" does not match any registered outlet.'
+ )
+ );
+
+ stub.restore();
});
test("freezes allowedOutlets and deniedOutlets arrays", function (assert) {
+ const stub = sinon.stub(console, "warn");
+
@block("metadata-frozen-outlets", {
allowedOutlets: ["sidebar-*"],
deniedOutlets: ["modal-*"],
@@ -172,6 +189,13 @@ module("Unit | Lib | block-outlet", function (hooks) {
assert.true(
Object.isFrozen(getBlockMetadata(FrozenOutletsBlock).deniedOutlets)
);
+ assert.true(
+ stub.calledWithMatch(
+ '[Blocks] Block "metadata-frozen-outlets": deniedOutlets pattern "modal-*" does not match any registered outlet.'
+ )
+ );
+
+ stub.restore();
});
test("throws for conflicting outlet patterns", function (assert) {
@@ -254,6 +278,8 @@ module("Unit | Lib | block-outlet", function (hooks) {
});
test("accepts only valid option keys", function (assert) {
+ const stub = sinon.stub(console, "warn");
+
@block("valid-options-block", {
container: true,
description: "Test block",
@@ -268,6 +294,13 @@ module("Unit | Lib | block-outlet", function (hooks) {
getBlockMetadata(ValidOptionsBlock).description,
"Test block"
);
+ assert.true(
+ stub.calledWithMatch(
+ '[Blocks] Block "valid-options-block": deniedOutlets pattern "modal-*" does not match any registered outlet.'
+ )
+ );
+
+ stub.restore();
});
test("throws for invalid arg schema - missing type", function (assert) {
diff --git a/frontend/discourse/tests/unit/lib/blocks/matching/outlet-matcher-test.js b/frontend/discourse/tests/unit/lib/blocks/matching/outlet-matcher-test.js
index 31cb382d3e8..ddae74f369d 100644
--- a/frontend/discourse/tests/unit/lib/blocks/matching/outlet-matcher-test.js
+++ b/frontend/discourse/tests/unit/lib/blocks/matching/outlet-matcher-test.js
@@ -421,29 +421,29 @@ module("Unit | Lib | Blocks | outlet-matcher", function () {
});
module("warnUnknownOutletPatterns", function (hooks) {
- let consoleSpy;
+ let consoleStub;
hooks.beforeEach(function () {
- consoleSpy = sinon.spy(console, "warn");
+ consoleStub = sinon.stub(console, "warn");
});
hooks.afterEach(function () {
- consoleSpy.restore();
+ consoleStub.restore();
});
test("does not warn for null patterns", function (assert) {
warnUnknownOutletPatterns(null, "test-block", "allowedOutlets");
- assert.false(consoleSpy.called);
+ assert.false(consoleStub.called);
});
test("does not warn for empty patterns", function (assert) {
warnUnknownOutletPatterns([], "test-block", "allowedOutlets");
- assert.false(consoleSpy.called);
+ assert.false(consoleStub.called);
});
test("does not warn for patterns matching known outlets", function (assert) {
warnUnknownOutletPatterns(["sidebar-*"], "test-block", "allowedOutlets");
- assert.false(consoleSpy.called);
+ assert.false(consoleStub.called);
});
test("warns for unregistered namespaced patterns", function (assert) {
@@ -455,7 +455,7 @@ module("Unit | Lib | Blocks | outlet-matcher", function () {
"allowedOutlets"
);
assert.strictEqual(
- consoleSpy.callCount,
+ consoleStub.callCount,
2,
"warns for each unregistered namespaced pattern"
);
@@ -467,19 +467,19 @@ module("Unit | Lib | Blocks | outlet-matcher", function () {
"test-block",
"allowedOutlets"
);
- assert.true(consoleSpy.calledOnce);
+ assert.true(consoleStub.calledOnce);
assert.true(
- consoleSpy.firstCall.args[0].includes(
+ consoleStub.firstCall.args[0].includes(
"does not match any registered outlet"
)
);
- assert.true(consoleSpy.firstCall.args[0].includes("test-block"));
- assert.true(consoleSpy.firstCall.args[0].includes("allowedOutlets"));
+ assert.true(consoleStub.firstCall.args[0].includes("test-block"));
+ assert.true(consoleStub.firstCall.args[0].includes("allowedOutlets"));
});
test("warns for typos in outlet names", function (assert) {
warnUnknownOutletPatterns(["sidbar-*"], "test-block", "allowedOutlets");
- assert.true(consoleSpy.calledOnce);
+ assert.true(consoleStub.calledOnce);
});
test("warns for each unmatched pattern", function (assert) {
@@ -488,7 +488,7 @@ module("Unit | Lib | Blocks | outlet-matcher", function () {
"test-block",
"allowedOutlets"
);
- assert.strictEqual(consoleSpy.callCount, 2);
+ assert.strictEqual(consoleStub.callCount, 2);
});
});
});
diff --git a/frontend/discourse/tests/unit/models/category-test.js b/frontend/discourse/tests/unit/models/category-test.js
index 6b94839114b..8e7fc262a27 100644
--- a/frontend/discourse/tests/unit/models/category-test.js
+++ b/frontend/discourse/tests/unit/models/category-test.js
@@ -510,6 +510,7 @@ module("Unit | Model | category", function (hooks) {
});
test("asyncFindByIds - do not request categories that have been loaded already", async function (assert) {
+ const stub = sinon.stub(console, "warn");
const requestedIds = [];
pretender.get("/categories/find", (request) => {
const ids = request.queryParams.ids.map((id) => parseInt(id, 10));
@@ -527,9 +528,16 @@ module("Unit | Model | category", function (hooks) {
await Category.asyncFindByIds([12345, 12346, 12347]);
assert.deepEqual(requestedIds, [[12345, 12346], [12347]]);
+ assert.true(
+ stub.calledWith(
+ "WARNING: Multiple calls to Category.asyncFindByIds within a second. Could they be combined?"
+ )
+ );
await Category.asyncFindByIds([12345]);
assert.deepEqual(requestedIds, [[12345, 12346], [12347]]);
+
+ stub.restore();
});
test("registerCategorySaveProperty includes property in save request", async function (assert) {
diff --git a/frontend/discourse/tests/unit/services/header-test.js b/frontend/discourse/tests/unit/services/header-test.js
index d7accf33cf5..c766312f721 100644
--- a/frontend/discourse/tests/unit/services/header-test.js
+++ b/frontend/discourse/tests/unit/services/header-test.js
@@ -1,6 +1,7 @@
import { getOwner } from "@ember/owner";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
+import sinon from "sinon";
module("Unit | Service | header", function (hooks) {
setupTest(hooks);
@@ -16,7 +17,15 @@ module("Unit | Service | header", function (hooks) {
});
test("it does not register invalid buttons for hiders", function (assert) {
+ const stub = sinon.stub(console, "error");
this.header.registerHider(this, ["search", "blahblah"]);
+
assert.false(this.header.headerButtonsHidden.includes("blah"));
+ assert.true(
+ stub.calledWith(
+ "Invalid button to hide: blahblah, valid buttons are: search, login, signup, menu"
+ )
+ );
+ stub.restore();
});
});
diff --git a/frontend/discourse/tests/unit/services/store-test.js b/frontend/discourse/tests/unit/services/store-test.js
index 5e2c026fbf1..9f4e4e68b5e 100644
--- a/frontend/discourse/tests/unit/services/store-test.js
+++ b/frontend/discourse/tests/unit/services/store-test.js
@@ -1,6 +1,7 @@
import { getOwner } from "@ember/owner";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
+import sinon from "sinon";
import pretender, {
fixturesByUrl,
response,
@@ -265,14 +266,37 @@ module("Unit | Service | store", function (hooks) {
});
test("Spec incompliant embedded record name", async function (assert) {
+ const stub = sinon.stub(console, "warn");
+
+ pretender.get("/fruits/5", () =>
+ response({
+ __rest_serializer: "1",
+ fruit: {
+ id: 5,
+ name: "kiwi",
+ farmer_id: null,
+ color_ids: [1],
+ category_id: 5,
+ other_fruit_ids: { apple: 1, banana: 2 },
+ },
+ })
+ );
+
const store = getOwner(this).lookup("service:store");
- const fruit = await store.find("fruit", 4);
+ const fruit = await store.find("fruit", 5);
assert.propContains(
fruit.other_fruit_ids,
{ apple: 1, banana: 2 },
"embedded record remains unhydrated"
);
+ assert.true(
+ stub.calledWith(
+ "WARNING: Expected an array of resource ids for fruit.other_fruit_ids"
+ )
+ );
+
+ stub.restore();
});
test("hydrateEmbedded", async function (assert) {