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.

Commit3e75436

Browse files
committed
test(editor-export): invalid data test for image block
1 parentb99e63c commit3e75436

File tree

3 files changed

+68
-155
lines changed

3 files changed

+68
-155
lines changed

‎lib/helper/converter/editor_to_html/index.ex‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ defmodule Helper.Converter.EditorToHTML do
133133

134134
minimap_content=Frags.Image.get_minimap(items)
135135

136-
IO.inspect(minimap_content,label:"mini map")
137-
138136
anchor_id=Utils.uid(:html,data)
139137

140138
~s(<div id="#{anchor_id}" class="#{image_wrapper_class}">

‎lib/helper/converter/editor_to_html/validator/editor_schema.ex‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ defmodule Helper.Converter.EditorToHTML.Validator.EditorSchema do
1515
# table
1616
@valid_table_align["left","center","right"]
1717

18+
# image
19+
@valid_image_mode["single","jiugongge","gallery"]
20+
1821
@specget(String.t())::map|[parent:map,item:map]
1922
defget("editor")do
2023
%{
@@ -90,6 +93,7 @@ defmodule Helper.Converter.EditorToHTML.Validator.EditorSchema do
9093
[
9194
parent:%{
9295
"id"=>[:string,required:false],
96+
"mode"=>[enum:@valid_image_mode],
9397
"items"=>[:list]
9498
},
9599
item:%{

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

Lines changed: 64 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -169,176 +169,87 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do
169169
assertUtils.str_occurence(converted,gallery_mini_image_class)==length(@images)
170170
end
171171

172-
# @tag :wip
173-
# test "edit exsit block will not change id value" do
174-
# editor_json =
175-
# set_items(
176-
# "order_list",
177-
# [
178-
# %{
179-
# "checked" => true,
180-
# "hideLabel" => false,
181-
# "indent" => 0,
182-
# "label" => "label",
183-
# "labelType" => "default",
184-
# "prefixIndex" => "1.",
185-
# "text" =>
186-
# "一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。"
187-
# }
188-
# ],
189-
# "exsit"
190-
# )
191-
192-
# {:ok, editor_string} = Jason.encode(editor_json)
193-
# {:ok, converted} = Parser.to_html(editor_string)
194-
195-
# assert Utils.str_occurence(converted, "id=\"exsit\"") == 1
196-
# end
197-
198-
# @tag :wip
199-
# test "basic checklist parse should work" do
200-
# editor_json =
201-
# set_items("checklist", [
202-
# %{
203-
# "checked" => true,
204-
# "hideLabel" => false,
205-
# "indent" => 0,
206-
# "label" => "label",
207-
# "labelType" => "default",
208-
# "text" =>
209-
# "一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。"
210-
# },
211-
# %{
212-
# "checked" => false,
213-
# "hideLabel" => false,
214-
# "indent" => 0,
215-
# "label" => "label",
216-
# "labelType" => "default",
217-
# "text" => "list item"
218-
# },
219-
# %{
220-
# "checked" => false,
221-
# "hideLabel" => false,
222-
# "indent" => 1,
223-
# "label" => "green",
224-
# "labelType" => "green",
225-
# "text" => "list item"
226-
# },
227-
# %{
228-
# "checked" => false,
229-
# "hideLabel" => false,
230-
# "indent" => 1,
231-
# "label" => "red",
232-
# "labelType" => "red",
233-
# "text" => "list item"
234-
# }
235-
# ])
236-
237-
# {:ok, editor_string} = Jason.encode(editor_json)
238-
# {:ok, converted} = Parser.to_html(editor_string)
239-
240-
# checked_class = @class["checklist_checkbox_checked"]
241-
# assert Utils.str_occurence(converted, checked_class) == 1
242-
# end
172+
@tag:wip
173+
test"edit exsit block will not change id value"do
174+
editor_json=
175+
set_items(
176+
"gallery",
177+
@images
178+
|>Enum.with_index()
179+
|>Enum.map(fn{src,index}->
180+
%{
181+
"index"=>index,
182+
"src"=>src,
183+
"caption"=>"this is a caption 1"
184+
}
185+
end),
186+
"exsit"
187+
)
243188

244-
# @tag :wip
245-
# test "checklist without label parse should work" do
246-
# editor_json =
247-
# set_items("checklist", [
248-
# %{
249-
# "checked" => true,
250-
# "hideLabel" => true,
251-
# "indent" => 0,
252-
# "label" => "label",
253-
# "labelType" => "default",
254-
# "text" => "list item"
255-
# },
256-
# %{
257-
# "checked" => false,
258-
# "hideLabel" => true,
259-
# "indent" => 0,
260-
# "label" => "label",
261-
# "labelType" => "default",
262-
# "text" => "list item"
263-
# }
264-
# ])
189+
{:ok,editor_string}=Jason.encode(editor_json)
190+
{:ok,converted}=Parser.to_html(editor_string)
265191

266-
# {:ok, editor_string} = Jason.encode(editor_json)
267-
# {:ok, converted} = Parser.to_html(editor_string)
192+
assertUtils.str_occurence(converted,"id=\"exsit\"")==1
193+
end
268194

269-
# label_class = @class["label"]
270-
# assert Utils.str_occurence(converted, label_class) == 0
271-
# end
195+
@tag:wip2
196+
test"invalid mode parse should raise error message"do
197+
editor_json=set_items("invalid-mode",[])
198+
{:ok,editor_string}=Jason.encode(editor_json)
199+
{:error,err_msg}=Parser.to_html(editor_string)
200+
201+
asserterr_msg==[
202+
%{
203+
block:"image",
204+
field:"mode",
205+
message:"should be: single | jiugongge | gallery"
206+
}
207+
]
208+
end
272209

273-
# @tag :wip
274-
# test "invalid list mode parse should raise error message" do
275-
# editor_json = set_items("invalid-mode", [])
276-
# {:ok, editor_string} = Jason.encode(editor_json)
277-
# {:error, err_msg} = Parser.to_html(editor_string)
210+
@tag:wip2
211+
test"invalid data parse should raise error message"do
212+
editor_json=
213+
set_items("single",[
214+
%{
215+
"index"=>"invalid",
216+
"src"=>"src"
217+
}
218+
])
278219

279-
# assert err_msg == [
280-
# %{
281-
# block: "list",
282-
# field: "mode",
283-
# message: "should be: checklist | order_list | unorder_list"
284-
# }
285-
# ]
286-
# end
220+
{:ok,editor_string}=Jason.encode(editor_json)
221+
{:error,err_msg}=Parser.to_html(editor_string)
222+
223+
asserterr_msg==[
224+
%{
225+
block:"image(single)",
226+
field:"index",
227+
message:"should be: number",
228+
value:"invalid"
229+
}
230+
]
231+
end
287232

288-
# @tag :wip
289-
# test "invalidlist data parse should raise error message" do
233+
# @tag :wip2
234+
# test "invalidsrc parse should raise error message" do
290235
# editor_json =
291-
# set_items("checklist", [
236+
# set_items("single", [
292237
# %{
293-
# "checked" => true,
294-
# "hideLabel" => "invalid",
295-
# "indent" => 5,
296-
# "label" => "label",
297-
# "labelType" => "default",
298-
# "text" => "list item"
238+
# "index" => 0,
239+
# "src" => "src"
299240
# }
300241
# ])
301242

302243
# {:ok, editor_string} = Jason.encode(editor_json)
303244
# {:error, err_msg} = Parser.to_html(editor_string)
245+
# IO.inspect(err_msg, label: "err_msg")
304246

305247
# assert err_msg == [
306248
# %{
307-
# block: "list(checklist)",
308-
# field: "hideLabel",
309-
# message: "should be:boolean",
249+
# block: "image(single)",
250+
# field: "index",
251+
# message: "should be:number",
310252
# value: "invalid"
311-
# },
312-
# %{
313-
# block: "list(checklist)",
314-
# field: "indent",
315-
# message: "should be: 0 | 1 | 2 | 3"
316-
# }
317-
# ]
318-
# end
319-
320-
# @tag :wip
321-
# test "invalid indent field should get error" do
322-
# editor_json =
323-
# set_items("checklist", [
324-
# %{
325-
# "checked" => true,
326-
# "hideLabel" => true,
327-
# "indent" => 10,
328-
# "label" => "label",
329-
# "labelType" => "default",
330-
# "text" => "list item"
331-
# }
332-
# ])
333-
334-
# {:ok, editor_string} = Jason.encode(editor_json)
335-
# {:error, error} = Parser.to_html(editor_string)
336-
337-
# assert error === [
338-
# %{
339-
# block: "list(checklist)",
340-
# field: "indent",
341-
# message: "should be: 0 | 1 | 2 | 3"
342253
# }
343254
# ]
344255
# end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp