mirror of
https://github.com/discourse/discourse.git
synced 2025-03-02 23:45:22 +08:00

* DEV: Remove server global test variable * Delete yarn-error.log * prettier and some eslint fixes * add global server variable back for plugins * rename imported server to pretender * prettier * support plugin server. usage * Export pretender as named * Prettier * change default pretender export * fix bad import * Use pretender() and original default export * export new Pretender as default * fix accidental change * WIP testing * add pretend handlers in correct location * move more stuff into the correct pretender * Consolidated more pretenders * comment out another bad test * fix user acceptance tests * commented out bad test * fixed another composer server stub * fix more tests * fixed tag test pretender * Fix admin email test * removed another draft handler * add back test * fix and uncomment another test * remove test that is not useful * remove commented out lines * reapply handlers between every test * no need to re-stub requests now :) * cleanup from review * more cleanup
108 lines
2.8 KiB
JavaScript
108 lines
2.8 KiB
JavaScript
import {
|
|
lookupCachedUploadUrl,
|
|
resolveAllShortUrls,
|
|
resetCache
|
|
} from "pretty-text/upload-short-url";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { fixture } from "helpers/qunit-helpers";
|
|
import pretender from "helpers/create-pretender";
|
|
|
|
QUnit.module("lib:pretty-text/upload-short-url", {
|
|
beforeEach() {
|
|
const response = object => {
|
|
return [200, { "Content-Type": "application/json" }, object];
|
|
};
|
|
|
|
const imageSrcs = [
|
|
{
|
|
short_url: "upload://a.jpeg",
|
|
url: "/uploads/default/original/3X/c/b/1.jpeg",
|
|
short_path: "/uploads/short-url/a.jpeg"
|
|
},
|
|
{
|
|
short_url: "upload://b.jpeg",
|
|
url: "/uploads/default/original/3X/c/b/2.jpeg",
|
|
short_path: "/uploads/short-url/b.jpeg"
|
|
}
|
|
];
|
|
|
|
const attachmentSrcs = [
|
|
{
|
|
short_url: "upload://c.pdf",
|
|
url: "/uploads/default/original/3X/c/b/3.pdf",
|
|
short_path: "/uploads/short-url/c.pdf"
|
|
}
|
|
];
|
|
|
|
const otherMediaSrcs = [
|
|
{
|
|
short_url: "upload://d.mp4",
|
|
url: "/uploads/default/original/3X/c/b/4.mp4",
|
|
short_path: "/uploads/short-url/d.mp4"
|
|
},
|
|
{
|
|
short_url: "upload://e.mp3",
|
|
url: "/uploads/default/original/3X/c/b/5.mp3",
|
|
short_path: "/uploads/short-url/e.mp3"
|
|
}
|
|
];
|
|
|
|
pretender.post("/uploads/lookup-urls", () => {
|
|
return response(imageSrcs.concat(attachmentSrcs.concat(otherMediaSrcs)));
|
|
});
|
|
|
|
fixture().html(
|
|
imageSrcs.map(src => `<img data-orig-src="${src.url}">`).join("") +
|
|
attachmentSrcs.map(src => `<a data-orig-href="${src.url}">`).join("")
|
|
);
|
|
},
|
|
|
|
afterEach() {
|
|
resetCache();
|
|
}
|
|
});
|
|
|
|
QUnit.test("resolveAllShortUrls", async assert => {
|
|
let lookup;
|
|
|
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
|
assert.deepEqual(lookup, {});
|
|
|
|
await resolveAllShortUrls(ajax);
|
|
|
|
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
|
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/1.jpeg",
|
|
short_path: "/uploads/short-url/a.jpeg"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://b.jpeg");
|
|
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/2.jpeg",
|
|
short_path: "/uploads/short-url/b.jpeg"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://c.jpeg");
|
|
assert.deepEqual(lookup, {});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://c.pdf");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/3.pdf",
|
|
short_path: "/uploads/short-url/c.pdf"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://d.mp4");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/4.mp4",
|
|
short_path: "/uploads/short-url/d.mp4"
|
|
});
|
|
|
|
lookup = lookupCachedUploadUrl("upload://e.mp3");
|
|
assert.deepEqual(lookup, {
|
|
url: "/uploads/default/original/3X/c/b/5.mp3",
|
|
short_path: "/uploads/short-url/e.mp3"
|
|
});
|
|
});
|