discourse/test/javascripts/lib/url-test.js.es6

40 lines
2.0 KiB
Plaintext
Raw Normal View History

import { default as DiscourseURL, userPath } from 'discourse/lib/url';
2015-08-10 17:11:27 -04:00
2017-06-14 13:57:58 -04:00
QUnit.module("lib:url");
2017-06-14 13:57:58 -04:00
QUnit.test("isInternal with a HTTP url", assert => {
2015-08-10 17:11:27 -04:00
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com");
2017-06-14 13:57:58 -04:00
assert.not(DiscourseURL.isInternal(null), "a blank URL is not internal");
assert.ok(DiscourseURL.isInternal("/test"), "relative URLs are internal");
assert.ok(DiscourseURL.isInternal("//eviltrout.com"), "a url on the same host is internal (protocol-less)");
assert.ok(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host is internal");
assert.ok(DiscourseURL.isInternal("https://eviltrout.com/moustache"), "a url on a HTTPS of the same host is internal");
assert.not(DiscourseURL.isInternal("//twitter.com.com"), "a different host is not internal (protocol-less)");
assert.not(DiscourseURL.isInternal("http://twitter.com"), "a different host is not internal");
});
2017-06-14 13:57:58 -04:00
QUnit.test("isInternal with a HTTPS url", assert => {
2015-08-10 17:11:27 -04:00
sandbox.stub(DiscourseURL, "origin").returns("https://eviltrout.com");
2017-06-14 13:57:58 -04:00
assert.ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls");
});
2017-06-14 13:57:58 -04:00
QUnit.test("isInternal on subfolder install", assert => {
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com/forum");
2017-06-14 13:57:58 -04:00
assert.not(DiscourseURL.isInternal("http://eviltrout.com"), "the host root is not internal");
assert.not(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host but on a different folder is not internal");
assert.ok(DiscourseURL.isInternal("http://eviltrout.com/forum/moustache"), "a url on the same host and on the same folder is internal");
});
2017-06-14 13:57:58 -04:00
QUnit.test("userPath", assert => {
assert.equal(userPath(), '/u');
assert.equal(userPath('eviltrout'), '/u/eviltrout');
assert.equal(userPath('hp.json'), '/u/hp.json');
});
2017-03-29 12:24:46 -04:00
2017-06-14 13:57:58 -04:00
QUnit.test("userPath with BaseUri", assert => {
2017-03-29 12:24:46 -04:00
Discourse.BaseUri = "/forum";
assert.equal(userPath(), '/forum/u');
assert.equal(userPath('eviltrout'), '/forum/u/eviltrout');
assert.equal(userPath('hp.json'), '/forum/u/hp.json');
2017-06-14 13:57:58 -04:00
});