Moved a bunch of tests to QUnit. Added basic `Discourse.Site` support to test suite.
This commit is contained in:
parent
2174c0d661
commit
797b99db7c
|
@ -18,8 +18,7 @@ Discourse.Presence = Em.Mixin.create({
|
|||
@return {Boolean}
|
||||
*/
|
||||
blank: function(name) {
|
||||
var prop;
|
||||
prop = this[name] || this.get(name);
|
||||
var prop = this[name] || this.get(name);
|
||||
if (!prop) return true;
|
||||
|
||||
switch (typeof prop) {
|
||||
|
|
|
@ -4,202 +4,6 @@ describe("Discourse.BBCode", function() {
|
|||
|
||||
var format = Discourse.BBCode.format;
|
||||
|
||||
describe('default replacer', function() {
|
||||
|
||||
describe("simple tags", function() {
|
||||
|
||||
it("bolds text", function() {
|
||||
expect(format("[b]strong[/b]")).toBe("<span class='bbcode-b'>strong</span>");
|
||||
});
|
||||
|
||||
it("italics text", function() {
|
||||
expect(format("[i]emphasis[/i]")).toBe("<span class='bbcode-i'>emphasis</span>");
|
||||
});
|
||||
|
||||
it("underlines text", function() {
|
||||
expect(format("[u]underlined[/u]")).toBe("<span class='bbcode-u'>underlined</span>");
|
||||
});
|
||||
|
||||
it("strikes-through text", function() {
|
||||
expect(format("[s]strikethrough[/s]")).toBe("<span class='bbcode-s'>strikethrough</span>");
|
||||
});
|
||||
|
||||
it("makes code into pre", function() {
|
||||
expect(format("[code]\nx++\n[/code]")).toBe("<pre>\nx++\n</pre>");
|
||||
});
|
||||
|
||||
it("supports spoiler tags", function() {
|
||||
expect(format("[spoiler]it's a sled[/spoiler]")).toBe("<span class=\"spoiler\">it's a sled</span>");
|
||||
});
|
||||
|
||||
it("links images", function() {
|
||||
expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">");
|
||||
});
|
||||
|
||||
it("supports [url] without a title", function() {
|
||||
expect(format("[url]http://bettercallsaul.com[/url]")).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>");
|
||||
});
|
||||
|
||||
it("supports [email] without a title", function() {
|
||||
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() {
|
||||
expect(format("[ul][li]option one[/li][/ul]")).toBe("<ul><li>option one</li></ul>");
|
||||
});
|
||||
|
||||
it("creates an ol", function() {
|
||||
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() {
|
||||
expect(format("[color=#00f]blue[/color]")).toBe("<span style=\"color: #00f\">blue</span>");
|
||||
});
|
||||
|
||||
it("supports [color=] with a long hex value", function() {
|
||||
expect(format("[color=#ffff00]yellow[/color]")).toBe("<span style=\"color: #ffff00\">yellow</span>");
|
||||
});
|
||||
|
||||
it("supports [color=] with an html color", function() {
|
||||
expect(format("[color=red]red[/color]")).toBe("<span style=\"color: red\">red</span>");
|
||||
});
|
||||
|
||||
it("it performs a noop on invalid input", function() {
|
||||
expect(format("[color=javascript:alert('wat')]noop[/color]")).toBe("noop");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("tags with arguments", function() {
|
||||
|
||||
it("supports [size=]", function() {
|
||||
expect(format("[size=35]BIG[/size]")).toBe("<span class=\"bbcode-size-35\">BIG</span>");
|
||||
});
|
||||
|
||||
it("supports [url] with a title", function() {
|
||||
expect(format("[url=http://bettercallsaul.com]better call![/url]")).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>");
|
||||
});
|
||||
|
||||
it("supports [email] with a title", function() {
|
||||
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("more complicated", function() {
|
||||
|
||||
it("can nest tags", function() {
|
||||
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", function() {
|
||||
expect(format("[b]first[/b] [b]second[/b]")).toBe("<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('email environment', function() {
|
||||
|
||||
describe("simple tags", function() {
|
||||
|
||||
it("bolds text", function() {
|
||||
expect(format("[b]strong[/b]", { environment: 'email' })).toBe("<b>strong</b>");
|
||||
});
|
||||
|
||||
it("italics text", function() {
|
||||
expect(format("[i]emphasis[/i]", { environment: 'email' })).toBe("<i>emphasis</i>");
|
||||
});
|
||||
|
||||
it("underlines text", function() {
|
||||
expect(format("[u]underlined[/u]", { environment: 'email' })).toBe("<u>underlined</u>");
|
||||
});
|
||||
|
||||
it("strikes-through text", function() {
|
||||
expect(format("[s]strikethrough[/s]", { environment: 'email' })).toBe("<s>strikethrough</s>");
|
||||
});
|
||||
|
||||
it("makes code into pre", function() {
|
||||
expect(format("[code]\nx++\n[/code]", { environment: 'email' })).toBe("<pre>\nx++\n</pre>");
|
||||
});
|
||||
|
||||
it("supports spoiler tags", function() {
|
||||
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() {
|
||||
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() {
|
||||
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", function() {
|
||||
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() {
|
||||
expect(format("[ul][li]option one[/li][/ul]", { environment: 'email' })).toBe("<ul><li>option one</li></ul>");
|
||||
});
|
||||
|
||||
it("creates an ol", function() {
|
||||
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() {
|
||||
expect(format("[color=#00f]blue[/color]", { environment: 'email' })).toBe("<span style=\"color: #00f\">blue</span>");
|
||||
});
|
||||
|
||||
it("supports [color=] with a long hex value", function() {
|
||||
expect(format("[color=#ffff00]yellow[/color]", { environment: 'email' })).toBe("<span style=\"color: #ffff00\">yellow</span>");
|
||||
});
|
||||
|
||||
it("supports [color=] with an html color", function() {
|
||||
expect(format("[color=red]red[/color]", { environment: 'email' })).toBe("<span style=\"color: red\">red</span>");
|
||||
});
|
||||
|
||||
it("it performs a noop on invalid input", function() {
|
||||
expect(format("[color=javascript:alert('wat')]noop[/color]", { environment: 'email' })).toBe("noop");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("tags with arguments", function() {
|
||||
|
||||
it("supports [size=]", function() {
|
||||
expect(format("[size=35]BIG[/size]", { environment: 'email' })).toBe("<span style=\"font-size: 35px\">BIG</span>");
|
||||
});
|
||||
|
||||
it("supports [url] with a title", function() {
|
||||
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", function() {
|
||||
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]", { environment: 'email' })).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("quoting", function() {
|
||||
|
||||
// Format text without an avatar lookup
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*global waitsFor:true expect:true describe:true beforeEach:true it:true spyOn:true */
|
||||
|
||||
describe("Discourse.Category", function() {
|
||||
|
||||
describe("slugFor", function() {
|
||||
|
||||
it("returns the slug when it exists", function() {
|
||||
expect(Discourse.Category.slugFor({ slug: 'hello' })).toBe("hello");
|
||||
});
|
||||
|
||||
it("returns id-category when slug is an empty string", function() {
|
||||
expect(Discourse.Category.slugFor({ id: 123, slug: '' })).toBe("123-category");
|
||||
});
|
||||
|
||||
it("returns id-category without a slug", function() {
|
||||
expect(Discourse.Category.slugFor({ id: 456 })).toBe("456-category");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
|
||||
|
||||
describe("Discourse.Composer", function() {
|
||||
|
||||
describe("replyLength", function() {
|
||||
|
||||
it("returns the length of a basic reply", function() {
|
||||
var composer = Discourse.Composer.create({ reply: "basic reply" });
|
||||
expect(composer.get('replyLength')).toBe(11);
|
||||
});
|
||||
|
||||
it("trims whitespaces", function() {
|
||||
var composer = Discourse.Composer.create({ reply: " \nbasic reply\t" });
|
||||
expect(composer.get('replyLength')).toBe(11);
|
||||
});
|
||||
|
||||
it("count only significant whitespaces", function() {
|
||||
// this will count the '\n' only once
|
||||
var composer = Discourse.Composer.create({ reply: "ba sic\n\nreply" });
|
||||
expect(composer.get('replyLength')).toBe(12);
|
||||
});
|
||||
|
||||
it("removes quotes", function() {
|
||||
var composer = Discourse.Composer.create({ reply: "1[quote=]not counted[/quote]2[quote=]at all[/quote]3" });
|
||||
expect(composer.get('replyLength')).toBe(3);
|
||||
});
|
||||
|
||||
it("handles nested quotes correctly", function() {
|
||||
var composer = Discourse.Composer.create({ reply: "1[quote=]not[quote=]counted[/quote]yay[/quote]2" });
|
||||
expect(composer.get('replyLength')).toBe(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
||||
|
||||
module("Discourse.BBCode");
|
||||
|
||||
test('format', function(){
|
||||
|
||||
var format = function(input, expected, text) {
|
||||
equal(Discourse.BBCode.format(input), expected, text);
|
||||
}
|
||||
|
||||
format("[b]strong[/b]", "<span class='bbcode-b'>strong</span>", "bolds text");
|
||||
format("[i]emphasis[/i]", "<span class='bbcode-i'>emphasis</span>", "italics text");
|
||||
format("[u]underlined[/u]", "<span class='bbcode-u'>underlined</span>", "underlines text");
|
||||
format("[s]strikethrough[/s]", "<span class='bbcode-s'>strikethrough</span>", "strikes-through text");
|
||||
format("[code]\nx++\n[/code]", "<pre>\nx++\n</pre>", "makes code into pre");
|
||||
format("[spoiler]it's a sled[/spoiler]", "<span class=\"spoiler\">it's a sled</span>", "supports spoiler tags");
|
||||
|
||||
format("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
format("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without a title");
|
||||
format("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
|
||||
// Lists
|
||||
format("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
format("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
|
||||
// Color
|
||||
format("[color=#00f]blue[/color]", "<span style=\"color: #00f\">blue</span>", "supports [color=] with a short hex value");
|
||||
format("[color=#ffff00]yellow[/color]", "<span style=\"color: #ffff00\">yellow</span>", "supports [color=] with a long hex value");
|
||||
format("[color=red]red[/color]", "<span style=\"color: red\">red</span>", "supports [color=] with an html color");
|
||||
format("[color=javascript:alert('wat')]noop[/color]", "noop", "it performs a noop on invalid input");
|
||||
|
||||
// Tags with arguments
|
||||
format("[size=35]BIG[/size]", "<span class=\"bbcode-size-35\">BIG</span>", "supports [size=]");
|
||||
|
||||
format("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
format("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
format("[u][i]abc[/i][/u]", "<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>", "can nest tags");
|
||||
format("[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");
|
||||
|
||||
|
||||
});
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,6 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
|
||||
|
||||
module("Header", {
|
||||
|
||||
setup: function() {
|
||||
Ember.run(Discourse, Discourse.advanceReadiness);
|
||||
},
|
||||
|
@ -12,7 +11,6 @@ module("Header", {
|
|||
});
|
||||
|
||||
test("/", function() {
|
||||
expect(2);
|
||||
|
||||
visit("/").then(function() {
|
||||
ok(exists("header"), "The header was rendered");
|
||||
|
|
|
@ -11,7 +11,6 @@ module("List Topics", {
|
|||
});
|
||||
|
||||
test("/", function() {
|
||||
expect(2);
|
||||
|
||||
visit("/").then(function() {
|
||||
ok(exists("#topic-list"), "The list of topics was rendered");
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
||||
|
||||
module("Discourse.Category");
|
||||
|
||||
test('slugFor', function(){
|
||||
|
||||
var slugFor = function(args, val, text) {
|
||||
equal(Discourse.Category.slugFor(args), val, text);
|
||||
}
|
||||
|
||||
slugFor({slug: 'hello'}, "hello", "It calculates the proper slug for hello");
|
||||
slugFor({id: 123, slug: ''}, "123-category", "It returns id-category for empty strings");
|
||||
slugFor({id: 456}, "456-category", "It returns id-category for undefined slugs");
|
||||
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
||||
|
||||
module("Discourse.Composer");
|
||||
|
||||
|
||||
test('replyLength', function() {
|
||||
|
||||
var replyLength = function(val, expectedLength, text) {
|
||||
var composer = Discourse.Composer.create({ reply: val });
|
||||
equal(composer.get('replyLength'), expectedLength);
|
||||
};
|
||||
|
||||
replyLength("basic reply", 11, "basic reply length");
|
||||
replyLength(" \nbasic reply\t", 11, "trims whitespaces");
|
||||
replyLength("ba sic\n\nreply", 12, "count only significant whitespaces");
|
||||
replyLength("1[quote=]not counted[/quote]2[quote=]at all[/quote]3", 3, "removes quotes");
|
||||
replyLength("1[quote=]not[quote=]counted[/quote]yay[/quote]2", 2, "handles nested quotes correctly");
|
||||
|
||||
})
|
|
@ -0,0 +1,13 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true present:true equal:true */
|
||||
|
||||
module("Discourse.Site");
|
||||
|
||||
test('instance', function(){
|
||||
|
||||
var site = Discourse.Site.instance();
|
||||
|
||||
present(site, "We have a current site singleton");
|
||||
present(site.get('categories'), "The instance has a list of categories");
|
||||
present(site.get('flagTypes'), "The instance has a list of flag types");
|
||||
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
/*jshint maxlen:250 */
|
||||
/*global count:true find:true document:true */
|
||||
/*global count:true find:true document:true equal:true */
|
||||
|
||||
//= require env
|
||||
|
||||
|
@ -57,4 +57,24 @@ function exists(selector) {
|
|||
|
||||
function count(selector) {
|
||||
return find(selector).length;
|
||||
}
|
||||
}
|
||||
|
||||
function objBlank(obj) {
|
||||
if (obj === undefined) return true;
|
||||
|
||||
switch (typeof obj) {
|
||||
case "string":
|
||||
return obj.trim().length === 0;
|
||||
case "object":
|
||||
return $.isEmptyObject(obj);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function present(obj, text) {
|
||||
equal(objBlank(obj), false, text);
|
||||
}
|
||||
|
||||
function blank(obj, text) {
|
||||
equal(objBlank(obj), true, text);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue