We used many global functions to handle tests when they should be imported like other libraries in our application. This also gets us closer to the way Ember CLI prefers our tests to be laid out.
96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
import { test, module } from "qunit";
|
|
import {
|
|
default as getURL,
|
|
setupURL,
|
|
setupS3CDN,
|
|
getURLWithCDN,
|
|
isAbsoluteURL,
|
|
getAbsoluteURL,
|
|
setPrefix,
|
|
withoutPrefix,
|
|
} from "discourse-common/lib/get-url";
|
|
|
|
module("lib:get-url");
|
|
|
|
test("isAbsoluteURL", (assert) => {
|
|
setupURL(null, "https://example.com", "/forum");
|
|
assert.ok(isAbsoluteURL("https://example.com/test/thing"));
|
|
assert.ok(!isAbsoluteURL("http://example.com/test/thing"));
|
|
assert.ok(!isAbsoluteURL("https://discourse.org/test/thing"));
|
|
});
|
|
|
|
test("getAbsoluteURL", (assert) => {
|
|
setupURL(null, "https://example.com", "/forum");
|
|
assert.equal(getAbsoluteURL("/cool/path"), "https://example.com/cool/path");
|
|
});
|
|
|
|
test("withoutPrefix", (assert) => {
|
|
setPrefix("/eviltrout");
|
|
assert.equal(withoutPrefix("/eviltrout/hello"), "/hello");
|
|
assert.equal(withoutPrefix("/eviltrout/"), "/");
|
|
assert.equal(withoutPrefix("/eviltrout"), "");
|
|
|
|
setPrefix("");
|
|
assert.equal(withoutPrefix("/eviltrout/hello"), "/eviltrout/hello");
|
|
assert.equal(withoutPrefix("/eviltrout"), "/eviltrout");
|
|
assert.equal(withoutPrefix("/"), "/");
|
|
|
|
setPrefix(null);
|
|
assert.equal(withoutPrefix("/eviltrout/hello"), "/eviltrout/hello");
|
|
assert.equal(withoutPrefix("/eviltrout"), "/eviltrout");
|
|
assert.equal(withoutPrefix("/"), "/");
|
|
});
|
|
|
|
test("getURL with empty paths", (assert) => {
|
|
setupURL(null, "https://example.com", "/");
|
|
assert.equal(getURL("/"), "/");
|
|
assert.equal(getURL(""), "");
|
|
setupURL(null, "https://example.com", "");
|
|
assert.equal(getURL("/"), "/");
|
|
assert.equal(getURL(""), "");
|
|
setupURL(null, "https://example.com", undefined);
|
|
assert.equal(getURL("/"), "/");
|
|
assert.equal(getURL(""), "");
|
|
});
|
|
|
|
test("getURL on subfolder install", (assert) => {
|
|
setupURL(null, "", "/forum");
|
|
assert.equal(getURL("/"), "/forum/", "root url has subfolder");
|
|
assert.equal(
|
|
getURL("/u/neil"),
|
|
"/forum/u/neil",
|
|
"relative url has subfolder"
|
|
);
|
|
|
|
assert.equal(
|
|
getURL(""),
|
|
"/forum",
|
|
"relative url has subfolder without trailing slash"
|
|
);
|
|
|
|
assert.equal(
|
|
getURL("/svg-sprite/forum.example.com/svg-sprite.js"),
|
|
"/forum/svg-sprite/forum.example.com/svg-sprite.js",
|
|
"works when the url has the prefix in the middle"
|
|
);
|
|
|
|
assert.equal(
|
|
getURL("/forum/t/123"),
|
|
"/forum/t/123",
|
|
"does not prefix if the URL is already prefixed"
|
|
);
|
|
});
|
|
|
|
test("getURLWithCDN on subfolder install with S3", (assert) => {
|
|
setupURL(null, "", "/forum");
|
|
setupS3CDN(
|
|
"//test.s3-us-west-1.amazonaws.com/site",
|
|
"https://awesome.cdn/site"
|
|
);
|
|
|
|
let url = "//test.s3-us-west-1.amazonaws.com/site/forum/awesome.png";
|
|
let expected = "https://awesome.cdn/site/forum/awesome.png";
|
|
|
|
assert.equal(getURLWithCDN(url), expected, "at correct path");
|
|
});
|