A platform for community discussion. Free, open, simple.
DEV: Fix uppy flakes and remove unnecessary output from tests (#39411)
Jarek Radosz4d3f246ee258
diff --git a/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js b/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.jsindex 8dd12580909..268117cd6b9 100644--- a/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js+++ b/frontend/discourse/tests/acceptance/composer-uploads-uppy-test.js@@ -6,6 +6,7 @@ import {focus,settled,visit,+ waitFor,} from "@ember/test-helpers";import { skip, test } from "qunit";import { Promise } from "rsvp";@@ -17,6 +18,7 @@ import {chromeTest,createFile,paste,+ silenceConsoleErrorsMatching,} from "discourse/tests/helpers/qunit-helpers";import { i18n } from "discourse-i18n";@@ -244,7 +246,7 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) {});test("cancelling uploads clears the placeholders out", async function (assert) {- const consoleErrorStub = sinon.stub(console, "error");+ const consoleErrorStub = silenceConsoleErrorsMatching("[Uppy]");await visit("/");await click("#create-topic");@@ -281,11 +283,6 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) {});await click("#cancel-file-upload");- assert.true(- consoleErrorStub.calledWithMatch("[Uppy]"),- "Uppy logs the cancelled uploads to the console"- );-consoleErrorStub.restore();});@@ -555,39 +552,30 @@ acceptance(});test("should show a consolidated message for multiple failed uploads", async function (assert) {- const consoleErrorStub = sinon.stub(console, "error");+ const consoleErrorStub = silenceConsoleErrorsMatching("[Uppy]");await visit("/");await click("#create-topic");const appEvents = getOwner(this).lookup("service:app-events");const image = createFile("meme1.png");const image1 = createFile("meme2.png");- const done = assert.async();-- appEvents.on("composer:upload-error", async () => {- await settled();- if (find(".dialog-body")) {- assert- .dom(".dialog-body")- .hasText(- "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();+ appEvents.trigger("composer:add-files", [image, image1]);- done();- }- });+ await waitFor(".dialog-body");+ assert+ .dom(".dialog-body")+ .hasText(+ "Sorry, there was an error uploading meme1.png and meme2.png. Please try again.",+ "shows a consolidated error dialog"+ );+ assert.true(+ consoleErrorStub.calledWithMatch("[Uppy]"),+ "Uppy logs the upload failures to the console"+ );- appEvents.trigger("composer:add-files", [image, image1]);+ await click(".dialog-footer .btn-primary");+ consoleErrorStub.restore();});});diff --git a/frontend/discourse/tests/helpers/qunit-helpers.js b/frontend/discourse/tests/helpers/qunit-helpers.jsindex 9e26244d959..6bc894dbdbc 100644--- a/frontend/discourse/tests/helpers/qunit-helpers.js+++ b/frontend/discourse/tests/helpers/qunit-helpers.js@@ -578,6 +578,18 @@ export function firefoxTest(name, testCase) {conditionalTest(name, navigator.userAgent.includes("Firefox"), testCase);}+export function silenceConsoleErrorsMatching(substring) {+ const stub = sinon.stub(console, "error").callsFake((...args) => {+ if (typeof args[0] === "string" && args[0].includes(substring)) {+ return;+ }++ stub.wrappedMethod.apply(console, args);+ });++ return stub;+}+export function createFile(name, type = "image/png", blobData = null) {// the blob content doesn't matter at all, just want it to be random-ishblobData = blobData || (Math.random() + 1).toString(36).substring(2);diff --git a/plugins/chat/test/javascripts/components/chat-composer-uploads-test.gjs b/plugins/chat/test/javascripts/components/chat-composer-uploads-test.gjsindex 7c51e1c4159..781b4c0aaf3 100644--- a/plugins/chat/test/javascripts/components/chat-composer-uploads-test.gjs+++ b/plugins/chat/test/javascripts/components/chat-composer-uploads-test.gjs@@ -2,7 +2,10 @@ import { click, render, waitFor } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import pretender from "discourse/tests/helpers/create-pretender";-import { createFile } from "discourse/tests/helpers/qunit-helpers";+import {+ createFile,+ silenceConsoleErrorsMatching,+} from "discourse/tests/helpers/qunit-helpers";import ChatComposerUploads from "discourse/plugins/chat/discourse/components/chat-composer-uploads";const fakeUpload = {@@ -113,6 +116,7 @@ module("Discourse Chat | Component | chat-composer-uploads", function (hooks) {});test("cancelling in progress upload", async function (assert) {+ silenceConsoleErrorsMatching("[Uppy]");setupUploadPretender();this.set("changedUploads", null);