This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/lib/oneboxer-test.js
Robin Ward 942ee1e218
FIX: Tests were broken in Firefox (#12456)
There are a lot of little fixes to tests here, but the biggest issue was
too much recursion because we kept replacing the helpers over and over
again. I assume Chrome has tail recursion or something to speed this up
but Firefox hated it.

Otherwise, we can't rely on the order of attributes in rendered HTML so
I simplified most of those tests to just look for key strings in the
HTML that are rendered.
2021-03-22 11:35:51 +11:00

54 lines
1.4 KiB
JavaScript

import { failedCache, localCache } from "pretty-text/oneboxer-cache";
import { module, test } from "qunit";
import { ajax } from "discourse/lib/ajax";
import { load } from "pretty-text/oneboxer";
function loadOnebox(element) {
return load({
elem: element,
refresh: false,
ajax,
synchronous: true,
categoryId: 1,
topicId: 1,
});
}
module("Unit | Utility | oneboxer", function () {
test("load - failed onebox", async function (assert) {
let element = document.createElement("A");
element.setAttribute("href", "http://somebadurl.com");
await loadOnebox(element);
assert.equal(
failedCache["http://somebadurl.com"],
true,
"stores the url as failed in a cache"
);
assert.equal(
loadOnebox(element),
undefined,
"it returns early for a failed cache"
);
});
test("load - successful onebox", async function (assert) {
let element = document.createElement("A");
element.setAttribute("href", "http://somegoodurl.com");
await loadOnebox(element);
assert.ok(
localCache["http://somegoodurl.com"]
.prop("outerHTML")
.indexOf("Yet another collaboration tool") !== -1,
"stores the html of the onebox in a local cache"
);
assert.ok(
loadOnebox(element).indexOf("Yet another collaboration tool") !== -1,
"it returns the html from the cache"
);
});
});