/*global waitsFor:true expect:true describe:true beforeEach:true it:true md5:true */ 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("strong"); }); it("italics text", function() { expect(format("[i]emphasis[/i]")).toBe("emphasis"); }); it("underlines text", function() { expect(format("[u]underlined[/u]")).toBe("underlined"); }); it("strikes-through text", function() { expect(format("[s]strikethrough[/s]")).toBe("strikethrough"); }); it("makes code into pre", function() { expect(format("[code]\nx++\n[/code]")).toBe("
\nx++\n"); }); it("supports spoiler tags", function() { expect(format("[spoiler]it's a sled[/spoiler]")).toBe("it's a sled"); }); it("links images", function() { expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe(""); }); it("supports [url] without a title", function() { expect(format("[url]http://bettercallsaul.com[/url]")).toBe("http://bettercallsaul.com"); }); it("supports [email] without a title", function() { expect(format("[email]eviltrout@mailinator.com[/email]")).toBe("eviltrout@mailinator.com"); }); }); describe("lists", function() { it("creates an ul", function() { expect(format("[ul][li]option one[/li][/ul]")).toBe("
\nx++\n"); }); it("supports spoiler tags", function() { expect(format("[spoiler]it's a sled[/spoiler]", { environment: 'email' })).toBe("it's a sled"); }); it("links images", function() { expect(format("[img]http://eviltrout.com/eviltrout.png[/img]", { environment: 'email' })).toBe(""); }); it("supports [url] without a title", function() { expect(format("[url]http://bettercallsaul.com[/url]", { environment: 'email' })).toBe("http://bettercallsaul.com"); }); it("supports [email] without a title", function() { expect(format("[email]eviltrout@mailinator.com[/email]", { environment: 'email' })).toBe("eviltrout@mailinator.com"); }); }); describe("lists", function() { it("creates an ul", function() { expect(format("[ul][li]option one[/li][/ul]", { environment: 'email' })).toBe("
"); }); it("can nest quotes", function() { expect(formatQuote("[quote=\"eviltrout, post:1, topic:1\"]abc[quote=\"eviltrout, post:2, topic:2\"]nested[/quote][/quote]")). toBe("
\n"); }); it("can handle more than one quote", function() { expect(formatQuote("before[quote=\"eviltrout, post:1, topic:1\"]first[/quote]middle[quote=\"eviltrout, post:2, topic:2\"]second[/quote]after")). toBe("before
first\n
middle
second\n
after"); }); describe("extractQuotes", function() { var extractQuotes = Discourse.BBCode.extractQuotes; it("returns an object a template renderer", function() { var q = "[quote=\"eviltrout, post:1, topic:2\"]hello[/quote]"; var result = extractQuotes(q + " world"); expect(result.text).toBe(md5(q) + "\n world"); expect(result.template).not.toBe(null); }); }); describe("buildQuoteBBCode", function() { var build = Discourse.BBCode.buildQuoteBBCode; var post = Discourse.Post.create({ cooked: "
lorem ipsum
", username: "eviltrout", post_number: 1, topic_id: 2 }); it("returns an empty string when contents is undefined", function() { expect(build(post, undefined)).toBe(""); expect(build(post, null)).toBe(""); expect(build(post, "")).toBe(""); }); it("returns the quoted contents", function() { expect(build(post, "lorem")).toBe("[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n"); }); it("trims white spaces before & after the quoted contents", function() { expect(build(post, " lorem ")).toBe("[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n"); }); it("marks quotes as full when the quote is the full message", function() { expect(build(post, "lorem ipsum")).toBe("[quote=\"eviltrout, post:1, topic:2, full:true\"]\nlorem ipsum\n[/quote]\n\n"); }); it("keeps BBCode formatting", function() { expect(build(post, "**lorem** ipsum")).toBe("[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n"); }); }); }); });