describe "Discourse.Utilities", -> 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("

hello

") it "automatically handles trivial newlines", -> expect(cook("1\n2\n3")).toBe("

1
\n2
\n3

") it "handles quotes properly", -> cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {topicId: 2, lookupAvatar: (name) -> "#{name}"}) expect(cooked).toBe("

1

\n

2

") 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("

1

\n

2

") describe "Links", -> it "allows links to contain query params", -> expect(cook("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A")).toBe('

Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A

') it "escapes double underscores in URLs", -> expect(cook("Derpy: http://derp.com?__test=1")).toBe('

Derpy: http://derp.com?__test=1

') it "autolinks something that begins with www", -> expect(cook("Atwood: www.codinghorror.com")).toBe('

Atwood: www.codinghorror.com

') it "autolinks a URL with http://www", -> expect(cook("Atwood: http://www.codinghorror.com")).toBe('

Atwood: http://www.codinghorror.com

') it "autolinks a URL", -> expect(cook("EvilTrout: http://eviltrout.com")).toBe('

EvilTrout: http://eviltrout.com

') it "supports markdown style links", -> expect(cook("here is [an example](http://twitter.com)")).toBe('

here is an example

') it "autolinks a URL with parentheses (like Wikipedia)", -> 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", -> it "translates mentions to links", -> expect(cook("Hello @sam", {mentionLookup: (->true)})).toBe("

Hello @sam

") it "adds a mention class", -> expect(cook("Hello @EvilTrout")).toBe("

Hello @EvilTrout

") it "won't add mention class to an email address", -> expect(cook("robin@email.host")).toBe("

robin@email.host

") it "won't be affected by email addresses that have a number before the @ symbol", -> expect(cook("hanzo55@yahoo.com")).toBe("

hanzo55@yahoo.com

") it "supports a @mention at the beginning of a post", -> expect(cook("@EvilTrout yo")).toBe("

@EvilTrout yo

") # 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("

http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street

")