mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Add ES6 support to more files
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("Category Edit", { loggedIn: true });
|
||||
@ -24,7 +25,7 @@ test("Change the category color", (assert) => {
|
||||
click('#save-category');
|
||||
andThen(() => {
|
||||
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
|
||||
assert.equal(Discourse.URL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
|
||||
assert.equal(DiscourseURL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
|
||||
});
|
||||
});
|
||||
|
||||
@ -37,6 +38,6 @@ test("Change the topic template", (assert) => {
|
||||
click('#save-category');
|
||||
andThen(() => {
|
||||
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
|
||||
assert.equal(Discourse.URL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
|
||||
assert.equal(DiscourseURL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,9 @@
|
||||
var testMouseTrap;
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
|
||||
module("Discourse.KeyboardShortcuts", {
|
||||
var testMouseTrap;
|
||||
import KeyboardShortcuts from 'discourse/lib/keyboard-shortcuts';
|
||||
|
||||
module("lib:keyboard-shortcuts", {
|
||||
setup: function() {
|
||||
var _bindings = {};
|
||||
|
||||
@ -23,7 +26,7 @@ module("Discourse.KeyboardShortcuts", {
|
||||
}
|
||||
};
|
||||
|
||||
sandbox.stub(Discourse.URL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
|
||||
$("#qunit-fixture").html([
|
||||
"<article class='topic-post selected'>",
|
||||
@ -64,20 +67,20 @@ module("Discourse.KeyboardShortcuts", {
|
||||
}
|
||||
});
|
||||
|
||||
var pathBindings = Discourse.KeyboardShortcuts.PATH_BINDINGS;
|
||||
var pathBindings = KeyboardShortcuts.PATH_BINDINGS;
|
||||
|
||||
_.each(pathBindings, function(path, binding) {
|
||||
var testName = binding + " goes to " + path;
|
||||
|
||||
test(testName, function() {
|
||||
Discourse.KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
testMouseTrap.trigger(binding);
|
||||
|
||||
ok(Discourse.URL.routeTo.calledWith(path));
|
||||
ok(DiscourseURL.routeTo.calledWith(path));
|
||||
});
|
||||
});
|
||||
|
||||
var clickBindings = Discourse.KeyboardShortcuts.CLICK_BINDINGS;
|
||||
var clickBindings = KeyboardShortcuts.CLICK_BINDINGS;
|
||||
|
||||
_.each(clickBindings, function(selector, binding) {
|
||||
var bindings = binding.split(",");
|
||||
@ -85,7 +88,7 @@ _.each(clickBindings, function(selector, binding) {
|
||||
var testName = binding + " clicks on " + selector;
|
||||
|
||||
test(testName, function() {
|
||||
Discourse.KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
$(selector).on("click", function() {
|
||||
ok(true, selector + " was clicked");
|
||||
});
|
||||
@ -96,32 +99,32 @@ _.each(clickBindings, function(selector, binding) {
|
||||
});
|
||||
});
|
||||
|
||||
var functionBindings = Discourse.KeyboardShortcuts.FUNCTION_BINDINGS;
|
||||
var functionBindings = KeyboardShortcuts.FUNCTION_BINDINGS;
|
||||
|
||||
_.each(functionBindings, function(func, binding) {
|
||||
var testName = binding + " calls " + func;
|
||||
|
||||
test(testName, function() {
|
||||
sandbox.stub(Discourse.KeyboardShortcuts, func, function() {
|
||||
sandbox.stub(KeyboardShortcuts, func, function() {
|
||||
ok(true, func + " is called when " + binding + " is triggered");
|
||||
});
|
||||
Discourse.KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
|
||||
testMouseTrap.trigger(binding);
|
||||
});
|
||||
});
|
||||
|
||||
test("selectDown calls _moveSelection with 1", function() {
|
||||
var spy = sandbox.spy(Discourse.KeyboardShortcuts, '_moveSelection');
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection');
|
||||
|
||||
Discourse.KeyboardShortcuts.selectDown();
|
||||
KeyboardShortcuts.selectDown();
|
||||
ok(spy.calledWith(1), "_moveSelection is called with 1");
|
||||
});
|
||||
|
||||
test("selectUp calls _moveSelection with -1", function() {
|
||||
var spy = sandbox.spy(Discourse.KeyboardShortcuts, '_moveSelection');
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection');
|
||||
|
||||
Discourse.KeyboardShortcuts.selectUp();
|
||||
KeyboardShortcuts.selectUp();
|
||||
ok(spy.calledWith(-1), "_moveSelection is called with -1");
|
||||
});
|
||||
|
||||
@ -131,20 +134,20 @@ test("goBack calls history.back", function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
Discourse.KeyboardShortcuts.goBack();
|
||||
KeyboardShortcuts.goBack();
|
||||
ok(called, "history.back is called");
|
||||
});
|
||||
|
||||
test("nextSection calls _changeSection with 1", function() {
|
||||
var spy = sandbox.spy(Discourse.KeyboardShortcuts, '_changeSection');
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_changeSection');
|
||||
|
||||
Discourse.KeyboardShortcuts.nextSection();
|
||||
KeyboardShortcuts.nextSection();
|
||||
ok(spy.calledWith(1), "_changeSection is called with 1");
|
||||
});
|
||||
|
||||
test("prevSection calls _changeSection with -1", function() {
|
||||
var spy = sandbox.spy(Discourse.KeyboardShortcuts, '_changeSection');
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_changeSection');
|
||||
|
||||
Discourse.KeyboardShortcuts.prevSection();
|
||||
KeyboardShortcuts.prevSection();
|
||||
ok(spy.calledWith(-1), "_changeSection is called with -1");
|
||||
});
|
||||
|
14
test/javascripts/helpers/custom-html-test.js.es6
Normal file
14
test/javascripts/helpers/custom-html-test.js.es6
Normal file
@ -0,0 +1,14 @@
|
||||
module("helper:custom-html");
|
||||
|
||||
import { getCustomHTML, setCustomHTML } from 'discourse/helpers/custom-html';
|
||||
|
||||
test("customHTML", function() {
|
||||
blank(getCustomHTML('evil'), "there is no custom HTML for a key by default");
|
||||
|
||||
setCustomHTML('evil', 'trout');
|
||||
equal(getCustomHTML('evil'), 'trout', 'it retrieves the custom html');
|
||||
|
||||
PreloadStore.store('customHTML', {cookie: 'monster'});
|
||||
equal(getCustomHTML('cookie'), 'monster', 'it returns HTML fragments from the PreloadStore');
|
||||
|
||||
});
|
8
test/javascripts/helpers/parse-html.js.es6
Normal file
8
test/javascripts/helpers/parse-html.js.es6
Normal file
@ -0,0 +1,8 @@
|
||||
/* global Tautologistics */
|
||||
export default function parseHTML(rawHtml) {
|
||||
const builder = new Tautologistics.NodeHtmlParser.HtmlBuilder();
|
||||
const parser = new Tautologistics.NodeHtmlParser.Parser(builder);
|
||||
|
||||
parser.parseComplete(rawHtml);
|
||||
return builder.dom;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
/* global Tautologistics */
|
||||
/* exported parseHTML */
|
||||
function parseHTML(rawHtml) {
|
||||
var builder = new Tautologistics.NodeHtmlParser.HtmlBuilder(),
|
||||
parser = new Tautologistics.NodeHtmlParser.Parser(builder);
|
||||
|
||||
parser.parseComplete(rawHtml);
|
||||
return builder.dom;
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import Quote from 'discourse/lib/quote';
|
||||
|
||||
module("Discourse.BBCode");
|
||||
|
||||
var format = function(input, expected, text) {
|
||||
@ -90,7 +92,7 @@ test("quotes", function() {
|
||||
});
|
||||
|
||||
var formatQuote = function(val, expected, text) {
|
||||
equal(Discourse.Quote.build(post, val), expected, text);
|
||||
equal(Quote.build(post, val), expected, text);
|
||||
};
|
||||
|
||||
formatQuote(undefined, "", "empty string for undefined content");
|
||||
|
@ -1,5 +1,6 @@
|
||||
module("lib:category-link");
|
||||
|
||||
import parseHTML from 'helpers/parse-html';
|
||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||
|
||||
test("categoryBadge without a category", function() {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
var windowOpen,
|
||||
@ -9,7 +10,7 @@ module("lib:click-track", {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
redirectTo = sandbox.stub(Discourse.URL, "redirectTo");
|
||||
redirectTo = sandbox.stub(DiscourseURL, "redirectTo");
|
||||
sandbox.stub(Discourse, "ajax");
|
||||
windowOpen = sandbox.stub(window, "open").returns(win);
|
||||
sandbox.stub(win, "focus");
|
||||
@ -51,7 +52,7 @@ test("it calls preventDefault when clicking on an a", function() {
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(Discourse.URL.redirectTo.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
@ -70,7 +71,7 @@ test("removes the href and put it as a data attribute", function() {
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(Discourse.URL.redirectTo.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTest("restores the href after a while", function() {
|
||||
@ -159,20 +160,20 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
sandbox.stub(Discourse.URL, "routeTo");
|
||||
sandbox.stub(Discourse.URL, "origin").returns("http://discuss.domain.com");
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(Discourse.ajax.calledOnce);
|
||||
ok(Discourse.URL.routeTo.calledOnce);
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
sandbox.stub(Discourse.URL, "routeTo");
|
||||
sandbox.stub(Discourse.URL, "origin").returns("http://discuss.domain.com");
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(Discourse.URL.redirectTo.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
|
@ -1,14 +0,0 @@
|
||||
module("Discourse.HTML");
|
||||
|
||||
var html = Discourse.HTML;
|
||||
|
||||
test("customHTML", function() {
|
||||
blank(html.getCustomHTML('evil'), "there is no custom HTML for a key by default");
|
||||
|
||||
html.setCustomHTML('evil', 'trout');
|
||||
equal(html.getCustomHTML('evil'), 'trout', 'it retrieves the custom html');
|
||||
|
||||
PreloadStore.store('customHTML', {cookie: 'monster'});
|
||||
equal(html.getCustomHTML('cookie'), 'monster', 'it returns HTML fragments from the PreloadStore');
|
||||
|
||||
});
|
@ -1,16 +1,18 @@
|
||||
module("Discourse.URL");
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
|
||||
module("lib:url");
|
||||
|
||||
test("isInternal with a HTTP url", function() {
|
||||
sandbox.stub(Discourse.URL, "origin").returns("http://eviltrout.com");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com");
|
||||
|
||||
not(Discourse.URL.isInternal(null), "a blank URL is not internal");
|
||||
ok(Discourse.URL.isInternal("/test"), "relative URLs are internal");
|
||||
ok(Discourse.URL.isInternal("http://eviltrout.com/tophat"), "a url on the same host is internal");
|
||||
ok(Discourse.URL.isInternal("https://eviltrout.com/moustache"), "a url on a HTTPS of the same host is internal");
|
||||
not(Discourse.URL.isInternal("http://twitter.com"), "a different host is not internal");
|
||||
not(DiscourseURL.isInternal(null), "a blank URL is not internal");
|
||||
ok(DiscourseURL.isInternal("/test"), "relative URLs are internal");
|
||||
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("http://twitter.com"), "a different host is not internal");
|
||||
});
|
||||
|
||||
test("isInternal with a HTTPS url", function() {
|
||||
sandbox.stub(Discourse.URL, "origin").returns("https://eviltrout.com");
|
||||
ok(Discourse.URL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("https://eviltrout.com");
|
||||
ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls");
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
module("Discourse.Invite");
|
||||
import Invite from 'discourse/models/invite';
|
||||
|
||||
module("model:invite");
|
||||
|
||||
test("create", function() {
|
||||
ok(Discourse.Invite.create(), "it can be created without arguments");
|
||||
ok(Invite.create(), "it can be created without arguments");
|
||||
});
|
||||
|
@ -6,7 +6,7 @@
|
||||
//= require ../../app/assets/javascripts/preload_store
|
||||
|
||||
// probe framework first
|
||||
//= require ../../app/assets/javascripts/discourse/lib/probes
|
||||
//= require probes
|
||||
|
||||
// Externals we need to load first
|
||||
//= require jquery.debug
|
||||
@ -80,6 +80,7 @@ var origDebounce = Ember.run.debounce,
|
||||
fixtures = require('fixtures/site_fixtures', null, null, false).default,
|
||||
flushMap = require('discourse/models/store', null, null, false).flushMap,
|
||||
ScrollingDOMMethods = require('discourse/mixins/scrolling', null, null, false).ScrollingDOMMethods,
|
||||
_DiscourseURL = require('discourse/lib/url', null, null, false).default,
|
||||
server;
|
||||
|
||||
function dup(obj) {
|
||||
@ -97,9 +98,9 @@ QUnit.testStart(function(ctx) {
|
||||
Discourse.User.resetCurrent();
|
||||
Discourse.Site.resetCurrent(Discourse.Site.create(dup(fixtures['site.json'].site)));
|
||||
|
||||
Discourse.URL.redirectedTo = null;
|
||||
Discourse.URL.redirectTo = function(url) {
|
||||
Discourse.URL.redirectedTo = url;
|
||||
_DiscourseURL.redirectedTo = null;
|
||||
_DiscourseURL.redirectTo = function(url) {
|
||||
_DiscourseURL.redirectedTo = url;
|
||||
};
|
||||
|
||||
PreloadStore.reset();
|
||||
|
Reference in New Issue
Block a user