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.

Commitebee0c9

Browse files
committed
refactor(editor-validator): improve error hint
1 parentf6159a7 commitebee0c9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ defmodule Helper.Converter.EditorToHTML.Validator do
66
aliasValidator.Schema
77
aliasConverter.EditorToHTML.Validator.EditorSchema
88

9-
# blocks with no children items
109
@normal_blocks["header","paragraph","quote"]
11-
# blocks with "items" fields
12-
@complex_blocks["list","table"]
10+
11+
# blocks with "items" fields (has many children item)
12+
@children_blocks["list","table"]
13+
14+
# all the supported blocks
15+
@supported_blocks@normal_blocks++@children_blocks
1316

1417
@specis_valid(map)::{:error,map}|{:ok,:pass}
1518
defis_valid(data)whenis_map(data)do
@@ -60,14 +63,18 @@ defmodule Helper.Converter.EditorToHTML.Validator do
6063

6164
# validate block which has mode and items
6265
defpvalidate_block(%{"type"=>type,"data"=>data})
63-
whentypein@complex_blocksdo
66+
whentypein@children_blocksdo
6467
[parent:parent_schema,item:item_schema]=EditorSchema.get(type)
6568
validate_with(type,parent_schema,item_schema,data)
6669
end
6770

68-
defpvalidate_block(%{"type"=>type}),do:raise("undown#{type} block")
71+
defpvalidate_block(%{"type"=>type})do
72+
raise("undown#{type} block, supported blocks:#{@supported_blocks|>Enum.join(" | ")}")
73+
end
6974

70-
defpvalidate_block(e),do:raise("undown block:#{e}")
75+
defpvalidate_block(e)do
76+
raise("undown block:#{e}, supported blocks:#{@supported_blocks|>Enum.join(" | ")}")
77+
end
7178

7279
# validate with given schema
7380
defpvalidate_with(block,schema,data)do

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do
4444
assert{:ok,_}=Parser.to_html(editor_string)
4545
end
4646

47-
@tag:wip
47+
@tag:wip2
4848
test"invalid editorjs json fmt should raise error"do
4949
editor_json=%{
5050
"invalid_time"=>1_567_250_876_713,
@@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do
100100
{:ok,editor_string}=Jason.encode(editor_json)
101101
{:error,error}=Parser.to_html(editor_string)
102102

103-
asserterror=="undown block: 1"
103+
assertString.contains?(error,"undown block: 1")
104104
end
105105

106106
test"real-world editor.js data should work"do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp