Convert all CoffeeScript to Javascript. See:

http://meta.discourse.org/t/is-it-better-for-discourse-to-use-javascript-or-coffeescript/3153
This commit is contained in:
Robin Ward
2013-02-20 13:15:50 -05:00
parent 68ad545f0f
commit f661fa609e
407 changed files with 13226 additions and 8953 deletions

View File

@ -0,0 +1,181 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.BBCode", function() {
var format;
format = Discourse.BBCode.format;
describe('default replacer', function() {
describe("simple tags", function() {
it("bolds text", function() {
return expect(format("[b]strong[/b]")).toBe("<span class='bbcode-b'>strong</span>");
});
it("italics text", function() {
return expect(format("[i]emphasis[/i]")).toBe("<span class='bbcode-i'>emphasis</span>");
});
it("underlines text", function() {
return expect(format("[u]underlined[/u]")).toBe("<span class='bbcode-u'>underlined</span>");
});
it("strikes-through text", function() {
return expect(format("[s]strikethrough[/s]")).toBe("<span class='bbcode-s'>strikethrough</span>");
});
it("makes code into pre", function() {
return expect(format("[code]\nx++\n[/code]")).toBe("<pre>\nx++\n</pre>");
});
it("supports spoiler tags", function() {
return expect(format("[spoiler]it's a sled[/spoiler]")).toBe("<span class=\"spoiler\">it's a sled</span>");
});
it("links images", function() {
return expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">");
});
it("supports [url] without a title", function() {
return expect(format("[url]http://bettercallsaul.com[/url]")).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>");
});
return it("supports [email] without a title", function() {
return expect(format("[email]eviltrout@mailinator.com[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>");
});
});
describe("lists", function() {
it("creates an ul", function() {
return expect(format("[ul][li]option one[/li][/ul]")).toBe("<ul><li>option one</li></ul>");
});
return it("creates an ol", function() {
return expect(format("[ol][li]option one[/li][/ol]")).toBe("<ol><li>option one</li></ol>");
});
});
describe("color", function() {
it("supports [color=] with a short hex value", function() {
return expect(format("[color=#00f]blue[/color]")).toBe("<span style=\"color: #00f\">blue</span>");
});
it("supports [color=] with a long hex value", function() {
return expect(format("[color=#ffff00]yellow[/color]")).toBe("<span style=\"color: #ffff00\">yellow</span>");
});
it("supports [color=] with an html color", function() {
return expect(format("[color=red]red[/color]")).toBe("<span style=\"color: red\">red</span>");
});
return it("it performs a noop on invalid input", function() {
return expect(format("[color=javascript:alert('wat')]noop[/color]")).toBe("noop");
});
});
describe("tags with arguments", function() {
it("supports [size=]", function() {
return expect(format("[size=35]BIG[/size]")).toBe("<span class=\"bbcode-size-35\">BIG</span>");
});
it("supports [url] with a title", function() {
return expect(format("[url=http://bettercallsaul.com]better call![/url]")).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>");
});
return it("supports [email] with a title", function() {
return expect(format("[email=eviltrout@mailinator.com]evil trout[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
});
});
return describe("more complicated", function() {
it("can nest tags", function() {
return expect(format("[u][i]abc[/i][/u]")).toBe("<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>");
});
return it("can bold two things on the same line", function() {
return expect(format("[b]first[/b] [b]second[/b]")).toBe("<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>");
});
});
});
return describe('email environment', function() {
describe("simple tags", function() {
it("bolds text", function() {
return expect(format("[b]strong[/b]", {
environment: 'email'
})).toBe("<b>strong</b>");
});
it("italics text", function() {
return expect(format("[i]emphasis[/i]", {
environment: 'email'
})).toBe("<i>emphasis</i>");
});
it("underlines text", function() {
return expect(format("[u]underlined[/u]", {
environment: 'email'
})).toBe("<u>underlined</u>");
});
it("strikes-through text", function() {
return expect(format("[s]strikethrough[/s]", {
environment: 'email'
})).toBe("<s>strikethrough</s>");
});
it("makes code into pre", function() {
return expect(format("[code]\nx++\n[/code]", {
environment: 'email'
})).toBe("<pre>\nx++\n</pre>");
});
it("supports spoiler tags", function() {
return expect(format("[spoiler]it's a sled[/spoiler]", {
environment: 'email'
})).toBe("<span style='background-color: #000'>it's a sled</span>");
});
it("links images", function() {
return expect(format("[img]http://eviltrout.com/eviltrout.png[/img]", {
environment: 'email'
})).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">");
});
it("supports [url] without a title", function() {
return expect(format("[url]http://bettercallsaul.com[/url]", {
environment: 'email'
})).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>");
});
return it("supports [email] without a title", function() {
return expect(format("[email]eviltrout@mailinator.com[/email]", {
environment: 'email'
})).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>");
});
});
describe("lists", function() {
it("creates an ul", function() {
return expect(format("[ul][li]option one[/li][/ul]", {
environment: 'email'
})).toBe("<ul><li>option one</li></ul>");
});
return it("creates an ol", function() {
return expect(format("[ol][li]option one[/li][/ol]", {
environment: 'email'
})).toBe("<ol><li>option one</li></ol>");
});
});
describe("color", function() {
it("supports [color=] with a short hex value", function() {
return expect(format("[color=#00f]blue[/color]", {
environment: 'email'
})).toBe("<span style=\"color: #00f\">blue</span>");
});
it("supports [color=] with a long hex value", function() {
return expect(format("[color=#ffff00]yellow[/color]", {
environment: 'email'
})).toBe("<span style=\"color: #ffff00\">yellow</span>");
});
it("supports [color=] with an html color", function() {
return expect(format("[color=red]red[/color]", {
environment: 'email'
})).toBe("<span style=\"color: red\">red</span>");
});
return it("it performs a noop on invalid input", function() {
return expect(format("[color=javascript:alert('wat')]noop[/color]", {
environment: 'email'
})).toBe("noop");
});
});
return describe("tags with arguments", function() {
it("supports [size=]", function() {
return expect(format("[size=35]BIG[/size]", {
environment: 'email'
})).toBe("<span style=\"font-size: 35px\">BIG</span>");
});
it("supports [url] with a title", function() {
return expect(format("[url=http://bettercallsaul.com]better call![/url]", {
environment: 'email'
})).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>");
});
return it("supports [email] with a title", function() {
return expect(format("[email=eviltrout@mailinator.com]evil trout[/email]", {
environment: 'email'
})).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
});
});
});
});
}).call(this);

View File

@ -1,138 +0,0 @@
describe "Discourse.BBCode", ->
format = Discourse.BBCode.format
describe 'default replacer', ->
describe "simple tags", ->
it "bolds text", ->
expect(format("[b]strong[/b]")).toBe("<span class='bbcode-b'>strong</span>")
it "italics text", ->
expect(format("[i]emphasis[/i]")).toBe("<span class='bbcode-i'>emphasis</span>")
it "underlines text", ->
expect(format("[u]underlined[/u]")).toBe("<span class='bbcode-u'>underlined</span>")
it "strikes-through text", ->
expect(format("[s]strikethrough[/s]")).toBe("<span class='bbcode-s'>strikethrough</span>")
it "makes code into pre", ->
expect(format("[code]\nx++\n[/code]")).toBe("<pre>\nx++\n</pre>")
it "supports spoiler tags", ->
expect(format("[spoiler]it's a sled[/spoiler]")).toBe("<span class=\"spoiler\">it's a sled</span>")
it "links images", ->
expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">")
it "supports [url] without a title", ->
expect(format("[url]http://bettercallsaul.com[/url]")).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>")
it "supports [email] without a title", ->
expect(format("[email]eviltrout@mailinator.com[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>")
describe "lists", ->
it "creates an ul", ->
expect(format("[ul][li]option one[/li][/ul]")).toBe("<ul><li>option one</li></ul>")
it "creates an ol", ->
expect(format("[ol][li]option one[/li][/ol]")).toBe("<ol><li>option one</li></ol>")
describe "color", ->
it "supports [color=] with a short hex value", ->
expect(format("[color=#00f]blue[/color]")).toBe("<span style=\"color: #00f\">blue</span>")
it "supports [color=] with a long hex value", ->
expect(format("[color=#ffff00]yellow[/color]")).toBe("<span style=\"color: #ffff00\">yellow</span>")
it "supports [color=] with an html color", ->
expect(format("[color=red]red[/color]")).toBe("<span style=\"color: red\">red</span>")
it "it performs a noop on invalid input", ->
expect(format("[color=javascript:alert('wat')]noop[/color]")).toBe("noop")
describe "tags with arguments", ->
it "supports [size=]", ->
expect(format("[size=35]BIG[/size]")).toBe("<span class=\"bbcode-size-35\">BIG</span>")
it "supports [url] with a title", ->
expect(format("[url=http://bettercallsaul.com]better call![/url]")).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>")
it "supports [email] with a title", ->
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>")
describe "more complicated", ->
it "can nest tags", ->
expect(format("[u][i]abc[/i][/u]")).toBe("<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>")
it "can bold two things on the same line", ->
expect(format("[b]first[/b] [b]second[/b]")).toBe("<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>")
describe 'email environment', ->
describe "simple tags", ->
it "bolds text", ->
expect(format("[b]strong[/b]", environment: 'email')).toBe("<b>strong</b>")
it "italics text", ->
expect(format("[i]emphasis[/i]", environment: 'email')).toBe("<i>emphasis</i>")
it "underlines text", ->
expect(format("[u]underlined[/u]", environment: 'email')).toBe("<u>underlined</u>")
it "strikes-through text", ->
expect(format("[s]strikethrough[/s]", environment: 'email')).toBe("<s>strikethrough</s>")
it "makes code into pre", ->
expect(format("[code]\nx++\n[/code]", environment: 'email')).toBe("<pre>\nx++\n</pre>")
it "supports spoiler tags", ->
expect(format("[spoiler]it's a sled[/spoiler]", environment: 'email')).toBe("<span style='background-color: #000'>it's a sled</span>")
it "links images", ->
expect(format("[img]http://eviltrout.com/eviltrout.png[/img]", environment: 'email')).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">")
it "supports [url] without a title", ->
expect(format("[url]http://bettercallsaul.com[/url]", environment: 'email')).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>")
it "supports [email] without a title", ->
expect(format("[email]eviltrout@mailinator.com[/email]", environment: 'email')).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>")
describe "lists", ->
it "creates an ul", ->
expect(format("[ul][li]option one[/li][/ul]", environment: 'email')).toBe("<ul><li>option one</li></ul>")
it "creates an ol", ->
expect(format("[ol][li]option one[/li][/ol]", environment: 'email')).toBe("<ol><li>option one</li></ol>")
describe "color", ->
it "supports [color=] with a short hex value", ->
expect(format("[color=#00f]blue[/color]", environment: 'email')).toBe("<span style=\"color: #00f\">blue</span>")
it "supports [color=] with a long hex value", ->
expect(format("[color=#ffff00]yellow[/color]", environment: 'email')).toBe("<span style=\"color: #ffff00\">yellow</span>")
it "supports [color=] with an html color", ->
expect(format("[color=red]red[/color]", environment: 'email')).toBe("<span style=\"color: red\">red</span>")
it "it performs a noop on invalid input", ->
expect(format("[color=javascript:alert('wat')]noop[/color]", environment: 'email')).toBe("noop")
describe "tags with arguments", ->
it "supports [size=]", ->
expect(format("[size=35]BIG[/size]", environment: 'email')).toBe("<span style=\"font-size: 35px\">BIG</span>")
it "supports [url] with a title", ->
expect(format("[url=http://bettercallsaul.com]better call![/url]", environment: 'email')).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>")
it "supports [email] with a title", ->
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]", environment: 'email')).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>")

View File

@ -8,7 +8,7 @@
currentWindowOnload();
}
$('<div id="main"><div class="rootElement"></div></div>').appendTo($('body')).hide();
jQuery('<div id="main"><div class="rootElement"></div></div>').appendTo(jQuery('body')).hide();
Discourse.SiteSettings = {}

View File

@ -0,0 +1,30 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.KeyValueStore", function() {
return describe("Setting values", function() {
var store;
store = Discourse.KeyValueStore;
store.init("test");
it("able to get the value back from the store", function() {
store.set({
key: "bob",
value: "uncle"
});
return expect(store.get("bob")).toBe("uncle");
});
return it("able to nuke the store", function() {
store.set({
key: "bob1",
value: "uncle"
});
store.abandonLocal();
localStorage.a = 1;
expect(store.get("bob1")).toBe(void 0);
return expect(localStorage.a).toBe("1");
});
});
});
}).call(this);

View File

@ -1,17 +0,0 @@
describe "Discourse.KeyValueStore", ->
describe "Setting values", ->
store = Discourse.KeyValueStore
store.init("test")
it "able to get the value back from the store", ->
store.set(key: "bob", value: "uncle")
expect(store.get("bob")).toBe("uncle")
it "able to nuke the store", ->
store.set(key: "bob1", value: "uncle")
store.abandonLocal()
localStorage["a"] = 1
expect(store.get("bob1")).toBe(undefined)
expect(localStorage["a"]).toBe("1")

View File

@ -0,0 +1,13 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.MessageBus", function() {
return describe("Long polling", function() {
var bus;
bus = Discourse.MessageBus;
return bus.start();
});
});
}).call(this);

View File

@ -1,24 +0,0 @@
describe "Discourse.MessageBus", ->
describe "Long polling", ->
bus = Discourse.MessageBus
bus.start()
# PENDING: Fix to allow these to run in jasmine-guard
#it "is able to get a response from the echo server", ->
# response = null
# bus.send("/echo", "hello world", (r) -> response = r)
# # give it some time to spin up
# waitsFor((-> response == "hello world"),"gotEcho",500)
#it "should get responses from broadcast channel", ->
# response = null
# # note /message_bus/broadcast is dev only
# bus.subscribe("/animals", (r) -> response = r)
# $.ajax
# url: '/message-bus/broadcast'
# data: {channel: "/animals", data: "kitten"}
# cache: false
# waitsFor((-> response == "kitten"),"gotBroadcast", 500)

View File

@ -1,14 +0,0 @@
describe "Discourse.Onebox", ->
beforeEach ->
spyOn($, 'ajax').andCallThrough()
it "Stops rapid calls with cache true", ->
Discourse.Onebox.lookup('http://bla.com', true, (c) -> c)
Discourse.Onebox.lookup('http://bla.com', true, (c) -> c)
expect($.ajax.calls.length).toBe(1)
it "Stops rapid calls with cache false", ->
Discourse.Onebox.lookup('http://bla.com/a', false, (c) -> c)
Discourse.Onebox.lookup('http://bla.com/a', false, (c) -> c)
expect($.ajax.calls.length).toBe(1)

View File

@ -0,0 +1,28 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true spyOn:true */
(function() {
describe("Discourse.Onebox", function() {
beforeEach(function() {
return spyOn(jQuery, 'ajax').andCallThrough();
});
it("Stops rapid calls with cache true", function() {
Discourse.Onebox.lookup('http://bla.com', true, function(c) {
return c;
});
Discourse.Onebox.lookup('http://bla.com', true, function(c) {
return c;
});
return expect(jQuery.ajax.calls.length).toBe(1);
});
return it("Stops rapid calls with cache false", function() {
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) {
return c;
});
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) {
return c;
});
return expect(jQuery.ajax.calls.length).toBe(1);
});
});
}).call(this);

View File

@ -0,0 +1,118 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true runs:true */
(function() {
describe("PreloadStore", function() {
beforeEach(function() {
return PreloadStore.store('bane', 'evil');
});
describe("contains", function() {
it("returns false for a key that doesn't exist", function() {
return expect(PreloadStore.contains('joker')).toBe(false);
});
return it("returns true for a stored key", function() {
return expect(PreloadStore.contains('bane')).toBe(true);
});
});
describe('getStatic', function() {
it("returns undefined if the key doesn't exist", function() {
return expect(PreloadStore.getStatic('joker')).toBe(void 0);
});
it("returns the the key if it exists", function() {
return expect(PreloadStore.getStatic('bane')).toBe('evil');
});
return it("removes the key after being called", function() {
PreloadStore.getStatic('bane');
return expect(PreloadStore.getStatic('bane')).toBe(void 0);
});
});
return describe('get', function() {
it("returns a promise that resolves to undefined", function() {
var done, storeResult;
done = storeResult = null;
PreloadStore.get('joker').then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe(void 0);
});
});
it("returns a promise that resolves to the result of the finder", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
return 'evil';
};
PreloadStore.get('joker', finder).then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
it("returns a promise that resolves to the result of the finder's promise", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
var promise;
promise = new RSVP.Promise();
promise.resolve('evil');
return promise;
};
PreloadStore.get('joker', finder).then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
it("returns a promise that resolves to the result of the finder's rejected promise", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
var promise;
promise = new RSVP.Promise();
promise.reject('evil');
return promise;
};
PreloadStore.get('joker', finder).then(null, function(rejectedResult) {
done = true;
storeResult = rejectedResult;
});
waitsFor((function() {
return done;
}), "Promise never rejected", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
return it("returns a promise that resolves to 'evil'", function() {
var done, storeResult;
done = storeResult = null;
PreloadStore.get('bane').then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
});
});
}).call(this);

View File

@ -1,81 +0,0 @@
describe "PreloadStore", ->
beforeEach ->
PreloadStore.store('bane', 'evil')
describe "contains", ->
it "returns false for a key that doesn't exist", ->
expect(PreloadStore.contains('joker')).toBe(false)
it "returns true for a stored key", ->
expect(PreloadStore.contains('bane')).toBe(true)
describe 'getStatic', ->
it "returns undefined if the key doesn't exist", ->
expect(PreloadStore.getStatic('joker')).toBe(undefined)
it "returns the the key if it exists", ->
expect(PreloadStore.getStatic('bane')).toBe('evil')
it "removes the key after being called", ->
PreloadStore.getStatic('bane')
expect(PreloadStore.getStatic('bane')).toBe(undefined)
describe 'get', ->
it "returns a promise that resolves to undefined", ->
done = storeResult = null
PreloadStore.get('joker').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe(undefined)
it "returns a promise that resolves to the result of the finder", ->
done = storeResult = null
finder = -> 'evil'
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.resolve('evil')
promise
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's rejected promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.reject('evil')
promise
PreloadStore.get('joker', finder).then null, (rejectedResult) ->
done = true
storeResult = rejectedResult
waitsFor (-> return done), "Promise never rejected", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to 'evil'", ->
done = storeResult = null
PreloadStore.get('bane').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')

View File

@ -1,15 +1,17 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true sanitizeHtml:true */
describe("sanitize", function(){
it("strips all script tags", function(){
sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
var sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
expect(sanitized)
.toBe("<div></div>");
});
it("strips disallowed attributes", function(){
sanitized = sanitizeHtml("<div><p class=\"funky\" wrong='1'>hello</p></div>");
var sanitized = sanitizeHtml("<div><p class=\"funky\" wrong='1'>hello</p></div>");
expect(sanitized)
.toBe("<div><p class=\"funky\">hello</p></div>");

View File

@ -0,0 +1,34 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.UserAction", function() {
return describe("collapseStream", function() {
return it("collapses all likes", function() {
var actions;
actions = [
Discourse.UserAction.create({
action_type: Discourse.UserAction.LIKE,
topic_id: 1,
user_id: 1,
post_number: 1
}), Discourse.UserAction.create({
action_type: Discourse.UserAction.EDIT,
topic_id: 2,
user_id: 1,
post_number: 1
}), Discourse.UserAction.create({
action_type: Discourse.UserAction.LIKE,
topic_id: 1,
user_id: 2,
post_number: 1
})
];
actions = Discourse.UserAction.collapseStream(actions);
expect(actions.length).toBe(2);
expect(actions[0].get("children").length).toBe(1);
return expect(actions[0].get("children")[0].items.length).toBe(2);
});
});
});
}).call(this);

View File

@ -1,16 +0,0 @@
describe "Discourse.UserAction", ->
describe "collapseStream", ->
it "collapses all likes", ->
actions = [
Discourse.UserAction.create(action_type: Discourse.UserAction.LIKE, topic_id:1, user_id:1, post_number:1)
Discourse.UserAction.create(action_type: Discourse.UserAction.EDIT, topic_id:2, user_id:1, post_number:1)
Discourse.UserAction.create(action_type: Discourse.UserAction.LIKE, topic_id:1, user_id:2, post_number:1)
]
actions = Discourse.UserAction.collapseStream(actions)
expect(actions.length).toBe(2)
expect(actions[0].get("children").length).toBe(1)
expect(actions[0].get("children")[0].items.length).toBe(2)

View File

@ -0,0 +1,136 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.Utilities", function() {
describe("categoryUrlId", function() {
it("returns the slug when it exists", function() {
return expect(Discourse.Utilities.categoryUrlId({
slug: 'hello'
})).toBe("hello");
});
it("returns id-category when slug is an empty string", function() {
return expect(Discourse.Utilities.categoryUrlId({
id: 123,
slug: ''
})).toBe("123-category");
});
return it("returns id-category without a slug", function() {
return expect(Discourse.Utilities.categoryUrlId({
id: 456
})).toBe("456-category");
});
});
describe("Cooking", function() {
var cook;
cook = function(contents, opts) {
opts = opts || {};
opts.mentionLookup = opts.mentionLookup || (function() {
return false;
});
return Discourse.Utilities.cook(contents, opts);
};
it("surrounds text with paragraphs", function() {
return expect(cook("hello")).toBe("<p>hello</p>");
});
it("automatically handles trivial newlines", function() {
return expect(cook("1\n2\n3")).toBe("<p>1 <br>\n2 <br>\n3</p>");
});
it("handles quotes properly", function() {
var cooked;
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {
topicId: 2,
lookupAvatar: function(name) {
return "" + name;
}
});
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
" bob\n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>");
});
it("includes no avatar if none is found", function() {
var cooked;
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {
topicId: 2,
lookupAvatar: function(name) {
return null;
}
});
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
" \n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>");
});
describe("Links", function() {
it("allows links to contain query params", function() {
expect(cook("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A")).
toBe('<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>');
});
it("escapes double underscores in URLs", function() {
return expect(cook("Derpy: http://derp.com?__test=1")).toBe('<p>Derpy: <a href="http://derp.com?%5F%5Ftest=1">http://derp.com?__test=1</a></p>');
});
it("autolinks something that begins with www", function() {
return expect(cook("Atwood: www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>');
});
it("autolinks a URL with http://www", function() {
return expect(cook("Atwood: http://www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>');
});
it("autolinks a URL", function() {
return expect(cook("EvilTrout: http://eviltrout.com")).toBe('<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>');
});
it("supports markdown style links", function() {
return expect(cook("here is [an example](http://twitter.com)")).toBe('<p>here is <a href="http://twitter.com">an example</a></p>');
});
return it("autolinks a URL with parentheses (like Wikipedia)", function() {
return expect(cook("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)"))
.toBe('<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>');
});
});
describe("Mentioning", function() {
it("translates mentions to links", function() {
return expect(cook("Hello @sam", {
mentionLookup: (function() {
return true;
})
})).toBe("<p>Hello <a href='/users/sam' class='mention'>@sam</a></p>");
});
it("adds a mention class", function() {
return expect(cook("Hello @EvilTrout")).toBe("<p>Hello <span class='mention'>@EvilTrout</span></p>");
});
it("won't add mention class to an email address", function() {
return expect(cook("robin@email.host")).toBe("<p>robin@email.host</p>");
});
it("won't be affected by email addresses that have a number before the @ symbol", function() {
return expect(cook("hanzo55@yahoo.com")).toBe("<p>hanzo55@yahoo.com</p>");
});
return it("supports a @mention at the beginning of a post", function() {
return expect(cook("@EvilTrout yo")).toBe("<p><span class='mention'>@EvilTrout</span> yo</p>");
});
});
return describe("Oneboxing", function() {
it("doesn't onebox a link within a list", function() {
return expect(cook("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org")).not.toMatch(/onebox/);
});
it("adds a onebox class to a link on its own line", function() {
return expect(cook("http://test.com")).toMatch(/onebox/);
});
it("supports multiple links", function() {
return expect(cook("http://test.com\nhttp://test2.com")).toMatch(/onebox[\s\S]+onebox/m);
});
it("doesn't onebox links that have trailing text", function() {
return expect(cook("http://test.com bob")).not.toMatch(/onebox/);
});
return it("works with links that have underscores in them", function() {
return expect(cook("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street")).
toBe("<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>");
});
});
});
return describe("emailValid", function() {
it("allows upper case in first part of emails", function() {
return expect(Discourse.Utilities.emailValid('Bob@example.com')).toBe(true);
});
return it("allows upper case in domain of emails", function() {
return expect(Discourse.Utilities.emailValid('bob@EXAMPLE.com')).toBe(true);
});
});
});
}).call(this);

View File

@ -1,101 +0,0 @@
describe "Discourse.Utilities", ->
describe "categoryUrlId", ->
it "returns the slug when it exists", ->
expect(Discourse.Utilities.categoryUrlId(slug: 'hello')).toBe("hello")
it "returns id-category when slug is an empty string", ->
expect(Discourse.Utilities.categoryUrlId(id: 123, slug: '')).toBe("123-category")
it "returns id-category without a slug", ->
expect(Discourse.Utilities.categoryUrlId(id: 456)).toBe("456-category")
describe "Cooking", ->
cook = (contents, opts) ->
opts = opts || {}
opts.mentionLookup = opts.mentionLookup || (() -> false)
Discourse.Utilities.cook(contents, opts)
it "surrounds text with paragraphs", ->
expect(cook("hello")).toBe("<p>hello</p>")
it "automatically handles trivial newlines", ->
expect(cook("1\n2\n3")).toBe("<p>1 <br>\n2 <br>\n3</p>")
it "handles quotes properly", ->
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {topicId: 2, lookupAvatar: (name) -> "#{name}"})
expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n bob\n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>")
it "includes no avatar if none is found", ->
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {topicId: 2, lookupAvatar: (name) -> null})
expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n \n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>")
describe "Links", ->
it "allows links to contain query params", ->
expect(cook("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A")).toBe('<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>')
it "escapes double underscores in URLs", ->
expect(cook("Derpy: http://derp.com?__test=1")).toBe('<p>Derpy: <a href="http://derp.com?%5F%5Ftest=1">http://derp.com?__test=1</a></p>')
it "autolinks something that begins with www", ->
expect(cook("Atwood: www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>')
it "autolinks a URL with http://www", ->
expect(cook("Atwood: http://www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>')
it "autolinks a URL", ->
expect(cook("EvilTrout: http://eviltrout.com")).toBe('<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>')
it "supports markdown style links", ->
expect(cook("here is [an example](http://twitter.com)")).toBe('<p>here is <a href="http://twitter.com">an example</a></p>')
it "autolinks a URL with parentheses (like Wikipedia)", ->
expect(cook("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)")).toBe('<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>')
describe "Mentioning", ->
it "translates mentions to links", ->
expect(cook("Hello @sam", {mentionLookup: (->true)})).toBe("<p>Hello <a href='/users/sam' class='mention'>@sam</a></p>")
it "adds a mention class", ->
expect(cook("Hello @EvilTrout")).toBe("<p>Hello <span class='mention'>@EvilTrout</span></p>")
it "won't add mention class to an email address", ->
expect(cook("robin@email.host")).toBe("<p>robin@email.host</p>")
it "won't be affected by email addresses that have a number before the @ symbol", ->
expect(cook("hanzo55@yahoo.com")).toBe("<p>hanzo55@yahoo.com</p>")
it "supports a @mention at the beginning of a post", ->
expect(cook("@EvilTrout yo")).toBe("<p><span class='mention'>@EvilTrout</span> yo</p>")
# Oneboxing functionality
describe "Oneboxing", ->
it "doesn't onebox a link within a list", ->
expect(cook("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org")).not.toMatch(/onebox/)
it "adds a onebox class to a link on its own line", ->
expect(cook("http://test.com")).toMatch(/onebox/)
it "supports multiple links", ->
expect(cook("http://test.com\nhttp://test2.com")).toMatch(/onebox[\s\S]+onebox/m)
it "doesn't onebox links that have trailing text", ->
expect(cook("http://test.com bob")).not.toMatch(/onebox/)
it "works with links that have underscores in them", ->
expect(cook("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street")).toBe("<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>")
describe "emailValid", ->
it "allows upper case in first part of emails", ->
expect(Discourse.Utilities.emailValid('Bob@example.com')).toBe(true)
it "allows upper case in domain of emails", ->
expect(Discourse.Utilities.emailValid('bob@EXAMPLE.com')).toBe(true)