Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit2e16b16

Browse files
committed
refactor(editor): spec-types && add more tests
1 parentc6ac24c commit2e16b16

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

‎lib/helper/converter/editor_to_html/frags/table.ex‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ defmodule Helper.Converter.EditorToHTML.Frags.Table do
55
see https://editorjs.io/
66
"""
77
aliasHelper.Converter.EditorToHTML.Class
8-
#alias Helper.Types, as: T
8+
aliasHelper.Types,as:T
99

1010
@classget_in(Class.article(),["table"])
1111

12+
@specget_row([T.editor_table_cell()])::T.html()
1213
defget_row(group_items)do
1314
tr_content=
1415
Enum.reduce(group_items,"",fnitem,acc->
@@ -19,6 +20,7 @@ defmodule Helper.Converter.EditorToHTML.Frags.Table do
1920
~s(<tr>#{tr_content}</tr>)
2021
end
2122

23+
@specfrag(:td,T.editor_table_cell())::T.html()
2224
deffrag(:td,item)do
2325
%{
2426
"align"=>align,
@@ -43,6 +45,7 @@ defmodule Helper.Converter.EditorToHTML.Frags.Table do
4345
end
4446
end
4547

48+
@specfrag(:th,T.editor_table_cell())::T.html()
4649
deffrag(:th,item)do
4750
%{"align"=>align,"text"=>text}=item
4851

‎lib/helper/types.ex‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ defmodule Helper.Types do
5959
required(:text)=>String.t(),
6060
prefixIndex:String.t()
6161
}
62+
63+
@typedoc"""
64+
editor.js's Table align type
65+
"""
66+
@typeeditor_table_align:::center|:left|:right
67+
68+
@typedoc"""
69+
editor.js's Table td type
70+
"""
71+
@typeeditor_table_cell::%{
72+
required(:text)=>String.t(),
73+
required(:align)=>editor_table_align,
74+
isStripe:Boolean.t(),
75+
isHeader:Boolean.t()
76+
}
77+
6278
@typedoc"""
6379
html fragment
6480
"""

‎test/helper/converter/editor_to_html_test/table_test.exs‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do
88
aliasHelper.Utils
99

1010
@root_classClass.article()
11-
@classget_in(@root_class,["list"])
11+
@classget_in(@root_class,["table"])
1212

1313
describe"[table block unit]"do
1414
defpset_items(column_count,items)do
@@ -97,25 +97,28 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do
9797
{:ok,editor_string}=Jason.encode(editor_json)
9898
{:ok,converted}=Parser.to_html(editor_string)
9999

100-
IO.inspect(converted,label:"table >>")
100+
th_header_class=@class["th_header"]
101+
td_stripe_class=@class["td_stripe"]
101102

102-
# unorder_list_prefix_class = @class["unorder_list_prefix"]
103-
#assert Utils.str_occurence(converted,unorder_list_prefix_class) == 3
103+
assertUtils.str_occurence(converted,th_header_class)==4
104+
assertUtils.str_occurence(converted,td_stripe_class)==3
104105
end
105106

106-
#@tag :wip
107-
#test "invalidlist mode parse should raise error message" do
108-
#editor_json = set_items("invalid-mode",[])
109-
# {:ok, editor_string} = Jason.encode(editor_json)
110-
# {:error, err_msg} = Parser.to_html(editor_string)
107+
@tag:wip2
108+
test"invalidtable field parse should raise error message"do
109+
editor_json=set_items("aa","bb")
110+
{:ok,editor_string}=Jason.encode(editor_json)
111+
{:error,err_msg}=Parser.to_html(editor_string)
111112

112-
# assert err_msg == [
113-
# %{
114-
# block: "list",
115-
# field: "mode",
116-
# message: "should be: checklist | order_list | unorder_list"
117-
# }
118-
# ]
119-
# end
113+
asserterr_msg=[
114+
%{
115+
block:"table",
116+
field:"columnCount",
117+
message:"should be: number",
118+
value:"aa"
119+
},
120+
%{block:"table",field:"items",message:"should be: list",value:"bb"}
121+
]
122+
end
120123
end
121124
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp