mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Upgrade QUnit to latest version
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import createStore from 'helpers/create-store';
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
|
||||
module("lib:category-link");
|
||||
QUnit.module("lib:category-link");
|
||||
|
||||
import parseHTML from 'helpers/parse-html';
|
||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||
|
||||
test("categoryBadge without a category", function() {
|
||||
blank(categoryBadgeHTML(), "it returns no HTML");
|
||||
QUnit.test("categoryBadge without a category", assert => {
|
||||
assert.blank(categoryBadgeHTML(), "it returns no HTML");
|
||||
});
|
||||
|
||||
test("Regular categoryBadge", function() {
|
||||
QUnit.test("Regular categoryBadge", assert => {
|
||||
const store = createStore();
|
||||
const category = store.createRecord('category', {
|
||||
name: 'hello',
|
||||
@@ -21,28 +20,28 @@ test("Regular categoryBadge", function() {
|
||||
});
|
||||
const tag = parseHTML(categoryBadgeHTML(category))[0];
|
||||
|
||||
equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
||||
equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
||||
assert.equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
||||
assert.equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
||||
|
||||
const label = tag.children[1];
|
||||
equal(label.attributes.title, 'cool description', 'it has the correct title');
|
||||
assert.equal(label.attributes.title, 'cool description', 'it has the correct title');
|
||||
|
||||
equal(label.children[0].data, 'hello', 'it has the category name');
|
||||
assert.equal(label.children[0].data, 'hello', 'it has the category name');
|
||||
});
|
||||
|
||||
test("undefined color", function() {
|
||||
QUnit.test("undefined color", assert => {
|
||||
const store = createStore();
|
||||
const noColor = store.createRecord('category', { name: 'hello', id: 123 });
|
||||
const tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
||||
|
||||
blank(tag.attributes.style, "it has no color style because there are no colors");
|
||||
assert.blank(tag.attributes.style, "it has no color style because there are no colors");
|
||||
});
|
||||
|
||||
test("allowUncategorized", function() {
|
||||
QUnit.test("allowUncategorized", assert => {
|
||||
const store = createStore();
|
||||
const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345});
|
||||
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
||||
|
||||
blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||
present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
||||
});
|
||||
assert.blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||
assert.present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
@@ -6,8 +5,8 @@ var windowOpen,
|
||||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track-edit-history", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track-edit-history", {
|
||||
beforeEach() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
@@ -56,56 +55,57 @@ var generateClickEventOn = function(selector) {
|
||||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", assert => {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", assert => {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", assert => {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
@@ -115,32 +115,32 @@ var trackRightClick = function(target) {
|
||||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick('a'));
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", assert => {
|
||||
assert.ok(trackRightClick('a'));
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('a');
|
||||
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -160,31 +160,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
||||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
@@ -6,8 +5,8 @@ var windowOpen,
|
||||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track-profile-page", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track-profile-page", {
|
||||
beforeEach() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
@@ -50,56 +49,57 @@ var generateClickEventOn = function(selector) {
|
||||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", assert => {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", assert => {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", assert => {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
@@ -109,38 +109,38 @@ var trackRightClick = function(target) {
|
||||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick('a'));
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", assert => {
|
||||
assert.ok(trackRightClick('a'));
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('a');
|
||||
equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("right clicks are tracked for second excerpt", function() {
|
||||
QUnit.test("right clicks are tracked for second excerpt", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('.second a');
|
||||
equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
assert.equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -160,44 +160,44 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
||||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('.second a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('.second a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
@@ -6,8 +5,8 @@ var windowOpen,
|
||||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track", {
|
||||
beforeEach() {
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
redirectTo = sandbox.stub(DiscourseURL, "redirectTo");
|
||||
@@ -47,87 +46,88 @@ var generateClickEventOn = function(selector) {
|
||||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", function(assert) {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks in quotes", function() {
|
||||
ok(track(generateClickEventOn('.inside-quote')));
|
||||
QUnit.test("does not track clicks in quotes", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.inside-quote')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("does not track clicks on mailto", function() {
|
||||
ok(track(generateClickEventOn('.mailto')));
|
||||
QUnit.test("does not track clicks on mailto", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.mailto')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", function(assert) {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
var badgeClickCount = function(id, expected) {
|
||||
var badgeClickCount = function(assert, id, expected) {
|
||||
track(generateClickEventOn('#' + id));
|
||||
var $badge = $('span.badge', fixture('#' + id).first());
|
||||
equal(parseInt($badge.html(), 10), expected);
|
||||
assert.equal(parseInt($badge.html(), 10), expected);
|
||||
};
|
||||
|
||||
test("does not update badge clicks on my own link", function() {
|
||||
QUnit.test("does not update badge clicks on my own link", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(314);
|
||||
badgeClickCount('with-badge', 1);
|
||||
badgeClickCount(assert, 'with-badge', 1);
|
||||
});
|
||||
|
||||
test("does not update badge clicks in my own post", function() {
|
||||
QUnit.test("does not update badge clicks in my own post", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(3141);
|
||||
badgeClickCount('with-badge-but-not-mine', 1);
|
||||
badgeClickCount(assert, 'with-badge-but-not-mine', 1);
|
||||
});
|
||||
|
||||
test("updates badge counts correctly", function() {
|
||||
badgeClickCount('inside-onebox', 1);
|
||||
badgeClickCount('inside-onebox-forced', 2);
|
||||
badgeClickCount('with-badge', 2);
|
||||
QUnit.test("updates badge counts correctly", function(assert) {
|
||||
badgeClickCount(assert, 'inside-onebox', 1);
|
||||
badgeClickCount(assert, 'inside-onebox-forced', 2);
|
||||
badgeClickCount(assert, 'with-badge', 2);
|
||||
});
|
||||
|
||||
var trackRightClick = function() {
|
||||
@@ -136,32 +136,32 @@ var trackRightClick = function() {
|
||||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick());
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", function(assert) {
|
||||
assert.ok(trackRightClick());
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", function(assert) {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick();
|
||||
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -181,31 +181,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
||||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", function(assert) {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", function(assert) {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { setting, propertyEqual, propertyNotEqual, fmt, i18n, url } from 'discourse/lib/computed';
|
||||
|
||||
module("lib:computed", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:computed", {
|
||||
beforeEach() {
|
||||
sandbox.stub(I18n, "t", function(scope) {
|
||||
return "%@ translated: " + scope;
|
||||
});
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
I18n.t.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("setting", function() {
|
||||
QUnit.test("setting", assert => {
|
||||
var t = Em.Object.extend({
|
||||
vehicle: setting('vehicle'),
|
||||
missingProp: setting('madeUpThing')
|
||||
}).create();
|
||||
|
||||
Discourse.SiteSettings.vehicle = "airplane";
|
||||
equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
assert.equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
assert.ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
});
|
||||
|
||||
test("propertyEqual", function() {
|
||||
QUnit.test("propertyEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
same: propertyEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
@@ -31,12 +31,12 @@ test("propertyEqual", function() {
|
||||
biscuits: 10
|
||||
});
|
||||
|
||||
ok(t.get('same'), "it is true when the properties are the same");
|
||||
assert.ok(t.get('same'), "it is true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
ok(!t.get('same'), "it isn't true when one property is different");
|
||||
assert.ok(!t.get('same'), "it isn't true when one property is different");
|
||||
});
|
||||
|
||||
test("propertyNotEqual", function() {
|
||||
QUnit.test("propertyNotEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
diff: propertyNotEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
@@ -44,13 +44,13 @@ test("propertyNotEqual", function() {
|
||||
biscuits: 10
|
||||
});
|
||||
|
||||
ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
assert.ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
ok(t.get('diff'), "it is true when one property is different");
|
||||
assert.ok(t.get('diff'), "it is true when one property is different");
|
||||
});
|
||||
|
||||
|
||||
test("fmt", function() {
|
||||
QUnit.test("fmt", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: fmt('username', "!!! %@ !!!"),
|
||||
multiple: fmt('username', 'mood', "%@ is %@")
|
||||
@@ -59,17 +59,17 @@ test("fmt", function() {
|
||||
mood: "happy"
|
||||
});
|
||||
|
||||
equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
||||
equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
||||
assert.equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
||||
assert.equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
||||
assert.equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
||||
assert.equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
||||
});
|
||||
|
||||
|
||||
test("i18n", function() {
|
||||
QUnit.test("i18n", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: i18n('username', "!!! %@ !!!"),
|
||||
multiple: i18n('username', 'mood', "%@ is %@")
|
||||
@@ -78,17 +78,17 @@ test("i18n", function() {
|
||||
mood: "happy"
|
||||
});
|
||||
|
||||
equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
||||
equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
||||
assert.equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
||||
assert.equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
||||
});
|
||||
|
||||
|
||||
test("url", function() {
|
||||
QUnit.test("url", assert => {
|
||||
var t, testClass;
|
||||
|
||||
testClass = Em.Object.extend({
|
||||
@@ -96,9 +96,9 @@ test("url", function() {
|
||||
});
|
||||
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix");
|
||||
assert.equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix");
|
||||
|
||||
Discourse.BaseUri = "/prefixed";
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix");
|
||||
assert.equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix");
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module("lib:discourse");
|
||||
QUnit.module("lib:discourse");
|
||||
|
||||
test("getURL on subfolder install", function() {
|
||||
QUnit.test("getURL on subfolder install", assert => {
|
||||
Discourse.BaseUri = "/forum";
|
||||
equal(Discourse.getURL("/"), "/forum/", "root url has subfolder");
|
||||
equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder");
|
||||
});
|
||||
assert.equal(Discourse.getURL("/"), "/forum/", "root url has subfolder");
|
||||
assert.equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder");
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import { emojiSearch, IMAGE_VERSION as v } from 'pretty-text/emoji';
|
||||
import { emojiUnescape } from 'discourse/lib/text';
|
||||
|
||||
module('lib:emoji');
|
||||
QUnit.module('lib:emoji');
|
||||
|
||||
function testUnescape(input, expected, description) {
|
||||
equal(emojiUnescape(input), expected, description);
|
||||
};
|
||||
QUnit.test("emojiUnescape", assert => {
|
||||
const testUnescape = (input, expected, description) => {
|
||||
assert.equal(emojiUnescape(input), expected, description);
|
||||
};
|
||||
|
||||
test("emojiUnescape", () => {
|
||||
testUnescape("Not emoji :O) :frog) :smile)", "Not emoji :O) :frog) :smile)", "title without emoji");
|
||||
testUnescape("Not emoji :frog :smile", "Not emoji :frog :smile", "end colon is not optional");
|
||||
testUnescape("emoticons :)", `emoticons <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'>`, "emoticons are still supported");
|
||||
@@ -24,11 +24,11 @@ test("emojiUnescape", () => {
|
||||
|
||||
});
|
||||
|
||||
test("Emoji search", () => {
|
||||
QUnit.test("Emoji search", assert => {
|
||||
// able to find an alias
|
||||
equal(emojiSearch("+1").length, 1);
|
||||
assert.equal(emojiSearch("+1").length, 1);
|
||||
|
||||
// able to find middle of line search
|
||||
equal(emojiSearch("check", {maxResults: 3}).length, 3);
|
||||
assert.equal(emojiSearch("check", {maxResults: 3}).length, 3);
|
||||
|
||||
});
|
||||
|
||||
@@ -2,12 +2,12 @@ var clock;
|
||||
|
||||
import { relativeAge, autoUpdatingRelativeAge, updateRelativeAge, breakUp, number, longDate } from 'discourse/lib/formatter';
|
||||
|
||||
module("lib:formatter", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:formatter", {
|
||||
beforeEach() {
|
||||
clock = sinon.useFakeTimers(new Date(2012,11,31,12,0).getTime());
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
clock.restore();
|
||||
}
|
||||
});
|
||||
@@ -34,7 +34,7 @@ var shortDate = function(days){
|
||||
return moment().subtract(days, 'days').format('MMM D');
|
||||
};
|
||||
|
||||
test("formating medium length dates", function() {
|
||||
QUnit.test("formating medium length dates", assert => {
|
||||
|
||||
format = "medium";
|
||||
var strip = function(html){
|
||||
@@ -46,133 +46,133 @@ test("formating medium length dates", function() {
|
||||
};
|
||||
|
||||
leaveAgo = true;
|
||||
equal(strip(formatMins(1.4)), "1 min ago");
|
||||
equal(strip(formatMins(2)), "2 mins ago");
|
||||
equal(strip(formatMins(55)), "55 mins ago");
|
||||
equal(strip(formatMins(56)), "1 hour ago");
|
||||
equal(strip(formatHours(4)), "4 hours ago");
|
||||
equal(strip(formatHours(22)), "22 hours ago");
|
||||
equal(strip(formatHours(23)), "23 hours ago");
|
||||
equal(strip(formatHours(23.5)), "1 day ago");
|
||||
equal(strip(formatDays(4.85)), "4 days ago");
|
||||
assert.equal(strip(formatMins(1.4)), "1 min ago");
|
||||
assert.equal(strip(formatMins(2)), "2 mins ago");
|
||||
assert.equal(strip(formatMins(55)), "55 mins ago");
|
||||
assert.equal(strip(formatMins(56)), "1 hour ago");
|
||||
assert.equal(strip(formatHours(4)), "4 hours ago");
|
||||
assert.equal(strip(formatHours(22)), "22 hours ago");
|
||||
assert.equal(strip(formatHours(23)), "23 hours ago");
|
||||
assert.equal(strip(formatHours(23.5)), "1 day ago");
|
||||
assert.equal(strip(formatDays(4.85)), "4 days ago");
|
||||
|
||||
leaveAgo = false;
|
||||
equal(strip(formatMins(0)), "just now");
|
||||
equal(strip(formatMins(1.4)), "1 min");
|
||||
equal(strip(formatMins(2)), "2 mins");
|
||||
equal(strip(formatMins(55)), "55 mins");
|
||||
equal(strip(formatMins(56)), "1 hour");
|
||||
equal(strip(formatHours(4)), "4 hours");
|
||||
equal(strip(formatHours(22)), "22 hours");
|
||||
equal(strip(formatHours(23)), "23 hours");
|
||||
equal(strip(formatHours(23.5)), "1 day");
|
||||
equal(strip(formatDays(4.85)), "4 days");
|
||||
assert.equal(strip(formatMins(0)), "just now");
|
||||
assert.equal(strip(formatMins(1.4)), "1 min");
|
||||
assert.equal(strip(formatMins(2)), "2 mins");
|
||||
assert.equal(strip(formatMins(55)), "55 mins");
|
||||
assert.equal(strip(formatMins(56)), "1 hour");
|
||||
assert.equal(strip(formatHours(4)), "4 hours");
|
||||
assert.equal(strip(formatHours(22)), "22 hours");
|
||||
assert.equal(strip(formatHours(23)), "23 hours");
|
||||
assert.equal(strip(formatHours(23.5)), "1 day");
|
||||
assert.equal(strip(formatDays(4.85)), "4 days");
|
||||
|
||||
equal(strip(formatDays(6)), shortDate(6));
|
||||
equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23
|
||||
equal(strip(formatDays(500)), shortDateYear(500));
|
||||
assert.equal(strip(formatDays(6)), shortDate(6));
|
||||
assert.equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23
|
||||
assert.equal(strip(formatDays(500)), shortDateYear(500));
|
||||
|
||||
equal($(formatDays(0)).attr("title"), longDate(new Date()));
|
||||
equal($(formatDays(0)).attr("class"), "date");
|
||||
assert.equal($(formatDays(0)).attr("title"), longDate(new Date()));
|
||||
assert.equal($(formatDays(0)).attr("class"), "date");
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,9,12,0).getTime()); // Jan 9, 2012
|
||||
|
||||
equal(strip(formatDays(8)), shortDate(8));
|
||||
equal(strip(formatDays(10)), shortDateYear(10));
|
||||
assert.equal(strip(formatDays(8)), shortDate(8));
|
||||
assert.equal(strip(formatDays(10)), shortDateYear(10));
|
||||
});
|
||||
|
||||
test("formating tiny dates", function() {
|
||||
QUnit.test("formating tiny dates", assert => {
|
||||
var shortDateYear = function(days){
|
||||
return moment().subtract(days, 'days').format("MMM 'YY");
|
||||
};
|
||||
|
||||
format = "tiny";
|
||||
equal(formatMins(0), "1m");
|
||||
equal(formatMins(1), "1m");
|
||||
equal(formatMins(2), "2m");
|
||||
equal(formatMins(60), "1h");
|
||||
equal(formatHours(4), "4h");
|
||||
equal(formatHours(23), "23h");
|
||||
equal(formatHours(23.5), "1d");
|
||||
equal(formatDays(1), "1d");
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDate(15));
|
||||
equal(formatDays(92), shortDate(92));
|
||||
equal(formatDays(364), shortDate(364));
|
||||
equal(formatDays(365), shortDate(365));
|
||||
equal(formatDays(366), shortDateYear(366)); // leap year
|
||||
equal(formatDays(500), shortDateYear(500));
|
||||
equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year
|
||||
assert.equal(formatMins(0), "1m");
|
||||
assert.equal(formatMins(1), "1m");
|
||||
assert.equal(formatMins(2), "2m");
|
||||
assert.equal(formatMins(60), "1h");
|
||||
assert.equal(formatHours(4), "4h");
|
||||
assert.equal(formatHours(23), "23h");
|
||||
assert.equal(formatHours(23.5), "1d");
|
||||
assert.equal(formatDays(1), "1d");
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(92), shortDate(92));
|
||||
assert.equal(formatDays(364), shortDate(364));
|
||||
assert.equal(formatDays(365), shortDate(365));
|
||||
assert.equal(formatDays(366), shortDateYear(366)); // leap year
|
||||
assert.equal(formatDays(500), shortDateYear(500));
|
||||
assert.equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year
|
||||
|
||||
var originalValue = Discourse.SiteSettings.relative_date_duration;
|
||||
Discourse.SiteSettings.relative_date_duration = 7;
|
||||
equal(formatDays(7), "7d");
|
||||
equal(formatDays(8), shortDate(8));
|
||||
assert.equal(formatDays(7), "7d");
|
||||
assert.equal(formatDays(8), shortDate(8));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 1;
|
||||
equal(formatDays(1), "1d");
|
||||
equal(formatDays(2), shortDate(2));
|
||||
assert.equal(formatDays(1), "1d");
|
||||
assert.equal(formatDays(2), shortDate(2));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 0;
|
||||
equal(formatMins(0), "1m");
|
||||
equal(formatMins(1), "1m");
|
||||
equal(formatMins(2), "2m");
|
||||
equal(formatMins(60), "1h");
|
||||
equal(formatDays(1), shortDate(1));
|
||||
equal(formatDays(2), shortDate(2));
|
||||
equal(formatDays(366), shortDateYear(366));
|
||||
assert.equal(formatMins(0), "1m");
|
||||
assert.equal(formatMins(1), "1m");
|
||||
assert.equal(formatMins(2), "2m");
|
||||
assert.equal(formatMins(60), "1h");
|
||||
assert.equal(formatDays(1), shortDate(1));
|
||||
assert.equal(formatDays(2), shortDate(2));
|
||||
assert.equal(formatDays(366), shortDateYear(366));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = null;
|
||||
equal(formatDays(1), '1d');
|
||||
equal(formatDays(14), '14d');
|
||||
equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(1), '1d');
|
||||
assert.equal(formatDays(14), '14d');
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 14;
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,12,12,0).getTime()); // Jan 12, 2012
|
||||
|
||||
equal(formatDays(11), "11d");
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDateYear(15));
|
||||
equal(formatDays(366), shortDateYear(366));
|
||||
assert.equal(formatDays(11), "11d");
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDateYear(15));
|
||||
assert.equal(formatDays(366), shortDateYear(366));
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,20,12,0).getTime()); // Jan 20, 2012
|
||||
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDate(15));
|
||||
equal(formatDays(20), shortDateYear(20));
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(20), shortDateYear(20));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = originalValue;
|
||||
});
|
||||
|
||||
test("autoUpdatingRelativeAge", function() {
|
||||
QUnit.test("autoUpdatingRelativeAge", assert => {
|
||||
var d = moment().subtract(1, 'day').toDate();
|
||||
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
equal($elem.data('format'), "tiny");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
assert.equal($elem.data('format'), "tiny");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), undefined);
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d, {title: true}));
|
||||
equal($elem.attr('title'), longDate(d));
|
||||
assert.equal($elem.attr('title'), longDate(d));
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true}));
|
||||
equal($elem.data('format'), "medium-with-ago");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), longDate(d));
|
||||
equal($elem.html(), '1 day ago');
|
||||
assert.equal($elem.data('format'), "medium-with-ago");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), longDate(d));
|
||||
assert.equal($elem.html(), '1 day ago');
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium'}));
|
||||
equal($elem.data('format'), "medium");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
equal($elem.html(), '1 day');
|
||||
assert.equal($elem.data('format'), "medium");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), undefined);
|
||||
assert.equal($elem.html(), '1 day');
|
||||
});
|
||||
|
||||
test("updateRelativeAge", function(){
|
||||
QUnit.test("updateRelativeAge", assert =>{
|
||||
|
||||
var d = new Date();
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
@@ -180,7 +180,7 @@ test("updateRelativeAge", function(){
|
||||
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2m");
|
||||
assert.equal($elem.html(), "2m");
|
||||
|
||||
d = new Date();
|
||||
$elem = $(autoUpdatingRelativeAge(d, {format: 'medium', leaveAgo: true}));
|
||||
@@ -188,27 +188,27 @@ test("updateRelativeAge", function(){
|
||||
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2 mins ago");
|
||||
assert.equal($elem.html(), "2 mins ago");
|
||||
});
|
||||
|
||||
test("breakUp", function(){
|
||||
QUnit.test("breakUp", assert =>{
|
||||
|
||||
var b = function(s,hint){ return breakUp(s,hint); };
|
||||
|
||||
equal(b("hello"), "hello");
|
||||
equal(b("helloworld"), "helloworld");
|
||||
equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
||||
equal(b("he_man"), "he_<wbr>​man");
|
||||
equal(b("he11111"), "he<wbr>​11111");
|
||||
equal(b("HRCBob"), "HRC<wbr>​Bob");
|
||||
equal(b("bobmarleytoo","Bob Marley Too"), "bob<wbr>​marley<wbr>​too");
|
||||
assert.equal(b("hello"), "hello");
|
||||
assert.equal(b("helloworld"), "helloworld");
|
||||
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
||||
assert.equal(b("he_man"), "he_<wbr>​man");
|
||||
assert.equal(b("he11111"), "he<wbr>​11111");
|
||||
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
||||
assert.equal(b("bobmarleytoo","Bob Marley Too"), "bob<wbr>​marley<wbr>​too");
|
||||
|
||||
});
|
||||
|
||||
test("number", function() {
|
||||
equal(number(123), "123", "it returns a string version of the number");
|
||||
equal(number("123"), "123", "it works with a string command");
|
||||
equal(number(NaN), "0", "it returns 0 for NaN");
|
||||
equal(number(3333), "3.3k", "it abbreviates thousands");
|
||||
equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
});
|
||||
QUnit.test("number", assert => {
|
||||
assert.equal(number(123), "123", "it returns a string version of the number");
|
||||
assert.equal(number("123"), "123", "it works with a string command");
|
||||
assert.equal(number(NaN), "0", "it returns 0 for NaN");
|
||||
assert.equal(number(3333), "3.3k", "it abbreviates thousands");
|
||||
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
module("lib:i18n", {
|
||||
QUnit.module("lib:i18n", {
|
||||
_locale: I18n.locale,
|
||||
_translations: I18n.translations,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
I18n.locale = "fr";
|
||||
|
||||
I18n.translations = {
|
||||
@@ -54,42 +54,42 @@ module("lib:i18n", {
|
||||
};
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
I18n.locale = this._locale;
|
||||
I18n.translations = this._translations;
|
||||
}
|
||||
});
|
||||
|
||||
test("defaults", function() {
|
||||
equal(I18n.defaultLocale, "en", "it has English as default locale");
|
||||
ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
||||
QUnit.test("defaults", assert => {
|
||||
assert.equal(I18n.defaultLocale, "en", "it has English as default locale");
|
||||
assert.ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
||||
});
|
||||
|
||||
test("translations", function() {
|
||||
equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
||||
equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
||||
equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
||||
equal(I18n.t("hello.universe"), "", "allows empty strings");
|
||||
QUnit.test("translations", assert => {
|
||||
assert.equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
||||
assert.equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
||||
assert.equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
||||
assert.equal(I18n.t("hello.universe"), "", "allows empty strings");
|
||||
});
|
||||
|
||||
test("extra translations", function() {
|
||||
QUnit.test("extra translations", assert => {
|
||||
I18n.extras = [{ "admin": { "title": "Discourse Admin" }}];
|
||||
|
||||
equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||
assert.equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||
});
|
||||
|
||||
test("pluralizations", function() {
|
||||
equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
||||
equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
||||
equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
||||
equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
||||
equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
||||
equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
||||
QUnit.test("pluralizations", assert => {
|
||||
assert.equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
||||
assert.equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
||||
assert.equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
||||
assert.equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
||||
assert.equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
||||
assert.equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
||||
|
||||
equal(I18n.t("word_count", { count: 0 }), "0 words");
|
||||
equal(I18n.t("word_count", { count: 1 }), "1 word");
|
||||
equal(I18n.t("word_count", { count: 2 }), "2 words");
|
||||
equal(I18n.t("word_count", { count: 3 }), "3 words");
|
||||
equal(I18n.t("word_count", { count: 10 }), "10 words");
|
||||
equal(I18n.t("word_count", { count: 100 }), "100 words");
|
||||
});
|
||||
assert.equal(I18n.t("word_count", { count: 0 }), "0 words");
|
||||
assert.equal(I18n.t("word_count", { count: 1 }), "1 word");
|
||||
assert.equal(I18n.t("word_count", { count: 2 }), "2 words");
|
||||
assert.equal(I18n.t("word_count", { count: 3 }), "3 words");
|
||||
assert.equal(I18n.t("word_count", { count: 10 }), "10 words");
|
||||
assert.equal(I18n.t("word_count", { count: 100 }), "100 words");
|
||||
});
|
||||
@@ -1,18 +1,18 @@
|
||||
import KeyValueStore from "discourse/lib/key-value-store";
|
||||
|
||||
module("lib:key-value-store");
|
||||
QUnit.module("lib:key-value-store");
|
||||
|
||||
test("it's able to get the result back from the store", (assert) => {
|
||||
QUnit.test("it's able to get the result back from the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob", value: "uncle" });
|
||||
assert.equal(store.get("bob"), "uncle");
|
||||
});
|
||||
|
||||
test("is able to nuke the store", (assert) => {
|
||||
QUnit.test("is able to nuke the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob1", value: "uncle" });
|
||||
store.abandonLocal();
|
||||
localStorage.a = 1;
|
||||
assert.equal(store.get("bob1"), void 0);
|
||||
assert.equal(localStorage.a, "1");
|
||||
});
|
||||
});
|
||||
@@ -1,74 +1,78 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import PreloadStore from 'preload-store';
|
||||
|
||||
module("preload-store", {
|
||||
setup() {
|
||||
QUnit.module("preload-store", {
|
||||
beforeEach() {
|
||||
PreloadStore.store('bane', 'evil');
|
||||
}
|
||||
});
|
||||
|
||||
test("get", function() {
|
||||
blank(PreloadStore.get('joker'), "returns blank for a missing key");
|
||||
equal(PreloadStore.get('bane'), 'evil', "returns the value for that key");
|
||||
QUnit.test("get", assert => {
|
||||
assert.blank(PreloadStore.get('joker'), "returns blank for a missing key");
|
||||
assert.equal(PreloadStore.get('bane'), 'evil', "returns the value for that key");
|
||||
});
|
||||
|
||||
test("remove", function() {
|
||||
QUnit.test("remove", assert => {
|
||||
PreloadStore.remove('bane');
|
||||
blank(PreloadStore.get('bane'), "removes the value if the key exists");
|
||||
assert.blank(PreloadStore.get('bane'), "removes the value if the key exists");
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker').then(function(result) {
|
||||
blank(result);
|
||||
start();
|
||||
assert.blank(result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() { return 'batdance'; };
|
||||
const done = assert.async();
|
||||
const finder = function() { return 'batdance'; };
|
||||
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
||||
equal(result, 'batdance');
|
||||
start();
|
||||
assert.equal(result, 'batdance');
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() {
|
||||
const finder = function() {
|
||||
return new Ember.RSVP.Promise(function(resolve) { resolve('hahahah'); });
|
||||
};
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
||||
equal(result, 'hahahah');
|
||||
start();
|
||||
assert.equal(result, 'hahahah');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() {
|
||||
const finder = function() {
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) { reject('error'); });
|
||||
};
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker', finder).then(null, function(result) {
|
||||
equal(result, 'error');
|
||||
start();
|
||||
assert.equal(result, 'error');
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
asyncTestDiscourse("returns a promise that resolves to 'evil'", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("returns a promise that resolves to 'evil'", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('bane').then(function(result) {
|
||||
equal(result, 'evil');
|
||||
start();
|
||||
assert.equal(result, 'evil');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import Post from 'discourse/models/post';
|
||||
import { default as PrettyText, buildOptions } from 'pretty-text/pretty-text';
|
||||
import { IMAGE_VERSION as v} from 'pretty-text/emoji';
|
||||
|
||||
module("lib:pretty-text");
|
||||
QUnit.module("lib:pretty-text");
|
||||
|
||||
const defaultOpts = buildOptions({
|
||||
siteSettings: {
|
||||
@@ -17,602 +17,614 @@ const defaultOpts = buildOptions({
|
||||
getURL: url => url
|
||||
});
|
||||
|
||||
function cooked(input, expected, text) {
|
||||
equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
QUnit.assert.cooked = function(input, expected, message) {
|
||||
const actual = new PrettyText(defaultOpts).cook(input);
|
||||
this.pushResult({
|
||||
result: actual === expected.replace(/\/>/g, ">"),
|
||||
actual,
|
||||
expected,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function cookedOptions(input, opts, expected, text) {
|
||||
equal(new PrettyText(_.merge({}, defaultOpts, opts)).cook(input), expected, text);
|
||||
QUnit.assert.cookedOptions = function(input, opts, expected, message) {
|
||||
const actual = new PrettyText(_.merge({}, defaultOpts, opts)).cook(input);
|
||||
this.pushResult({
|
||||
result: actual === expected,
|
||||
actual,
|
||||
expected,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function cookedPara(input, expected, text) {
|
||||
cooked(input, `<p>${expected}</p>`, text);
|
||||
QUnit.assert.cookedPara = function(input, expected, message) {
|
||||
QUnit.assert.cooked(input, `<p>${expected}</p>`, message);
|
||||
};
|
||||
|
||||
test("buildOptions", () => {
|
||||
ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled');
|
||||
ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled');
|
||||
QUnit.test("buildOptions", assert => {
|
||||
assert.ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled');
|
||||
|
||||
ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled');
|
||||
ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled');
|
||||
assert.ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled');
|
||||
});
|
||||
|
||||
test("basic cooking", function() {
|
||||
cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
||||
cooked("**evil**", "<p><strong>evil</strong></p>", "it bolds text.");
|
||||
cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
||||
cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
|
||||
cooked("word_with_underscores", "<p>word_with_underscores</p>", "it doesn't do intraword italics");
|
||||
cooked("common/_special_font_face.html.erb", "<p>common/_special_font_face.html.erb</p>", "it doesn't intraword with a slash");
|
||||
cooked("hello \\*evil\\*", "<p>hello *evil*</p>", "it supports escaping of asterisks");
|
||||
cooked("hello \\_evil\\_", "<p>hello _evil_</p>", "it supports escaping of italics");
|
||||
cooked("brussels sprouts are *awful*.", "<p>brussels sprouts are <em>awful</em>.</p>", "it doesn't swallow periods.");
|
||||
QUnit.test("basic cooking", assert => {
|
||||
assert.cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
||||
assert.cooked("**evil**", "<p><strong>evil</strong></p>", "it bolds text.");
|
||||
assert.cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
||||
assert.cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
assert.cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
assert.cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
|
||||
assert.cooked("word_with_underscores", "<p>word_with_underscores</p>", "it doesn't do intraword italics");
|
||||
assert.cooked("common/_special_font_face.html.erb", "<p>common/_special_font_face.html.erb</p>", "it doesn't intraword with a slash");
|
||||
assert.cooked("hello \\*evil\\*", "<p>hello *evil*</p>", "it supports escaping of asterisks");
|
||||
assert.cooked("hello \\_evil\\_", "<p>hello _evil_</p>", "it supports escaping of italics");
|
||||
assert.cooked("brussels sprouts are *awful*.", "<p>brussels sprouts are <em>awful</em>.</p>", "it doesn't swallow periods.");
|
||||
});
|
||||
|
||||
test("Nested bold and italics", function() {
|
||||
cooked("*this is italic **with some bold** inside*", "<p><em>this is italic <strong>with some bold</strong> inside</em></p>", "it handles nested bold in italics");
|
||||
QUnit.test("Nested bold and italics", assert => {
|
||||
assert.cooked("*this is italic **with some bold** inside*", "<p><em>this is italic <strong>with some bold</strong> inside</em></p>", "it handles nested bold in italics");
|
||||
});
|
||||
|
||||
test("Traditional Line Breaks", function() {
|
||||
QUnit.test("Traditional Line Breaks", assert => {
|
||||
const input = "1\n2\n3";
|
||||
cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
assert.cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
|
||||
const result = new PrettyText({ traditionalMarkdownLinebreaks: true }).cook(input);
|
||||
equal(result, "<p>1\n2\n3</p>");
|
||||
assert.equal(result, "<p>1\n2\n3</p>");
|
||||
});
|
||||
|
||||
test("Unbalanced underscores", function() {
|
||||
cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "<p><a href=\"http://eviltrout.com\">evil_trout</a> hello_</p>");
|
||||
QUnit.test("Unbalanced underscores", assert => {
|
||||
assert.cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "<p><a href=\"http://eviltrout.com\">evil_trout</a> hello_</p>");
|
||||
});
|
||||
|
||||
test("Line Breaks", function() {
|
||||
cooked("[] first choice\n[] second choice",
|
||||
QUnit.test("Line Breaks", assert => {
|
||||
assert.cooked("[] first choice\n[] second choice",
|
||||
"<p>[] first choice<br/>[] second choice</p>",
|
||||
"it handles new lines correctly with [] options");
|
||||
|
||||
cooked("<blockquote>evil</blockquote>\ntrout",
|
||||
assert.cooked("<blockquote>evil</blockquote>\ntrout",
|
||||
"<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"it doesn't insert <br> after blockquotes");
|
||||
|
||||
cooked("leading<blockquote>evil</blockquote>\ntrout",
|
||||
assert.cooked("leading<blockquote>evil</blockquote>\ntrout",
|
||||
"leading<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"it doesn't insert <br> after blockquotes with leading text");
|
||||
});
|
||||
|
||||
test("Paragraphs for HTML", function() {
|
||||
cooked("<div>hello world</div>", "<div>hello world</div>", "it doesn't surround <div> with paragraphs");
|
||||
cooked("<p>hello world</p>", "<p>hello world</p>", "it doesn't surround <p> with paragraphs");
|
||||
cooked("<i>hello world</i>", "<p><i>hello world</i></p>", "it surrounds inline <i> html tags with paragraphs");
|
||||
cooked("<b>hello world</b>", "<p><b>hello world</b></p>", "it surrounds inline <b> html tags with paragraphs");
|
||||
QUnit.test("Paragraphs for HTML", assert => {
|
||||
assert.cooked("<div>hello world</div>", "<div>hello world</div>", "it doesn't surround <div> with paragraphs");
|
||||
assert.cooked("<p>hello world</p>", "<p>hello world</p>", "it doesn't surround <p> with paragraphs");
|
||||
assert.cooked("<i>hello world</i>", "<p><i>hello world</i></p>", "it surrounds inline <i> html tags with paragraphs");
|
||||
assert.cooked("<b>hello world</b>", "<p><b>hello world</b></p>", "it surrounds inline <b> html tags with paragraphs");
|
||||
});
|
||||
|
||||
test("Links", function() {
|
||||
QUnit.test("Links", assert => {
|
||||
|
||||
cooked("EvilTrout: http://eviltrout.com",
|
||||
assert.cooked("EvilTrout: http://eviltrout.com",
|
||||
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>',
|
||||
"autolinks a URL");
|
||||
|
||||
cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A",
|
||||
assert.cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A",
|
||||
'<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>',
|
||||
"allows links to contain query params");
|
||||
|
||||
cooked("Derpy: http://derp.com?__test=1",
|
||||
assert.cooked("Derpy: http://derp.com?__test=1",
|
||||
'<p>Derpy: <a href="http://derp.com?__test=1">http://derp.com?__test=1</a></p>',
|
||||
"works with double underscores in urls");
|
||||
|
||||
cooked("Derpy: http://derp.com?_test_=1",
|
||||
assert.cooked("Derpy: http://derp.com?_test_=1",
|
||||
'<p>Derpy: <a href="http://derp.com?_test_=1">http://derp.com?_test_=1</a></p>',
|
||||
"works with underscores in urls");
|
||||
|
||||
cooked("Atwood: www.codinghorror.com",
|
||||
assert.cooked("Atwood: www.codinghorror.com",
|
||||
'<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>',
|
||||
"autolinks something that begins with www");
|
||||
|
||||
cooked("Atwood: http://www.codinghorror.com",
|
||||
assert.cooked("Atwood: http://www.codinghorror.com",
|
||||
'<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>',
|
||||
"autolinks a URL with http://www");
|
||||
|
||||
cooked("EvilTrout: http://eviltrout.com hello",
|
||||
assert.cooked("EvilTrout: http://eviltrout.com hello",
|
||||
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a> hello</p>',
|
||||
"autolinks with trailing text");
|
||||
|
||||
cooked("here is [an example](http://twitter.com)",
|
||||
assert.cooked("here is [an example](http://twitter.com)",
|
||||
'<p>here is <a href="http://twitter.com">an example</a></p>',
|
||||
"supports markdown style links");
|
||||
|
||||
cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
|
||||
assert.cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
|
||||
'<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>',
|
||||
"autolinks a URL with parentheses (like Wikipedia)");
|
||||
|
||||
cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
||||
assert.cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
||||
"<p>Here's a tweet:<br/><a href=\"https://twitter.com/evil_trout/status/345954894420787200\" class=\"onebox\" target=\"_blank\">https://twitter.com/evil_trout/status/345954894420787200</a></p>",
|
||||
"It doesn't strip the new line.");
|
||||
|
||||
cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
||||
assert.cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
||||
"<ol><li>View <span class=\"mention\">@eviltrout</span>'s profile here: <a href=\"http://meta.discourse.org/u/eviltrout/activity\">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li></ol>",
|
||||
"allows autolinking within a list without inserting a paragraph.");
|
||||
|
||||
cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
|
||||
assert.cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
|
||||
|
||||
cooked("[]: http://eviltrout.com", "<p>[]: <a href=\"http://eviltrout.com\">http://eviltrout.com</a></p>", "It doesn't accept empty link references");
|
||||
assert.cooked("[]: http://eviltrout.com", "<p>[]: <a href=\"http://eviltrout.com\">http://eviltrout.com</a></p>", "It doesn't accept empty link references");
|
||||
|
||||
cooked("[b]label[/b]: description", "<p><span class=\"bbcode-b\">label</span>: description</p>", "It doesn't accept BBCode as link references");
|
||||
assert.cooked("[b]label[/b]: description", "<p><span class=\"bbcode-b\">label</span>: description</p>", "It doesn't accept BBCode as link references");
|
||||
|
||||
cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
|
||||
assert.cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
|
||||
"<p><a href=\"http://discourse.org\">http://discourse.org</a> and " +
|
||||
"<a href=\"http://discourse.org/another_url\">http://discourse.org/another_url</a> and " +
|
||||
"<a href=\"http://www.imdb.com/name/nm2225369\">http://www.imdb.com/name/nm2225369</a></p>",
|
||||
'allows multiple links on one line');
|
||||
|
||||
cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com",
|
||||
assert.cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com",
|
||||
"<ul><li><a href=\"http://eviltrout.com\">Evil Trout</a></li></ul>",
|
||||
"allows markdown link references in a list");
|
||||
|
||||
cooked("User [MOD]: Hello!",
|
||||
assert.cooked("User [MOD]: Hello!",
|
||||
"<p>User [MOD]: Hello!</p>",
|
||||
"It does not consider references that are obviously not URLs");
|
||||
|
||||
cooked("<small>http://eviltrout.com</small>", "<p><small><a href=\"http://eviltrout.com\">http://eviltrout.com</a></small></p>", "Links within HTML tags");
|
||||
assert.cooked("<small>http://eviltrout.com</small>", "<p><small><a href=\"http://eviltrout.com\">http://eviltrout.com</a></small></p>", "Links within HTML tags");
|
||||
|
||||
cooked("[http://google.com ... wat](http://discourse.org)",
|
||||
assert.cooked("[http://google.com ... wat](http://discourse.org)",
|
||||
"<p><a href=\"http://discourse.org\">http://google.com ... wat</a></p>",
|
||||
"it supports links within links");
|
||||
|
||||
cooked("[http://google.com](http://discourse.org)",
|
||||
assert.cooked("[http://google.com](http://discourse.org)",
|
||||
"<p><a href=\"http://discourse.org\">http://google.com</a></p>",
|
||||
"it supports markdown links where the name and link match");
|
||||
|
||||
|
||||
cooked("[Link](http://www.example.com) (with an outer \"description\")",
|
||||
assert.cooked("[Link](http://www.example.com) (with an outer \"description\")",
|
||||
"<p><a href=\"http://www.example.com\">Link</a> (with an outer \"description\")</p>",
|
||||
"it doesn't consume closing parens as part of the url");
|
||||
|
||||
cooked("A link inside parentheses (http://www.example.com)",
|
||||
assert.cooked("A link inside parentheses (http://www.example.com)",
|
||||
"<p>A link inside parentheses (<a href=\"http://www.example.com\">http://www.example.com</a>)</p>",
|
||||
"it auto-links a url within parentheses");
|
||||
|
||||
cooked("[ul][1]\n\n[1]: http://eviltrout.com",
|
||||
assert.cooked("[ul][1]\n\n[1]: http://eviltrout.com",
|
||||
"<p><a href=\"http://eviltrout.com\">ul</a></p>",
|
||||
"it can use `ul` as a link name");
|
||||
});
|
||||
|
||||
test("simple quotes", function() {
|
||||
cooked("> nice!", "<blockquote><p>nice!</p></blockquote>", "it supports simple quotes");
|
||||
cooked(" > nice!", "<blockquote><p>nice!</p></blockquote>", "it allows quotes with preceding spaces");
|
||||
cooked("> level 1\n> > level 2",
|
||||
QUnit.test("simple quotes", assert => {
|
||||
assert.cooked("> nice!", "<blockquote><p>nice!</p></blockquote>", "it supports simple quotes");
|
||||
assert.cooked(" > nice!", "<blockquote><p>nice!</p></blockquote>", "it allows quotes with preceding spaces");
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"it allows nesting of blockquotes");
|
||||
cooked("> level 1\n> > level 2",
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"it allows nesting of blockquotes with spaces");
|
||||
|
||||
cooked("- hello\n\n > world\n > eviltrout",
|
||||
assert.cooked("- hello\n\n > world\n > eviltrout",
|
||||
"<ul><li>hello</li></ul>\n\n<blockquote><p>world<br/>eviltrout</p></blockquote>",
|
||||
"it allows quotes within a list.");
|
||||
|
||||
cooked("- <p>eviltrout</p>",
|
||||
assert.cooked("- <p>eviltrout</p>",
|
||||
"<ul><li><p>eviltrout</p></li></ul>",
|
||||
"it allows paragraphs within a list.");
|
||||
|
||||
|
||||
cooked(" > indent 1\n > indent 2", "<blockquote><p>indent 1<br/>indent 2</p></blockquote>", "allow multiple spaces to indent");
|
||||
assert.cooked(" > indent 1\n > indent 2", "<blockquote><p>indent 1<br/>indent 2</p></blockquote>", "allow multiple spaces to indent");
|
||||
|
||||
});
|
||||
|
||||
test("Quotes", function() {
|
||||
QUnit.test("Quotes", assert => {
|
||||
|
||||
cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]",
|
||||
assert.cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]",
|
||||
{ topicId: 2 },
|
||||
"<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:</div><blockquote>" +
|
||||
"<p>a quote</p><p>second line</p><p>third line</p></blockquote></aside>",
|
||||
"works with multiple lines");
|
||||
|
||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
{ topicId: 2, lookupAvatar: function(name) { return "" + name; }, sanitize: true },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob" +
|
||||
"bob:</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
"handles quotes properly");
|
||||
|
||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
{ topicId: 2, lookupAvatar: function() { } },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob:" +
|
||||
"</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
"includes no avatar if none is found");
|
||||
|
||||
cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
||||
assert.cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
||||
"<p><aside class=\"quote\"><blockquote><p>a</p><p><aside class=\"quote\"><blockquote><p>b</p></blockquote></aside></p></blockquote></aside></p>",
|
||||
"handles nested quotes properly");
|
||||
|
||||
});
|
||||
|
||||
test("Mentions", function() {
|
||||
QUnit.test("Mentions", assert => {
|
||||
|
||||
const alwaysTrue = { mentionLookup: (function() { return "user"; }) };
|
||||
|
||||
cookedOptions("Hello @sam", alwaysTrue,
|
||||
assert.cookedOptions("Hello @sam", alwaysTrue,
|
||||
"<p>Hello <a class=\"mention\" href=\"/u/sam\">@sam</a></p>",
|
||||
"translates mentions to links");
|
||||
|
||||
cooked("[@codinghorror](https://twitter.com/codinghorror)",
|
||||
assert.cooked("[@codinghorror](https://twitter.com/codinghorror)",
|
||||
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||
"it doesn't do mentions within links");
|
||||
|
||||
cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
|
||||
assert.cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
|
||||
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||
"it doesn't do link mentions within links");
|
||||
|
||||
cooked("Hello @EvilTrout",
|
||||
assert.cooked("Hello @EvilTrout",
|
||||
"<p>Hello <span class=\"mention\">@EvilTrout</span></p>",
|
||||
"adds a mention class");
|
||||
|
||||
cooked("robin@email.host",
|
||||
assert.cooked("robin@email.host",
|
||||
"<p>robin@email.host</p>",
|
||||
"won't add mention class to an email address");
|
||||
|
||||
cooked("hanzo55@yahoo.com",
|
||||
assert.cooked("hanzo55@yahoo.com",
|
||||
"<p>hanzo55@yahoo.com</p>",
|
||||
"won't be affected by email addresses that have a number before the @ symbol");
|
||||
|
||||
cooked("@EvilTrout yo",
|
||||
assert.cooked("@EvilTrout yo",
|
||||
"<p><span class=\"mention\">@EvilTrout</span> yo</p>",
|
||||
"it handles mentions at the beginning of a string");
|
||||
|
||||
cooked("yo\n@EvilTrout",
|
||||
assert.cooked("yo\n@EvilTrout",
|
||||
"<p>yo<br/><span class=\"mention\">@EvilTrout</span></p>",
|
||||
"it handles mentions at the beginning of a new line");
|
||||
|
||||
cooked("`evil` @EvilTrout `trout`",
|
||||
assert.cooked("`evil` @EvilTrout `trout`",
|
||||
"<p><code>evil</code> <span class=\"mention\">@EvilTrout</span> <code>trout</code></p>",
|
||||
"deals correctly with multiple <code> blocks");
|
||||
|
||||
cooked("```\na @test\n```",
|
||||
assert.cooked("```\na @test\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a @test</code></pre></p>",
|
||||
"should not do mentions within a code block.");
|
||||
|
||||
cooked("> foo bar baz @eviltrout",
|
||||
assert.cooked("> foo bar baz @eviltrout",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span></p></blockquote>",
|
||||
"handles mentions in simple quotes");
|
||||
|
||||
cooked("> foo bar baz @eviltrout ohmagerd\nlook at this",
|
||||
assert.cooked("> foo bar baz @eviltrout ohmagerd\nlook at this",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span> ohmagerd<br/>look at this</p></blockquote>",
|
||||
"does mentions properly with trailing text within a simple quote");
|
||||
|
||||
cooked("`code` is okay before @mention",
|
||||
assert.cooked("`code` is okay before @mention",
|
||||
"<p><code>code</code> is okay before <span class=\"mention\">@mention</span></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("@mention is okay before `code`",
|
||||
assert.cooked("@mention is okay before `code`",
|
||||
"<p><span class=\"mention\">@mention</span> is okay before <code>code</code></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("don't `@mention`",
|
||||
assert.cooked("don't `@mention`",
|
||||
"<p>don't <code>@mention</code></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("Yes `@this` should be code @eviltrout",
|
||||
assert.cooked("Yes `@this` should be code @eviltrout",
|
||||
"<p>Yes <code>@this</code> should be code <span class=\"mention\">@eviltrout</span></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("@eviltrout and `@eviltrout`",
|
||||
assert.cooked("@eviltrout and `@eviltrout`",
|
||||
"<p><span class=\"mention\">@eviltrout</span> and <code>@eviltrout</code></p>",
|
||||
"you can have a mention in an inline code block following a real mention.");
|
||||
|
||||
cooked("1. this is a list\n\n2. this is an @eviltrout mention\n",
|
||||
assert.cooked("1. this is a list\n\n2. this is an @eviltrout mention\n",
|
||||
"<ol><li><p>this is a list</p></li><li><p>this is an <span class=\"mention\">@eviltrout</span> mention</p></li></ol>",
|
||||
"it mentions properly in a list.");
|
||||
|
||||
cooked("Hello @foo/@bar",
|
||||
assert.cooked("Hello @foo/@bar",
|
||||
"<p>Hello <span class=\"mention\">@foo</span>/<span class=\"mention\">@bar</span></p>",
|
||||
"handles mentions separated by a slash.");
|
||||
|
||||
cookedOptions("@eviltrout", alwaysTrue,
|
||||
assert.cookedOptions("@eviltrout", alwaysTrue,
|
||||
"<p><a class=\"mention\" href=\"/u/eviltrout\">@eviltrout</a></p>",
|
||||
"it doesn't onebox mentions");
|
||||
|
||||
cookedOptions("<small>a @sam c</small>", alwaysTrue,
|
||||
assert.cookedOptions("<small>a @sam c</small>", alwaysTrue,
|
||||
"<p><small>a <a class=\"mention\" href=\"/u/sam\">@sam</a> c</small></p>",
|
||||
"it allows mentions within HTML tags");
|
||||
});
|
||||
|
||||
test("Category hashtags", () => {
|
||||
QUnit.test("Category hashtags", assert => {
|
||||
const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) };
|
||||
|
||||
cookedOptions("Check out #category-hashtag", alwaysTrue,
|
||||
assert.cookedOptions("Check out #category-hashtag", alwaysTrue,
|
||||
"<p>Check out <a class=\"hashtag\" href=\"http://test.discourse.org/category-hashtag\">#<span>category-hashtag</span></a></p>",
|
||||
"it translates category hashtag into links");
|
||||
|
||||
cooked("Check out #category-hashtag",
|
||||
assert.cooked("Check out #category-hashtag",
|
||||
"<p>Check out <span class=\"hashtag\">#category-hashtag</span></p>",
|
||||
"it does not translate category hashtag into links if it is not a valid category hashtag");
|
||||
|
||||
cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
|
||||
assert.cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
|
||||
"<p><a href=\"http://www.test.com\">#category-hashtag</a></p>",
|
||||
"it does not translate category hashtag within links");
|
||||
|
||||
cooked("```\n# #category-hashtag\n```",
|
||||
assert.cooked("```\n# #category-hashtag\n```",
|
||||
"<p><pre><code class=\"lang-auto\"># #category-hashtag</code></pre></p>",
|
||||
"it does not translate category hashtags to links in code blocks");
|
||||
|
||||
cooked("># #category-hashtag\n",
|
||||
assert.cooked("># #category-hashtag\n",
|
||||
"<blockquote><h1><span class=\"hashtag\">#category-hashtag</span></h1></blockquote>",
|
||||
"it handles category hashtags in simple quotes");
|
||||
|
||||
cooked("# #category-hashtag",
|
||||
assert.cooked("# #category-hashtag",
|
||||
"<h1><span class=\"hashtag\">#category-hashtag</span></h1>",
|
||||
"it works within ATX-style headers");
|
||||
|
||||
cooked("don't `#category-hashtag`",
|
||||
assert.cooked("don't `#category-hashtag`",
|
||||
"<p>don't <code>#category-hashtag</code></p>",
|
||||
"it does not mention in an inline code block");
|
||||
|
||||
cooked("test #hashtag1/#hashtag2",
|
||||
assert.cooked("test #hashtag1/#hashtag2",
|
||||
"<p>test <span class=\"hashtag\">#hashtag1</span>/#hashtag2</p>",
|
||||
"it does not convert category hashtag not bounded by spaces");
|
||||
|
||||
cooked("<small>#category-hashtag</small>",
|
||||
assert.cooked("<small>#category-hashtag</small>",
|
||||
"<p><small><span class=\"hashtag\">#category-hashtag</span></small></p>",
|
||||
"it works between HTML tags");
|
||||
});
|
||||
|
||||
|
||||
test("Heading", function() {
|
||||
cooked("**Bold**\n----------", "<h2><strong>Bold</strong></h2>", "It will bold the heading");
|
||||
QUnit.test("Heading", assert => {
|
||||
assert.cooked("**Bold**\n----------", "<h2><strong>Bold</strong></h2>", "It will bold the heading");
|
||||
});
|
||||
|
||||
test("bold and italics", function() {
|
||||
cooked("a \"**hello**\"", "<p>a \"<strong>hello</strong>\"</p>", "bolds in quotes");
|
||||
cooked("(**hello**)", "<p>(<strong>hello</strong>)</p>", "bolds in parens");
|
||||
cooked("**hello**\nworld", "<p><strong>hello</strong><br>world</p>", "allows newline after bold");
|
||||
cooked("**hello**\n**world**", "<p><strong>hello</strong><br><strong>world</strong></p>", "newline between two bolds");
|
||||
cooked("**a*_b**", "<p><strong>a*_b</strong></p>", "allows for characters within bold");
|
||||
cooked("** hello**", "<p>** hello**</p>", "does not bold on a space boundary");
|
||||
cooked("**hello **", "<p>**hello **</p>", "does not bold on a space boundary");
|
||||
cooked("你**hello**", "<p>你**hello**</p>", "does not bold chinese intra word");
|
||||
cooked("**你hello**", "<p><strong>你hello</strong></p>", "allows bolded chinese");
|
||||
QUnit.test("bold and italics", assert => {
|
||||
assert.cooked("a \"**hello**\"", "<p>a \"<strong>hello</strong>\"</p>", "bolds in quotes");
|
||||
assert.cooked("(**hello**)", "<p>(<strong>hello</strong>)</p>", "bolds in parens");
|
||||
assert.cooked("**hello**\nworld", "<p><strong>hello</strong><br>world</p>", "allows newline after bold");
|
||||
assert.cooked("**hello**\n**world**", "<p><strong>hello</strong><br><strong>world</strong></p>", "newline between two bolds");
|
||||
assert.cooked("**a*_b**", "<p><strong>a*_b</strong></p>", "allows for characters within bold");
|
||||
assert.cooked("** hello**", "<p>** hello**</p>", "does not bold on a space boundary");
|
||||
assert.cooked("**hello **", "<p>**hello **</p>", "does not bold on a space boundary");
|
||||
assert.cooked("你**hello**", "<p>你**hello**</p>", "does not bold chinese intra word");
|
||||
assert.cooked("**你hello**", "<p><strong>你hello</strong></p>", "allows bolded chinese");
|
||||
});
|
||||
|
||||
test("Escaping", function() {
|
||||
cooked("*\\*laughs\\**", "<p><em>*laughs*</em></p>", "allows escaping strong");
|
||||
cooked("*\\_laughs\\_*", "<p><em>_laughs_</em></p>", "allows escaping em");
|
||||
QUnit.test("Escaping", assert => {
|
||||
assert.cooked("*\\*laughs\\**", "<p><em>*laughs*</em></p>", "allows escaping strong");
|
||||
assert.cooked("*\\_laughs\\_*", "<p><em>_laughs_</em></p>", "allows escaping em");
|
||||
});
|
||||
|
||||
test("New Lines", function() {
|
||||
QUnit.test("New Lines", assert => {
|
||||
// Note: This behavior was discussed and we determined it does not make sense to do this
|
||||
// unless you're using traditional line breaks
|
||||
cooked("_abc\ndef_", "<p>_abc<br>def_</p>", "it does not allow markup to span new lines");
|
||||
cooked("_abc\n\ndef_", "<p>_abc</p>\n\n<p>def_</p>", "it does not allow markup to span new paragraphs");
|
||||
assert.cooked("_abc\ndef_", "<p>_abc<br>def_</p>", "it does not allow markup to span new lines");
|
||||
assert.cooked("_abc\n\ndef_", "<p>_abc</p>\n\n<p>def_</p>", "it does not allow markup to span new paragraphs");
|
||||
});
|
||||
|
||||
test("Oneboxing", function() {
|
||||
QUnit.test("Oneboxing", assert => {
|
||||
|
||||
function matches(input, regexp) {
|
||||
return new PrettyText(defaultOpts).cook(input).match(regexp);
|
||||
};
|
||||
|
||||
ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/),
|
||||
assert.ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/),
|
||||
"doesn't onebox a link within a list");
|
||||
|
||||
ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line");
|
||||
ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
|
||||
ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
|
||||
assert.ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line");
|
||||
assert.ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
|
||||
assert.ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
|
||||
|
||||
ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
|
||||
ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
assert.ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
|
||||
assert.ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
"onebox"),
|
||||
"Markdown links where the label is the same as the url are oneboxed");
|
||||
|
||||
cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
||||
assert.cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
||||
"<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\"" +
|
||||
" target=\"_blank\">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>",
|
||||
"works with links that have underscores in them");
|
||||
|
||||
});
|
||||
|
||||
test("links with full urls", function() {
|
||||
cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
|
||||
QUnit.test("links with full urls", assert => {
|
||||
assert.cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
|
||||
"<p><a href=\"http://eviltrout.com\">http://eviltrout.com</a> is a url</p>",
|
||||
"it supports links that are full URLs");
|
||||
});
|
||||
|
||||
test("Code Blocks", function() {
|
||||
QUnit.test("Code Blocks", assert => {
|
||||
|
||||
cooked("<pre>\nhello\n</pre>\n",
|
||||
assert.cooked("<pre>\nhello\n</pre>\n",
|
||||
"<p><pre>hello</pre></p>",
|
||||
"pre blocks don't include extra lines");
|
||||
|
||||
cooked("```\na\nb\nc\n\nd\n```",
|
||||
assert.cooked("```\na\nb\nc\n\nd\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
|
||||
"it treats new lines properly");
|
||||
|
||||
cooked("```\ntest\n```",
|
||||
assert.cooked("```\ntest\n```",
|
||||
"<p><pre><code class=\"lang-auto\">test</code></pre></p>",
|
||||
"it supports basic code blocks");
|
||||
|
||||
cooked("```json\n{hello: 'world'}\n```\ntrailing",
|
||||
assert.cooked("```json\n{hello: 'world'}\n```\ntrailing",
|
||||
"<p><pre><code class=\"lang-json\">{hello: 'world'}</code></pre></p>\n\n<p>trailing</p>",
|
||||
"It does not truncate text after a code block.");
|
||||
|
||||
cooked("```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
assert.cooked("```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"it maintains new lines inside a code block.");
|
||||
|
||||
cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
assert.cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p>hello<br/>world<br/></p>\n\n<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"it maintains new lines inside a code block with leading content.");
|
||||
|
||||
cooked("```ruby\n<header>hello</header>\n```",
|
||||
assert.cooked("```ruby\n<header>hello</header>\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"><header>hello</header></code></pre></p>",
|
||||
"it escapes code in the code block");
|
||||
|
||||
cooked("```text\ntext\n```",
|
||||
assert.cooked("```text\ntext\n```",
|
||||
"<p><pre><code class=\"lang-nohighlight\">text</code></pre></p>",
|
||||
"handles text by adding nohighlight");
|
||||
|
||||
cooked("```ruby\n# cool\n```",
|
||||
assert.cooked("```ruby\n# cool\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"># cool</code></pre></p>",
|
||||
"it supports changing the language");
|
||||
|
||||
cooked(" ```\n hello\n ```",
|
||||
assert.cooked(" ```\n hello\n ```",
|
||||
"<pre><code>```\nhello\n```</code></pre>",
|
||||
"only detect ``` at the beginning of lines");
|
||||
|
||||
cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
||||
assert.cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">def self.parse(text)\n\n text\nend</code></pre></p>",
|
||||
"it allows leading spaces on lines in a code block.");
|
||||
|
||||
cooked("```ruby\nhello `eviltrout`\n```",
|
||||
assert.cooked("```ruby\nhello `eviltrout`\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">hello `eviltrout`</code></pre></p>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
cooked("```eviltrout\nhello\n```",
|
||||
assert.cooked("```eviltrout\nhello\n```",
|
||||
"<p><pre><code class=\"lang-auto\">hello</code></pre></p>",
|
||||
"it doesn't not whitelist all classes");
|
||||
|
||||
cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]\n```",
|
||||
assert.cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]\n```",
|
||||
"<p><pre><code class=\"lang-auto\">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]</code></pre></p>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
cooked(" hello\n<blockquote>test</blockquote>",
|
||||
assert.cooked(" hello\n<blockquote>test</blockquote>",
|
||||
"<pre><code>hello</code></pre>\n\n<blockquote>test</blockquote>",
|
||||
"it allows an indented code block to by followed by a `<blockquote>`");
|
||||
|
||||
cooked("``` foo bar ```",
|
||||
assert.cooked("``` foo bar ```",
|
||||
"<p><code>foo bar</code></p>",
|
||||
"it tolerates misuse of code block tags as inline code");
|
||||
|
||||
cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
|
||||
assert.cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-auto\">line1</code></pre></p>\n\n<p><pre><code class=\"lang-auto\">line2\n\nline3</code></pre></p>",
|
||||
"it does not consume next block's trailing newlines");
|
||||
|
||||
cooked(" <pre>test</pre>",
|
||||
assert.cooked(" <pre>test</pre>",
|
||||
"<pre><code><pre>test</pre></code></pre>",
|
||||
"it does not parse other block types in markdown code blocks");
|
||||
|
||||
cooked(" [quote]test[/quote]",
|
||||
assert.cooked(" [quote]test[/quote]",
|
||||
"<pre><code>[quote]test[/quote]</code></pre>",
|
||||
"it does not parse other block types in markdown code blocks");
|
||||
|
||||
cooked("## a\nb\n```\nc\n```",
|
||||
assert.cooked("## a\nb\n```\nc\n```",
|
||||
"<h2>a</h2>\n\n<p><pre><code class=\"lang-auto\">c</code></pre></p>",
|
||||
"it handles headings with code blocks after them.");
|
||||
});
|
||||
|
||||
test("URLs in BBCode tags", function() {
|
||||
QUnit.test("URLs in BBCode tags", assert => {
|
||||
|
||||
cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
||||
assert.cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
||||
"<p><img src=\"http://eviltrout.com/eviltrout.png\"/><img src=\"http://samsaffron.com/samsaffron.png\"/></p>",
|
||||
"images are properly parsed");
|
||||
|
||||
cooked("[url]http://discourse.org[/url]",
|
||||
assert.cooked("[url]http://discourse.org[/url]",
|
||||
"<p><a href=\"http://discourse.org\">http://discourse.org</a></p>",
|
||||
"links are properly parsed");
|
||||
|
||||
cooked("[url=http://discourse.org]discourse[/url]",
|
||||
assert.cooked("[url=http://discourse.org]discourse[/url]",
|
||||
"<p><a href=\"http://discourse.org\">discourse</a></p>",
|
||||
"named links are properly parsed");
|
||||
|
||||
});
|
||||
|
||||
test("images", function() {
|
||||
cooked("[](http://folksy.com/)",
|
||||
QUnit.test("images", assert => {
|
||||
assert.cooked("[](http://folksy.com/)",
|
||||
"<p><a href=\"http://folksy.com/\"><img src=\"http://folksy.com/images/folksy-colour.png\" alt=\"folksy logo\"/></a></p>",
|
||||
"It allows images with links around them");
|
||||
|
||||
cooked("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">",
|
||||
assert.cooked("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">",
|
||||
"<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></p>",
|
||||
"It allows data images");
|
||||
});
|
||||
|
||||
test("censoring", function() {
|
||||
cooked("aw shucks, golly gee whiz.",
|
||||
QUnit.test("censoring", assert => {
|
||||
assert.cooked("aw shucks, golly gee whiz.",
|
||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||
"it censors words in the Site Settings");
|
||||
|
||||
cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||
assert.cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a whizzard! I love cheesewhiz. ■■■■.</p>",
|
||||
"it doesn't censor words unless they have boundaries.");
|
||||
|
||||
cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||
assert.cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
||||
"it censors words even if previous partial matches exist.");
|
||||
|
||||
cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||
assert.cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||
"<p>The link still works. <a href=\"http://www.whiz.com\">■■■■</a></p>",
|
||||
"it won't break links by censoring them.");
|
||||
|
||||
cooked("Call techapj the computer whiz at 555-555-1234 for free help.",
|
||||
assert.cooked("Call techapj the computer whiz at 555-555-1234 for free help.",
|
||||
"<p>Call ■■■■■■■ the computer ■■■■ at 555-■■■■■■■■ for free help.</p>",
|
||||
"uses both censored words and patterns from site settings");
|
||||
|
||||
cooked("I have a pen, I have an a**le",
|
||||
assert.cooked("I have a pen, I have an a**le",
|
||||
"<p>I have a pen, I have an ■■■■■</p>",
|
||||
"it escapes regexp chars");
|
||||
});
|
||||
|
||||
test("code blocks/spans hoisting", function() {
|
||||
cooked("```\n\n some code\n```",
|
||||
QUnit.test("code blocks/spans hoisting", assert => {
|
||||
assert.cooked("```\n\n some code\n```",
|
||||
"<p><pre><code class=\"lang-auto\"> some code</code></pre></p>",
|
||||
"it works when nesting standard markdown code blocks within a fenced code block");
|
||||
|
||||
cooked("`$&`",
|
||||
assert.cooked("`$&`",
|
||||
"<p><code>$&</code></p>",
|
||||
"it works even when hoisting special replacement patterns");
|
||||
});
|
||||
|
||||
test('basic bbcode', function() {
|
||||
cookedPara("[b]strong[/b]", "<span class=\"bbcode-b\">strong</span>", "bolds text");
|
||||
cookedPara("[i]emphasis[/i]", "<span class=\"bbcode-i\">emphasis</span>", "italics text");
|
||||
cookedPara("[u]underlined[/u]", "<span class=\"bbcode-u\">underlined</span>", "underlines text");
|
||||
cookedPara("[s]strikethrough[/s]", "<span class=\"bbcode-s\">strikethrough</span>", "strikes-through text");
|
||||
cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
cookedPara("[b]evil [i]trout[/i][/b]",
|
||||
QUnit.test('basic bbcode', assert => {
|
||||
assert.cookedPara("[b]strong[/b]", "<span class=\"bbcode-b\">strong</span>", "bolds text");
|
||||
assert.cookedPara("[i]emphasis[/i]", "<span class=\"bbcode-i\">emphasis</span>", "italics text");
|
||||
assert.cookedPara("[u]underlined[/u]", "<span class=\"bbcode-u\">underlined</span>", "underlines text");
|
||||
assert.cookedPara("[s]strikethrough[/s]", "<span class=\"bbcode-s\">strikethrough</span>", "strikes-through text");
|
||||
assert.cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
assert.cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
assert.cookedPara("[b]evil [i]trout[/i][/b]",
|
||||
"<span class=\"bbcode-b\">evil <span class=\"bbcode-i\">trout</span></span>",
|
||||
"allows embedding of tags");
|
||||
cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
cookedPara("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
assert.cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
assert.cookedPara("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
});
|
||||
|
||||
test('urls', function() {
|
||||
cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
|
||||
cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
|
||||
cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
|
||||
cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
|
||||
cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
QUnit.test('urls', assert => {
|
||||
assert.cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
|
||||
assert.cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
|
||||
assert.cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
|
||||
assert.cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
|
||||
assert.cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
"<a href=\"http://www.example.com\"><img src=\"http://example.com/logo.png\"></a>",
|
||||
"supports [url] with an embedded [img]");
|
||||
});
|
||||
test('invalid bbcode', function() {
|
||||
QUnit.test('invalid bbcode', assert => {
|
||||
const result = new PrettyText({ lookupAvatar: false }).cook("[code]I am not closed\n\nThis text exists.");
|
||||
equal(result, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
assert.equal(result, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
});
|
||||
|
||||
test('code', function() {
|
||||
cookedPara("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
cookedPara("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
cookedPara("[code]abc\n#def\n[/code]", '<pre><code class=\"lang-auto\">abc\n#def</code></pre>', 'it handles headings in a [code] block');
|
||||
cookedPara("[code]\n s[/code]",
|
||||
QUnit.test('code', assert => {
|
||||
assert.cookedPara("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]abc\n#def\n[/code]", '<pre><code class=\"lang-auto\">abc\n#def</code></pre>', 'it handles headings in a [code] block');
|
||||
assert.cookedPara("[code]\n s[/code]",
|
||||
"<pre><code class=\"lang-auto\"> s</code></pre>",
|
||||
"it doesn't trim leading whitespace");
|
||||
});
|
||||
|
||||
test('lists', function() {
|
||||
cookedPara("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
cookedPara("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
QUnit.test('lists', assert => {
|
||||
assert.cookedPara("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
assert.cookedPara("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
assert.cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
});
|
||||
|
||||
test('tags with arguments', function() {
|
||||
cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
cookedPara("[u][i]abc[/i][/u]", "<span class=\"bbcode-u\"><span class=\"bbcode-i\">abc</span></span>", "can nest tags");
|
||||
cookedPara("[b]first[/b] [b]second[/b]", "<span class=\"bbcode-b\">first</span> <span class=\"bbcode-b\">second</span>", "can bold two things on the same line");
|
||||
QUnit.test('tags with arguments', assert => {
|
||||
assert.cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
assert.cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
assert.cookedPara("[u][i]abc[/i][/u]", "<span class=\"bbcode-u\"><span class=\"bbcode-i\">abc</span></span>", "can nest tags");
|
||||
assert.cookedPara("[b]first[/b] [b]second[/b]", "<span class=\"bbcode-b\">first</span> <span class=\"bbcode-b\">second</span>", "can bold two things on the same line");
|
||||
});
|
||||
|
||||
|
||||
test("quotes", function() {
|
||||
QUnit.test("quotes", assert => {
|
||||
const post = Post.create({
|
||||
cooked: "<p><b>lorem</b> ipsum</p>",
|
||||
username: "eviltrout",
|
||||
@@ -621,7 +633,7 @@ test("quotes", function() {
|
||||
});
|
||||
|
||||
function formatQuote(val, expected, text) {
|
||||
equal(Quote.build(post, val), expected, text);
|
||||
assert.equal(Quote.build(post, val), expected, text);
|
||||
};
|
||||
|
||||
formatQuote(undefined, "", "empty string for undefined content");
|
||||
@@ -646,80 +658,80 @@ test("quotes", function() {
|
||||
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n",
|
||||
"it escapes the contents of the quote");
|
||||
|
||||
cookedPara("[quote]test[/quote]",
|
||||
assert.cookedPara("[quote]test[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p>test</p></blockquote></aside>",
|
||||
"it supports quotes without params");
|
||||
|
||||
cookedPara("[quote]\n*test*\n[/quote]",
|
||||
assert.cookedPara("[quote]\n*test*\n[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p><em>test</em></p></blockquote></aside>",
|
||||
"it doesn't insert a new line for italics");
|
||||
|
||||
cookedPara("[quote=,script='a'><script>alert('test');//':a][/quote]",
|
||||
assert.cookedPara("[quote=,script='a'><script>alert('test');//':a][/quote]",
|
||||
"<aside class=\"quote\"><blockquote></blockquote></aside>",
|
||||
"It will not create a script tag within an attribute");
|
||||
});
|
||||
|
||||
test("quote formatting", function() {
|
||||
QUnit.test("quote formatting", assert => {
|
||||
|
||||
cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]",
|
||||
assert.cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]",
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>[sam]</p></blockquote></aside>",
|
||||
"it allows quotes with [] inside");
|
||||
|
||||
cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>",
|
||||
"renders quotes properly");
|
||||
|
||||
cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>\n\n<p>hello</p>",
|
||||
"handles new lines properly");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><aside class=\"quote\" data-post=\"2\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Bob:" +
|
||||
"</div><blockquote></blockquote></aside></blockquote></aside>",
|
||||
"quotes can be nested");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><p>[quote=\"Bob, post:2, topic:1\"]</p></blockquote></aside>",
|
||||
"handles mismatched nested quote tags");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks without leading newline");
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks with leading newline");
|
||||
});
|
||||
|
||||
test("quotes with trailing formatting", function() {
|
||||
QUnit.test("quotes with trailing formatting", assert => {
|
||||
const result = new PrettyText(defaultOpts).cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]\nhello\n[/quote]\n*Test*");
|
||||
equal(result,
|
||||
assert.equal(result,
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>hello</p></blockquote></aside>\n\n<p><em>Test</em></p>",
|
||||
"it allows trailing formatting");
|
||||
});
|
||||
|
||||
test("enable/disable features", () => {
|
||||
QUnit.test("enable/disable features", assert => {
|
||||
const table = `<table><tr><th>hello</th></tr><tr><td>world</td></tr></table>`;
|
||||
const hasTable = new PrettyText({ features: {table: true}, sanitize: true}).cook(table);
|
||||
equal(hasTable, `<table class="md-table"><tr><th>hello</th></tr><tr><td>world</td></tr></table>`);
|
||||
assert.equal(hasTable, `<table class="md-table"><tr><th>hello</th></tr><tr><td>world</td></tr></table>`);
|
||||
|
||||
const noTable = new PrettyText({ features: { table: false }, sanitize: true}).cook(table);
|
||||
equal(noTable, `<p></p>`, 'tables are stripped when disabled');
|
||||
assert.equal(noTable, `<p></p>`, 'tables are stripped when disabled');
|
||||
});
|
||||
|
||||
test("emoji", () => {
|
||||
cooked(":smile:", `<p><img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
cooked(":(", `<p><img src="/images/emoji/emoji_one/frowning.png?v=${v}" title=":frowning:" class="emoji" alt=":frowning:"></p>`);
|
||||
cooked("8-)", `<p><img src="/images/emoji/emoji_one/sunglasses.png?v=${v}" title=":sunglasses:" class="emoji" alt=":sunglasses:"></p>`);
|
||||
QUnit.test("emoji", assert => {
|
||||
assert.cooked(":smile:", `<p><img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
assert.cooked(":(", `<p><img src="/images/emoji/emoji_one/frowning.png?v=${v}" title=":frowning:" class="emoji" alt=":frowning:"></p>`);
|
||||
assert.cooked("8-)", `<p><img src="/images/emoji/emoji_one/sunglasses.png?v=${v}" title=":sunglasses:" class="emoji" alt=":sunglasses:"></p>`);
|
||||
});
|
||||
|
||||
test("emoji - emojiSet", () => {
|
||||
cookedOptions(":smile:",
|
||||
QUnit.test("emoji - emojiSet", assert => {
|
||||
assert.cookedOptions(":smile:",
|
||||
{ emojiSet: 'twitter' },
|
||||
`<p><img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
});
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { default as PrettyText, buildOptions } from 'pretty-text/pretty-text';
|
||||
import { hrefAllowed } from 'pretty-text/sanitizer';
|
||||
|
||||
module("lib:sanitizer");
|
||||
QUnit.module("lib:sanitizer");
|
||||
|
||||
test("sanitize", function() {
|
||||
QUnit.test("sanitize", assert => {
|
||||
const pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
const cooked = (input, expected, text) => equal(pt.cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
const cooked = (input, expected, text) => assert.equal(pt.cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
|
||||
equal(pt.sanitize("<i class=\"fa-bug fa-spin\">bug</i>"), "<i>bug</i>");
|
||||
equal(pt.sanitize("<div><script>alert('hi');</script></div>"), "<div></div>");
|
||||
equal(pt.sanitize("<div><p class=\"funky\" wrong='1'>hello</p></div>"), "<div><p>hello</p></div>");
|
||||
equal(pt.sanitize("<3 <3"), "<3 <3");
|
||||
equal(pt.sanitize("<_<"), "<_<");
|
||||
assert.equal(pt.sanitize("<i class=\"fa-bug fa-spin\">bug</i>"), "<i>bug</i>");
|
||||
assert.equal(pt.sanitize("<div><script>alert('hi');</script></div>"), "<div></div>");
|
||||
assert.equal(pt.sanitize("<div><p class=\"funky\" wrong='1'>hello</p></div>"), "<div><p>hello</p></div>");
|
||||
assert.equal(pt.sanitize("<3 <3"), "<3 <3");
|
||||
assert.equal(pt.sanitize("<_<"), "<_<");
|
||||
cooked("hello<script>alert(42)</script>", "<p>hello</p>", "it sanitizes while cooking");
|
||||
|
||||
cooked("<a href='http://disneyland.disney.go.com/'>disney</a> <a href='http://reddit.com'>reddit</a>",
|
||||
@@ -32,11 +32,11 @@ test("sanitize", function() {
|
||||
"<iframe width=\"425\" height=\"350\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" src=\"http://www.openstreetmap.org/export/embed.html?bbox=22.49454975128174%2C51.220338322410775%2C22.523088455200195%2C51.23345342732931&layer=mapnik\"></iframe>",
|
||||
"it allows iframe to OpenStreetMap");
|
||||
|
||||
equal(pt.sanitize("<textarea>hullo</textarea>"), "hullo");
|
||||
equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
||||
equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
||||
equal(pt.sanitize("<progress>hello"), "hello");
|
||||
equal(pt.sanitize("<mark>highlight</mark>"), "highlight");
|
||||
assert.equal(pt.sanitize("<textarea>hullo</textarea>"), "hullo");
|
||||
assert.equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
||||
assert.equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
||||
assert.equal(pt.sanitize("<progress>hello"), "hello");
|
||||
assert.equal(pt.sanitize("<mark>highlight</mark>"), "highlight");
|
||||
|
||||
cooked("[the answer](javascript:alert(42))", "<p><a>the answer</a></p>", "it prevents XSS");
|
||||
|
||||
@@ -60,26 +60,26 @@ test("sanitize", function() {
|
||||
cooked(`<div dir="rtl">RTL text</div>`, `<div dir="rtl">RTL text</div>`);
|
||||
});
|
||||
|
||||
test("ids on headings", () => {
|
||||
QUnit.test("ids on headings", assert => {
|
||||
const pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
equal(pt.sanitize("<h3>Test Heading</h3>"), "<h3>Test Heading</h3>");
|
||||
equal(pt.sanitize(`<h1 id="test-heading">Test Heading</h1>`), `<h1 id="test-heading">Test Heading</h1>`);
|
||||
equal(pt.sanitize(`<h2 id="test-heading">Test Heading</h2>`), `<h2 id="test-heading">Test Heading</h2>`);
|
||||
equal(pt.sanitize(`<h3 id="test-heading">Test Heading</h3>`), `<h3 id="test-heading">Test Heading</h3>`);
|
||||
equal(pt.sanitize(`<h4 id="test-heading">Test Heading</h4>`), `<h4 id="test-heading">Test Heading</h4>`);
|
||||
equal(pt.sanitize(`<h5 id="test-heading">Test Heading</h5>`), `<h5 id="test-heading">Test Heading</h5>`);
|
||||
equal(pt.sanitize(`<h6 id="test-heading">Test Heading</h6>`), `<h6 id="test-heading">Test Heading</h6>`);
|
||||
assert.equal(pt.sanitize("<h3>Test Heading</h3>"), "<h3>Test Heading</h3>");
|
||||
assert.equal(pt.sanitize(`<h1 id="test-heading">Test Heading</h1>`), `<h1 id="test-heading">Test Heading</h1>`);
|
||||
assert.equal(pt.sanitize(`<h2 id="test-heading">Test Heading</h2>`), `<h2 id="test-heading">Test Heading</h2>`);
|
||||
assert.equal(pt.sanitize(`<h3 id="test-heading">Test Heading</h3>`), `<h3 id="test-heading">Test Heading</h3>`);
|
||||
assert.equal(pt.sanitize(`<h4 id="test-heading">Test Heading</h4>`), `<h4 id="test-heading">Test Heading</h4>`);
|
||||
assert.equal(pt.sanitize(`<h5 id="test-heading">Test Heading</h5>`), `<h5 id="test-heading">Test Heading</h5>`);
|
||||
assert.equal(pt.sanitize(`<h6 id="test-heading">Test Heading</h6>`), `<h6 id="test-heading">Test Heading</h6>`);
|
||||
});
|
||||
|
||||
test("urlAllowed", () => {
|
||||
const allowed = (url, msg) => equal(hrefAllowed(url), url, msg);
|
||||
QUnit.test("urlAllowed", assert => {
|
||||
const allowed = (url, msg) => assert.equal(hrefAllowed(url), url, msg);
|
||||
|
||||
allowed("/foo/bar.html", "allows relative urls");
|
||||
allowed("http://eviltrout.com/evil/trout", "allows full urls");
|
||||
allowed("https://eviltrout.com/evil/trout", "allows https urls");
|
||||
allowed("//eviltrout.com/evil/trout", "allows protocol relative urls");
|
||||
|
||||
equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"),
|
||||
assert.equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"),
|
||||
"http://google.com/test%27onmouseover=alert(%27XSS!%27);//.swf",
|
||||
"escape single quotes");
|
||||
});
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
import { default as DiscourseURL, userPath } from 'discourse/lib/url';
|
||||
|
||||
module("lib:url");
|
||||
QUnit.module("lib:url");
|
||||
|
||||
test("isInternal with a HTTP url", function() {
|
||||
QUnit.test("isInternal with a HTTP url", assert => {
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com");
|
||||
|
||||
not(DiscourseURL.isInternal(null), "a blank URL is not internal");
|
||||
ok(DiscourseURL.isInternal("/test"), "relative URLs are internal");
|
||||
ok(DiscourseURL.isInternal("//eviltrout.com"), "a url on the same host is internal (protocol-less)");
|
||||
ok(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host is internal");
|
||||
ok(DiscourseURL.isInternal("https://eviltrout.com/moustache"), "a url on a HTTPS of the same host is internal");
|
||||
not(DiscourseURL.isInternal("//twitter.com.com"), "a different host is not internal (protocol-less)");
|
||||
not(DiscourseURL.isInternal("http://twitter.com"), "a different host is not internal");
|
||||
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");
|
||||
});
|
||||
|
||||
test("isInternal with a HTTPS url", function() {
|
||||
QUnit.test("isInternal with a HTTPS url", assert => {
|
||||
sandbox.stub(DiscourseURL, "origin").returns("https://eviltrout.com");
|
||||
ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls");
|
||||
assert.ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls");
|
||||
});
|
||||
|
||||
test("isInternal on subfolder install", function() {
|
||||
QUnit.test("isInternal on subfolder install", assert => {
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com/forum");
|
||||
not(DiscourseURL.isInternal("http://eviltrout.com"), "the host root is not internal");
|
||||
not(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host but on a different folder is not internal");
|
||||
ok(DiscourseURL.isInternal("http://eviltrout.com/forum/moustache"), "a url on the same host and on the same folder is internal");
|
||||
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");
|
||||
});
|
||||
|
||||
test("userPath", assert => {
|
||||
QUnit.test("userPath", assert => {
|
||||
assert.equal(userPath(), '/u');
|
||||
assert.equal(userPath('eviltrout'), '/u/eviltrout');
|
||||
assert.equal(userPath('hp.json'), '/u/hp.json');
|
||||
});
|
||||
|
||||
test("userPath with BaseUri", assert => {
|
||||
QUnit.test("userPath with BaseUri", assert => {
|
||||
Discourse.BaseUri = "/forum";
|
||||
assert.equal(userPath(), '/forum/u');
|
||||
assert.equal(userPath('eviltrout'), '/forum/u/eviltrout');
|
||||
assert.equal(userPath('hp.json'), '/forum/u/hp.json');
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import userSearch from 'discourse/lib/user-search';
|
||||
|
||||
module("lib:user-search", {
|
||||
setup() {
|
||||
QUnit.module("lib:user-search", {
|
||||
beforeEach() {
|
||||
const response = (object) => {
|
||||
return [
|
||||
200,
|
||||
@@ -57,8 +57,8 @@ module("lib:user-search", {
|
||||
}
|
||||
});
|
||||
|
||||
test("it places groups unconditionally for exact match", function() {
|
||||
QUnit.test("it places groups unconditionally for exact match", assert => {
|
||||
return userSearch({term: 'Team'}).then((results)=>{
|
||||
equal(results[results.length-1]["name"], "team");
|
||||
assert.equal(results[results.length-1]["name"], "team");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
/* global Int8Array:true */
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import {
|
||||
emailValid,
|
||||
extractDomainFromUrl,
|
||||
@@ -17,68 +16,68 @@ import {
|
||||
setCaretPosition
|
||||
} from 'discourse/lib/utilities';
|
||||
|
||||
module("lib:utilities");
|
||||
QUnit.module("lib:utilities");
|
||||
|
||||
test("emailValid", function() {
|
||||
ok(emailValid('Bob@example.com'), "allows upper case in the first part of emails");
|
||||
ok(emailValid('bob@EXAMPLE.com'), "allows upper case in the email domain");
|
||||
QUnit.test("emailValid", assert => {
|
||||
assert.ok(emailValid('Bob@example.com'), "allows upper case in the first part of emails");
|
||||
assert.ok(emailValid('bob@EXAMPLE.com'), "allows upper case in the email domain");
|
||||
});
|
||||
|
||||
test("extractDomainFromUrl", function() {
|
||||
equal(extractDomainFromUrl('http://meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain name from url");
|
||||
equal(extractDomainFromUrl('meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain regardless of scheme presence");
|
||||
equal(extractDomainFromUrl('http://192.168.0.1:443/random'), '192.168.0.1', "works for IP address");
|
||||
equal(extractDomainFromUrl('http://localhost:443/random'), 'localhost', "works for localhost");
|
||||
QUnit.test("extractDomainFromUrl", assert => {
|
||||
assert.equal(extractDomainFromUrl('http://meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain name from url");
|
||||
assert.equal(extractDomainFromUrl('meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain regardless of scheme presence");
|
||||
assert.equal(extractDomainFromUrl('http://192.168.0.1:443/random'), '192.168.0.1', "works for IP address");
|
||||
assert.equal(extractDomainFromUrl('http://localhost:443/random'), 'localhost', "works for localhost");
|
||||
});
|
||||
|
||||
var validUpload = validateUploadedFiles;
|
||||
|
||||
test("validateUploadedFiles", function() {
|
||||
not(validUpload(null), "no files are invalid");
|
||||
not(validUpload(undefined), "undefined files are invalid");
|
||||
not(validUpload([]), "empty array of files is invalid");
|
||||
QUnit.test("validateUploadedFiles", assert => {
|
||||
assert.not(validUpload(null), "no files are invalid");
|
||||
assert.not(validUpload(undefined), "undefined files are invalid");
|
||||
assert.not(validUpload([]), "empty array of files is invalid");
|
||||
});
|
||||
|
||||
test("uploading one file", function() {
|
||||
QUnit.test("uploading one file", assert => {
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
not(validUpload([1, 2]));
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.too_many_uploads')));
|
||||
assert.not(validUpload([1, 2]));
|
||||
assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.too_many_uploads')));
|
||||
});
|
||||
|
||||
test("new user cannot upload images", function() {
|
||||
QUnit.test("new user cannot upload images", assert => {
|
||||
Discourse.SiteSettings.newuser_max_images = 0;
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
not(validUpload([{name: "image.png"}]), 'the upload is not valid');
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.image_upload_not_allowed_for_new_user')), 'the alert is called');
|
||||
assert.not(validUpload([{name: "image.png"}]), 'the upload is not valid');
|
||||
assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.image_upload_not_allowed_for_new_user')), 'the alert is called');
|
||||
});
|
||||
|
||||
test("new user cannot upload attachments", function() {
|
||||
QUnit.test("new user cannot upload attachments", assert => {
|
||||
Discourse.SiteSettings.newuser_max_attachments = 0;
|
||||
sandbox.stub(bootbox, "alert");
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
|
||||
not(validUpload([{name: "roman.txt"}]));
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user')));
|
||||
assert.not(validUpload([{name: "roman.txt"}]));
|
||||
assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user')));
|
||||
});
|
||||
|
||||
test("ensures an authorized upload", function() {
|
||||
QUnit.test("ensures an authorized upload", assert => {
|
||||
sandbox.stub(bootbox, "alert");
|
||||
not(validUpload([{ name: "unauthorized.html" }]));
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.upload_not_authorized', { authorized_extensions: authorizedExtensions() })));
|
||||
assert.not(validUpload([{ name: "unauthorized.html" }]));
|
||||
assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.upload_not_authorized', { authorized_extensions: authorizedExtensions() })));
|
||||
});
|
||||
|
||||
test("staff can upload anything in PM", function() {
|
||||
QUnit.test("staff can upload anything in PM", assert => {
|
||||
const files = [{ name: "some.docx" }];
|
||||
Discourse.SiteSettings.authorized_extensions = "jpeg";
|
||||
Discourse.User.resetCurrent(Discourse.User.create({ moderator: true }));
|
||||
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
not(validUpload(files));
|
||||
ok(validUpload(files, { isPrivateMessage: true, allowStaffToUploadAnyFileInPm: true }));
|
||||
assert.not(validUpload(files));
|
||||
assert.ok(validUpload(files, { isPrivateMessage: true, allowStaffToUploadAnyFileInPm: true }));
|
||||
});
|
||||
|
||||
var imageSize = 10 * 1024;
|
||||
@@ -94,19 +93,19 @@ var dummyBlob = function() {
|
||||
}
|
||||
};
|
||||
|
||||
test("allows valid uploads to go through", function() {
|
||||
QUnit.test("allows valid uploads to go through", assert => {
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
Discourse.User.currentProp("trust_level", 1);
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
// image
|
||||
var image = { name: "image.png", size: imageSize };
|
||||
ok(validUpload([image]));
|
||||
assert.ok(validUpload([image]));
|
||||
// pasted image
|
||||
var pastedImage = dummyBlob();
|
||||
ok(validUpload([pastedImage]));
|
||||
assert.ok(validUpload([pastedImage]));
|
||||
|
||||
not(bootbox.alert.calledOnce);
|
||||
assert.not(bootbox.alert.calledOnce);
|
||||
});
|
||||
|
||||
var testUploadMarkdown = function(filename) {
|
||||
@@ -119,27 +118,27 @@ var testUploadMarkdown = function(filename) {
|
||||
});
|
||||
};
|
||||
|
||||
test("getUploadMarkdown", function() {
|
||||
ok(testUploadMarkdown("lolcat.gif") === '<img src="/uploads/123/abcdef.ext" width="100" height="200">');
|
||||
ok(testUploadMarkdown("important.txt") === '<a class="attachment" href="/uploads/123/abcdef.ext">important.txt</a> (42 Bytes)\n');
|
||||
QUnit.test("getUploadMarkdown", assert => {
|
||||
assert.ok(testUploadMarkdown("lolcat.gif") === '<img src="/uploads/123/abcdef.ext" width="100" height="200">');
|
||||
assert.ok(testUploadMarkdown("important.txt") === '<a class="attachment" href="/uploads/123/abcdef.ext">important.txt</a> (42 Bytes)\n');
|
||||
});
|
||||
|
||||
test("isAnImage", function() {
|
||||
QUnit.test("isAnImage", assert => {
|
||||
_.each(["png", "jpg", "jpeg", "bmp", "gif", "tif", "tiff", "ico"], function(extension) {
|
||||
var image = "image." + extension;
|
||||
ok(isAnImage(image), image + " is recognized as an image");
|
||||
ok(isAnImage("http://foo.bar/path/to/" + image), image + " is recognized as an image");
|
||||
assert.ok(isAnImage(image), image + " is recognized as an image");
|
||||
assert.ok(isAnImage("http://foo.bar/path/to/" + image), image + " is recognized as an image");
|
||||
});
|
||||
not(isAnImage("file.txt"));
|
||||
not(isAnImage("http://foo.bar/path/to/file.txt"));
|
||||
not(isAnImage(""));
|
||||
assert.not(isAnImage("file.txt"));
|
||||
assert.not(isAnImage("http://foo.bar/path/to/file.txt"));
|
||||
assert.not(isAnImage(""));
|
||||
});
|
||||
|
||||
test("avatarUrl", function() {
|
||||
QUnit.test("avatarUrl", assert => {
|
||||
var rawSize = getRawSize;
|
||||
blank(avatarUrl('', 'tiny'), "no template returns blank");
|
||||
equal(avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url");
|
||||
equal(avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size");
|
||||
assert.blank(avatarUrl('', 'tiny'), "no template returns blank");
|
||||
assert.equal(avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url");
|
||||
assert.equal(avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size");
|
||||
});
|
||||
|
||||
var setDevicePixelRatio = function(value) {
|
||||
@@ -150,64 +149,64 @@ var setDevicePixelRatio = function(value) {
|
||||
}
|
||||
};
|
||||
|
||||
test("avatarImg", function() {
|
||||
QUnit.test("avatarImg", assert => {
|
||||
var oldRatio = window.devicePixelRatio;
|
||||
setDevicePixelRatio(2);
|
||||
|
||||
var avatarTemplate = "/path/to/avatar/{size}.png";
|
||||
equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}),
|
||||
assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}),
|
||||
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar'>",
|
||||
"it returns the avatar html");
|
||||
|
||||
equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}),
|
||||
assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}),
|
||||
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar' title='evilest trout'>",
|
||||
"it adds a title if supplied");
|
||||
|
||||
equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}),
|
||||
assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}),
|
||||
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar evil fish'>",
|
||||
"it adds extra classes if supplied");
|
||||
|
||||
blank(avatarImg({avatarTemplate: "", size: 'tiny'}),
|
||||
assert.blank(avatarImg({avatarTemplate: "", size: 'tiny'}),
|
||||
"it doesn't render avatars for invalid avatar template");
|
||||
|
||||
setDevicePixelRatio(oldRatio);
|
||||
});
|
||||
|
||||
test("allowsImages", function() {
|
||||
QUnit.test("allowsImages", assert => {
|
||||
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif";
|
||||
ok(allowsImages(), "works");
|
||||
assert.ok(allowsImages(), "works");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif";
|
||||
ok(allowsImages(), "works with old extensions syntax");
|
||||
assert.ok(allowsImages(), "works with old extensions syntax");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = "txt|pdf|*";
|
||||
ok(allowsImages(), "images are allowed when all extensions are allowed");
|
||||
assert.ok(allowsImages(), "images are allowed when all extensions are allowed");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = "json|jpg|pdf|txt";
|
||||
ok(allowsImages(), "images are allowed when at least one extension is an image extension");
|
||||
assert.ok(allowsImages(), "images are allowed when at least one extension is an image extension");
|
||||
});
|
||||
|
||||
|
||||
test("allowsAttachments", function() {
|
||||
QUnit.test("allowsAttachments", assert => {
|
||||
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif";
|
||||
not(allowsAttachments(), "no attachments allowed by default");
|
||||
assert.not(allowsAttachments(), "no attachments allowed by default");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|*";
|
||||
ok(allowsAttachments(), "attachments are allowed when all extensions are allowed");
|
||||
assert.ok(allowsAttachments(), "attachments are allowed when all extensions are allowed");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|pdf";
|
||||
ok(allowsAttachments(), "attachments are allowed when at least one extension is not an image extension");
|
||||
assert.ok(allowsAttachments(), "attachments are allowed when at least one extension is not an image extension");
|
||||
|
||||
Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif|.pdf";
|
||||
ok(allowsAttachments(), "works with old extensions syntax");
|
||||
assert.ok(allowsAttachments(), "works with old extensions syntax");
|
||||
});
|
||||
|
||||
test("defaultHomepage", function() {
|
||||
QUnit.test("defaultHomepage", assert => {
|
||||
Discourse.SiteSettings.top_menu = "latest|top|hot";
|
||||
equal(defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting");
|
||||
assert.equal(defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting");
|
||||
});
|
||||
|
||||
test("caretRowCol", () => {
|
||||
QUnit.test("caretRowCol", assert => {
|
||||
var textarea = document.createElement('textarea');
|
||||
const content = document.createTextNode("01234\n56789\n012345");
|
||||
textarea.appendChild(content);
|
||||
@@ -217,8 +216,8 @@ test("caretRowCol", () => {
|
||||
setCaretPosition(textarea, setCaretPos);
|
||||
|
||||
const result = caretRowCol(textarea);
|
||||
equal(result.rowNum, expectedRowNum, "returns the right row of the caret");
|
||||
equal(result.colNum, expectedColNum, "returns the right col of the caret");
|
||||
assert.equal(result.rowNum, expectedRowNum, "returns the right row of the caret");
|
||||
assert.equal(result.colNum, expectedColNum, "returns the right col of the caret");
|
||||
};
|
||||
|
||||
assertResult(0, 1, 0);
|
||||
@@ -228,4 +227,4 @@ test("caretRowCol", () => {
|
||||
assertResult(14, 3, 2);
|
||||
|
||||
document.body.removeChild(textarea);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user