mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 08:43:02 +08:00
DEV: Wait for debounced functions
Modern Ember testing environment requires calling `await settled()` to wait for delayed runloop-aware functions.
This commit is contained in:
parent
80ef210730
commit
ae8c96ed35
|
@ -7,6 +7,7 @@ import {
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { fixture } from "discourse/tests/helpers/qunit-helpers";
|
import { fixture } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||||
|
import { settled } from "@ember/test-helpers";
|
||||||
|
|
||||||
function stubUrls(imageSrcs, attachmentSrcs, otherMediaSrcs) {
|
function stubUrls(imageSrcs, attachmentSrcs, otherMediaSrcs) {
|
||||||
if (!imageSrcs) {
|
if (!imageSrcs) {
|
||||||
|
@ -97,6 +98,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
assert.deepEqual(lookup, {});
|
assert.deepEqual(lookup, {});
|
||||||
|
|
||||||
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
||||||
|
await settled();
|
||||||
|
|
||||||
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
||||||
|
|
||||||
|
@ -143,6 +145,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
test("resolveAllShortUrls - href + src replaced correctly", async function (assert) {
|
test("resolveAllShortUrls - href + src replaced correctly", async function (assert) {
|
||||||
stubUrls();
|
stubUrls();
|
||||||
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
||||||
|
await settled();
|
||||||
|
|
||||||
let image1 = fixture().find("img").eq(0);
|
let image1 = fixture().find("img").eq(0);
|
||||||
let image2 = fixture().find("img").eq(1);
|
let image2 = fixture().find("img").eq(1);
|
||||||
|
@ -166,6 +169,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
test("resolveAllShortUrls - url with full origin replaced correctly", async function (assert) {
|
test("resolveAllShortUrls - url with full origin replaced correctly", async function (assert) {
|
||||||
stubUrls();
|
stubUrls();
|
||||||
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]);
|
||||||
|
await settled();
|
||||||
let video = fixture().find("video").eq(1);
|
let video = fixture().find("video").eq(1);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@ -187,6 +191,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
await resolveAllShortUrls(ajax, { secure_media: true }, fixture()[0]);
|
await resolveAllShortUrls(ajax, { secure_media: true }, fixture()[0]);
|
||||||
|
await settled();
|
||||||
|
|
||||||
let link = fixture().find("a");
|
let link = fixture().find("a");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@ -201,6 +206,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
|
|
||||||
let scopedElement = fixture()[0].querySelector(".scoped-area");
|
let scopedElement = fixture()[0].querySelector(".scoped-area");
|
||||||
await resolveAllShortUrls(ajax, {}, scopedElement);
|
await resolveAllShortUrls(ajax, {}, scopedElement);
|
||||||
|
await settled();
|
||||||
|
|
||||||
lookup = lookupCachedUploadUrl("upload://z.jpeg");
|
lookup = lookupCachedUploadUrl("upload://z.jpeg");
|
||||||
|
|
||||||
|
@ -213,6 +219,7 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
|
||||||
// just the ones being looked up (like the normal behaviour)
|
// just the ones being looked up (like the normal behaviour)
|
||||||
resetCache();
|
resetCache();
|
||||||
await resolveAllShortUrls(ajax, {}, scopedElement);
|
await resolveAllShortUrls(ajax, {}, scopedElement);
|
||||||
|
await settled();
|
||||||
|
|
||||||
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
||||||
assert.deepEqual(lookup, {});
|
assert.deepEqual(lookup, {});
|
||||||
|
|
|
@ -26,6 +26,9 @@ define("@ember/test-helpers", () => {
|
||||||
getApplication() {
|
getApplication() {
|
||||||
return _app;
|
return _app;
|
||||||
},
|
},
|
||||||
|
async settled() {
|
||||||
|
// No-op in pre ember-cli environment
|
||||||
|
},
|
||||||
};
|
};
|
||||||
["click", "visit", "currentURL", "fillIn", "setResolver"].forEach((attr) => {
|
["click", "visit", "currentURL", "fillIn", "setResolver"].forEach((attr) => {
|
||||||
helpers[attr] = function () {
|
helpers[attr] = function () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user