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.

Commitf618493

Browse files
committed
test(editor): add base parse tests
1 parentd79340a commitf618493

File tree

3 files changed

+117
-36
lines changed

3 files changed

+117
-36
lines changed

‎lib/helper/error_code.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ defmodule Helper.ErrorCode do
2727
defecode(:exsit_pending_bill),do:@default_base+11
2828
defecode(:bill_state),do:@default_base+12
2929
defecode(:bill_action),do:@default_base+13
30+
defecode(:editor_data_parse),do:@default_base+14
3031
# throttle
3132
defecode(:throttle_inverval),do:@throttle_base+1
3233
defecode(:throttle_hour),do:@throttle_base+2

‎lib/helper/rich_text_parser.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ defmodule Helper.RichTextParser do
66
"""
77

88
defstring_to_json(string)do
9-
Jason.decode!(string)
9+
Jason.decode(string)
1010
end
1111
end

‎test/helper/rich_text_parser_test.exs‎

Lines changed: 115 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,130 @@ defmodule GroupherServer.Test.Helper.RichTextParserTest do
66
aliasHelper.RichTextParser,as:Parser
77

88
describe"[basic convert]"do
9-
@tag:wip2
10-
test"string_to_json should work"do
11-
string=~s({"time":1566184478687,"blocks":[{}],"version":"2.15.0"})
12-
hello=Parser.string_to_json(string)
9+
@tag:wip
10+
test"string_json should work"do
11+
string=~S({"time":1566184478687,"blocks":[{}],"version":"2.15.0"})
12+
{:ok,converted}=Parser.string_to_json(string)
1313

14-
IO.inspect(hello,label:"hello")
14+
assertconverted["time"]==1_566_184_478_687
15+
assertconverted["version"]=="2.15.0"
1516
end
1617

17-
test"TODO: test emoji. 😏"do
18-
true
18+
@tag:wip
19+
test"invalid string data should get error"do
20+
string=~S({"time":1566184478687,"blocks":[{}],"version":})
21+
assert{:error,converted}=Parser.string_to_json(string)
1922
end
2023

21-
@tag:wip2
22-
test"real data should work"do
23-
editor_json2=~S({
24-
"time": 1563816717958,
25-
"blocks": [{
26-
"type": "header",
27-
"data": {
28-
"text": "(Editor.js\)",
29-
"level": 2
24+
@tag:wip
25+
test"real-world editor.js data should work"do
26+
string=~S({
27+
"time" : 1567250876713,
28+
"blocks" : [
29+
{
30+
"type" : "header",
31+
"data" : {
32+
"text" : "Editor.js",
33+
"level" : 2
34+
}
35+
},
36+
{
37+
"type" : "paragraph",
38+
"data" : {
39+
"text" : "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text."
40+
}
41+
},
42+
{
43+
"type" : "header",
44+
"data" : {
45+
"text" : "Key features",
46+
"level" : 3
47+
}
48+
},
49+
{
50+
"type" : "list",
51+
"data" : {
52+
"style" : "unordered",
53+
"items" : [
54+
"It is a block-styled editor",
55+
"It returns clean data output in JSON",
56+
"Designed to be extendable and pluggable with a simple API"
57+
]
58+
}
59+
},
60+
{
61+
"type" : "header",
62+
"data" : {
63+
"text" : "What does it mean «block-styled editor»",
64+
"level" : 3
65+
}
66+
},
67+
{
68+
"type" : "paragraph",
69+
"data" : {
70+
"text" : "Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class=\"cdx-marker\">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure\) provided by Plugin and united by Editor's Core."
71+
}
72+
},
73+
{
74+
"type" : "paragraph",
75+
"data" : {
76+
"text" : "There are dozens of <a href=\"https://github.com/editor-js\">ready-to-use Blocks</a> and the <a href=\"https://editorjs.io/creating-a-block-tool\">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games."
77+
}
78+
},
79+
{
80+
"type" : "header",
81+
"data" : {
82+
"text" : "What does it mean clean data output",
83+
"level" : 3
84+
}
85+
},
86+
{
87+
"type" : "paragraph",
88+
"data" : {
89+
"text" : "Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
90+
}
91+
},
92+
{
93+
"type" : "paragraph",
94+
"data" : {
95+
"text" : "Given data can be used as you want: render with HTML for <code class=\"inline-code\">Web clients</code>, render natively for <code class=\"inline-code\">mobile apps</code>, create markup for <code class=\"inline-code\">Facebook Instant Articles</code> or <code class=\"inline-code\">Google AMP</code>, generate an <code class=\"inline-code\">audio version</code> and so on."
96+
}
97+
},
98+
{
99+
"type" : "paragraph",
100+
"data" : {
101+
"text" : "Clean data is useful to sanitize, validate and process on the backend."
102+
}
103+
},
104+
{
105+
"type" : "delimiter",
106+
"data" : {}
107+
},
108+
{
109+
"type" : "paragraph",
110+
"data" : {
111+
"text" : "We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
112+
}
113+
},
114+
{
115+
"type" : "image",
116+
"data" : {
117+
"file" : {
118+
"url" : "https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg"
119+
},
120+
"caption" : "",
121+
"withBorder" : true,
122+
"stretched" : false,
123+
"withBackground" : false
124+
}
30125
}
31-
}
32126
],
33-
"version": "2.15.0"
127+
"version": "2.15.0"
34128
})
129+
{:ok,converted}=Parser.string_to_json(string)
130+
IO.inspect(converted,label:"haha")
35131

36-
editor_json="""
37-
{
38-
"time": 1563816717958,
39-
"blocks": [{
40-
"type": "header",
41-
"data": {
42-
"text": "(Editor.js)",
43-
"level": 2
44-
}
45-
}
46-
],
47-
"version": "2.15.0"
48-
}
49-
"""
50-
51-
hello=Jason.decode!(editor_json)
52-
IO.inspect(hello,label:"hello")
132+
assertnotEnum.empty?(converted["blocks"])
53133
end
54134
end
55135
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp