From 490c80bc9651f93b61dfe4ae531bc0072a35d044 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 03:46:34 +0000 Subject: [PATCH] test: common api: add tests for format_input/4 --- test/web/common_api/common_api_utils_test.exs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index fc89e3116..754bc7255 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -56,4 +56,54 @@ test "parses emoji from name and bio" do assert expected == Utils.emoji_from_profile(user) end + + describe "format_input/4" do + test "works for bare text/plain" do + text = "hello world!" + expected = "hello world!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + + text = "hello world!\n\nsecond paragraph!" + expected = "hello world!

second paragraph!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + end + + test "works for bare text/html" do + text = "

hello world!

" + expected = "

hello world!

" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + + text = "

hello world!

\n\n

second paragraph

" + expected = "

hello world!

\n\n

second paragraph

" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + end + + test "works for bare text/markdown" do + text = "**hello world**" + expected = "

hello world

\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + + text = "**hello world**\n\n*another paragraph*" + expected = "

hello world

\n

another paragraph

\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + end + end end