diff --git a/spec/javascripts/components/markdown_spec.js b/spec/javascripts/components/markdown_spec.js deleted file mode 100644 index 948000573..000000000 --- a/spec/javascripts/components/markdown_spec.js +++ /dev/null @@ -1,132 +0,0 @@ -/*global waitsFor:true expect:true describe:true beforeEach:true it:true */ - -describe("Discourse.Markdown", function() { - - describe("Cooking", function() { - - var cook = function(contents, opts) { - opts = opts || {}; - opts.mentionLookup = opts.mentionLookup || false; - return Discourse.Markdown.cook(contents, opts); - }; - - it("surrounds text with paragraphs", function() { - expect(cook("hello")).toBe("
hello
"); - }); - - it("automatically handles trivial newlines", function() { - expect(cook("1\n2\n3")).toBe("1
\n2
\n3
1
\n
\n2
1
\n
\n2
Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A
'); - }); - - it("escapes double underscores in URLs", function() { - expect(cook("Derpy: http://derp.com?__test=1")).toBe('Derpy: http://derp.com?__test=1
'); - }); - - it("autolinks something that begins with www", function() { - expect(cook("Atwood: www.codinghorror.com")).toBe('Atwood: www.codinghorror.com
'); - }); - - it("autolinks a URL with http://www", function() { - expect(cook("Atwood: http://www.codinghorror.com")).toBe('Atwood: http://www.codinghorror.com
'); - }); - - it("autolinks a URL", function() { - expect(cook("EvilTrout: http://eviltrout.com")).toBe('EvilTrout: http://eviltrout.com
'); - }); - - it("supports markdown style links", function() { - expect(cook("here is [an example](http://twitter.com)")).toBe('here is an example
'); - }); - - it("autolinks a URL with parentheses (like Wikipedia)", function() { - expect(cook("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)")). - toBe('Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)
'); - }); - - }); - - describe("Mentioning", function() { - - it("translates mentions to links", function() { - expect(cook("Hello @sam", { mentionLookup: (function() { return true; }) })).toBe("Hello @sam
"); - }); - - it("adds a mention class", function() { - expect(cook("Hello @EvilTrout")).toBe("Hello @EvilTrout
"); - }); - - it("won't add mention class to an email address", function() { - expect(cook("robin@email.host")).toBe("robin@email.host
"); - }); - - it("won't be affected by email addresses that have a number before the @ symbol", function() { - expect(cook("hanzo55@yahoo.com")).toBe("hanzo55@yahoo.com
"); - }); - - it("supports a @mention at the beginning of a post", function() { - expect(cook("@EvilTrout yo")).toBe("@EvilTrout yo
"); - }); - - it("doesn't do @username mentions inside or blocks", function() {
- expect(cook("`@EvilTrout yo`")).toBe("@EvilTrout yo
");
- });
-
- it("deals correctly with multiple blocks", function() {
- expect(cook("`evil` @EvilTrout `trout`")).toBe("evil
@EvilTrout trout
");
- });
-
- });
-
- describe("Oneboxing", function() {
-
- it("doesn't onebox a link within a list", function() {
- 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() {
- expect(cook("http://test.com")).toMatch(/onebox/);
- });
-
- it("supports multiple links", function() {
- expect(cook("http://test.com\nhttp://test2.com")).toMatch(/onebox[\s\S]+onebox/m);
- });
-
- it("doesn't onebox links that have trailing text", function() {
- expect(cook("http://test.com bob")).not.toMatch(/onebox/);
- });
-
- it("works with links that have underscores in them", function() {
- expect(cook("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street")).
- toBe("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street
");
- });
-
- });
-
- });
-
-});
\ No newline at end of file
diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js
new file mode 100644
index 000000000..ed398eb76
--- /dev/null
+++ b/test/javascripts/components/markdown_test.js
@@ -0,0 +1,95 @@
+/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true */
+
+module("Discourse.Markdown");
+
+var cooked = function(input, expected, text) {
+ equal(Discourse.Markdown.cook(input, {mentionLookup: false }), expected, text);
+};
+
+var cookedOptions = function(input, opts, expected, text) {
+ equal(Discourse.Markdown.cook(input, opts), expected, text);
+}
+
+test("basic cooking", function() {
+ cooked("hello", "hello
", "surrounds text with paragraphs");
+ cooked("1\n2\n3", "1
\n2
\n3
", "automatically handles trivial newlines");
+});
+
+test("Links", function() {
+ cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A",
+ 'Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A
',
+ "allows links to contain query params");
+
+ cooked("Derpy: http://derp.com?__test=1",
+ 'Derpy: http://derp.com?__test=1
',
+ "escapes double underscores in URLs");
+
+ cooked("Atwood: www.codinghorror.com",
+ 'Atwood: www.codinghorror.com
',
+ "autolinks something that begins with www");
+
+ cooked("Atwood: http://www.codinghorror.com",
+ 'Atwood: http://www.codinghorror.com
',
+ "autolinks a URL with http://www");
+
+ cooked("EvilTrout: http://eviltrout.com",
+ 'EvilTrout: http://eviltrout.com
',
+ "autolinks a URL");
+
+ cooked("here is [an example](http://twitter.com)",
+ 'here is an example
',
+ "supports markdown style links");
+
+ cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
+ 'Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)
',
+ "autolinks a URL with parentheses (like Wikipedia)");
+});
+
+test("Quotes", function() {
+ cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
+ { topicId: 2, lookupAvatar: function(name) { return "" + name; } },
+ "1
\n
\n2
",
+ "handles quotes properly");
+
+ cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
+ { topicId: 2, lookupAvatar: function(name) { } },
+ "1
\n
\n2
",
+ "includes no avatar if none is found");
+});
+
+test("Mentions", function() {
+ cookedOptions("Hello @sam", { mentionLookup: (function() { return true; }) },
+ "Hello @sam
",
+ "translates mentions to links");
+
+ cooked("Hello @EvilTrout", "Hello @EvilTrout
", "adds a mention class");
+ cooked("robin@email.host", "robin@email.host
", "won't add mention class to an email address");
+ cooked("hanzo55@yahoo.com", "hanzo55@yahoo.com
", "won't be affected by email addresses that have a number before the @ symbol");
+ cooked("@EvilTrout yo", "@EvilTrout yo
", "doesn't do @username mentions inside or blocks");
+ cooked("`evil` @EvilTrout `trout`",
+ "evil
@EvilTrout trout
",
+ "deals correctly with multiple blocks");
+
+});
+
+test("Oneboxing", function() {
+
+ var matches = function(input, regexp) {
+ return Discourse.Markdown.cook(input, {mentionLookup: false }).match(regexp);
+ };
+
+ 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");
+
+ cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
+ "",
+ "works with links that have underscores in them");
+
+});
+