|
| 1 | +defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + use GroupherServerWeb.ConnCase, async: true |
| 5 | + |
| 6 | + alias Helper.Converter.EditorToHTML.Class |
| 7 | + alias Helper.Converter.EditorToHTML, as: Parser |
| 8 | + |
| 9 | + alias Helper.Utils |
| 10 | + |
| 11 | + @root_class Class.article() |
| 12 | + @class get_in(@root_class, ["quote"]) |
| 13 | + |
| 14 | + describe "[quote block]" do |
| 15 | + defp set_data(mode, text, caption \\ nil) do |
| 16 | + data = |
| 17 | + case caption do |
| 18 | + nil -> |
| 19 | + %{ |
| 20 | + "mode" => mode, |
| 21 | + "text" => text |
| 22 | + } |
| 23 | + |
| 24 | + _ -> |
| 25 | + %{ |
| 26 | + "mode" => mode, |
| 27 | + "text" => text, |
| 28 | + "caption" => caption |
| 29 | + } |
| 30 | + end |
| 31 | + |
| 32 | + %{ |
| 33 | + "time" => 1_567_250_876_713, |
| 34 | + "blocks" => [ |
| 35 | + %{ |
| 36 | + "type" => "quote", |
| 37 | + "data" => data |
| 38 | + } |
| 39 | + ], |
| 40 | + "version" => "2.15.0" |
| 41 | + } |
| 42 | + end |
| 43 | + |
| 44 | + @tag :wip2 |
| 45 | + test "short quote parse should work" do |
| 46 | + editor_json = set_data("short", "short quote") |
| 47 | + {:ok, editor_string} = Jason.encode(editor_json) |
| 48 | + {:ok, converted} = Parser.to_html(editor_string) |
| 49 | + |
| 50 | + short_wrapper_class = @class["short_wrapper"] |
| 51 | + caption_class = @class["caption"] |
| 52 | + |
| 53 | + assert Utils.str_occurence(converted, short_wrapper_class) == 1 |
| 54 | + assert Utils.str_occurence(converted, "</blockquote>") == 1 |
| 55 | + assert Utils.str_occurence(converted, caption_class) == 0 |
| 56 | + end |
| 57 | + |
| 58 | + @tag :wip2 |
| 59 | + test "long quote parse should work" do |
| 60 | + editor_json = set_data("long", "long quote", "caption") |
| 61 | + {:ok, editor_string} = Jason.encode(editor_json) |
| 62 | + {:ok, converted} = Parser.to_html(editor_string) |
| 63 | + |
| 64 | + long_wrapper_class = @class["long_wrapper"] |
| 65 | + caption_text_class = @class["caption_text"] |
| 66 | + |
| 67 | + assert Utils.str_occurence(converted, long_wrapper_class) == 1 |
| 68 | + assert Utils.str_occurence(converted, "</blockquote>") == 1 |
| 69 | + assert Utils.str_occurence(converted, caption_text_class) == 1 |
| 70 | + end |
| 71 | + |
| 72 | + @tag :wip2 |
| 73 | + test "long quote without caption parse should work" do |
| 74 | + editor_json = set_data("long", "long quote") |
| 75 | + {:ok, editor_string} = Jason.encode(editor_json) |
| 76 | + |
| 77 | + {:ok, converted} = Parser.to_html(editor_string) |
| 78 | + |
| 79 | + long_wrapper_class = @class["long_wrapper"] |
| 80 | + caption_text_class = @class["caption_text"] |
| 81 | + |
| 82 | + assert Utils.str_occurence(converted, long_wrapper_class) == 1 |
| 83 | + assert Utils.str_occurence(converted, "</blockquote>") == 1 |
| 84 | + assert Utils.str_occurence(converted, caption_text_class) == 0 |
| 85 | + end |
| 86 | + |
| 87 | + @tag :wip2 |
| 88 | + test "long quote without empty caption parse should work" do |
| 89 | + editor_json = set_data("long", "long quote", "") |
| 90 | + {:ok, editor_string} = Jason.encode(editor_json) |
| 91 | + |
| 92 | + {:ok, converted} = Parser.to_html(editor_string) |
| 93 | + |
| 94 | + long_wrapper_class = @class["long_wrapper"] |
| 95 | + caption_text_class = @class["caption_text"] |
| 96 | + |
| 97 | + assert Utils.str_occurence(converted, long_wrapper_class) == 1 |
| 98 | + assert Utils.str_occurence(converted, "</blockquote>") == 1 |
| 99 | + assert Utils.str_occurence(converted, caption_text_class) == 0 |
| 100 | + end |
| 101 | + |
| 102 | + # @editor_json %{ |
| 103 | + # "time" => 1_567_250_876_713, |
| 104 | + # "blocks" => [ |
| 105 | + # %{ |
| 106 | + # "type" => "paragraph", |
| 107 | + # "data" => %{ |
| 108 | + # "text" => [] |
| 109 | + # } |
| 110 | + # } |
| 111 | + # ], |
| 112 | + # "version" => "2.15.0" |
| 113 | + # } |
| 114 | + @tag :wip2 |
| 115 | + test "invalid quote should have invalid hint" do |
| 116 | + editor_json = set_data("none_exsit", "long quote", "") |
| 117 | + {:ok, editor_string} = Jason.encode(editor_json) |
| 118 | + {:error, error} = Parser.to_html(editor_string) |
| 119 | + |
| 120 | + assert error == [ |
| 121 | + %{block: "quote", field: "mode", message: "should be: short | long"} |
| 122 | + ] |
| 123 | + end |
| 124 | + end |
| 125 | +end |
0 commit comments