mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: markdown encoder test
This commit is contained in:
parent
9eaa79b558
commit
2e7f803e02
@ -0,0 +1,137 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() async {
|
||||
group('document_markdown_encoder.dart', () {
|
||||
const example = '''
|
||||
{
|
||||
"document": {
|
||||
"type": "editor",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": {
|
||||
"subtype": "heading",
|
||||
"heading": "h2"
|
||||
},
|
||||
"delta": [
|
||||
{ "insert": "👋 " },
|
||||
{ "insert": "Welcome to", "attributes": { "bold": true } },
|
||||
{ "insert": " " },
|
||||
{
|
||||
"insert": "AppFlowy Editor",
|
||||
"attributes": {
|
||||
"href": "appflowy.io",
|
||||
"italic": true,
|
||||
"bold": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{ "type": "text", "delta": [] },
|
||||
{
|
||||
"type": "text",
|
||||
"delta": [
|
||||
{ "insert": "AppFlowy Editor is a " },
|
||||
{ "insert": "highly customizable", "attributes": { "bold": true } },
|
||||
{ "insert": " " },
|
||||
{ "insert": "rich-text editor", "attributes": { "italic": true } },
|
||||
{ "insert": " for " },
|
||||
{ "insert": "Flutter", "attributes": { "underline": true } }
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "checkbox": true, "subtype": "checkbox" },
|
||||
"delta": [{ "insert": "Customizable" }]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "checkbox": true, "subtype": "checkbox" },
|
||||
"delta": [{ "insert": "Test-covered" }]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "checkbox": false, "subtype": "checkbox" },
|
||||
"delta": [{ "insert": "more to come!" }]
|
||||
},
|
||||
{ "type": "text", "delta": [] },
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "subtype": "quote" },
|
||||
"delta": [{ "insert": "Here is an example you can give a try" }]
|
||||
},
|
||||
{ "type": "text", "delta": [] },
|
||||
{
|
||||
"type": "text",
|
||||
"delta": [
|
||||
{ "insert": "You can also use " },
|
||||
{
|
||||
"insert": "AppFlowy Editor",
|
||||
"attributes": {
|
||||
"italic": true,
|
||||
"bold": true,
|
||||
"backgroundColor": "0x6000BCF0"
|
||||
}
|
||||
},
|
||||
{ "insert": " as a component to build your own app." }
|
||||
]
|
||||
},
|
||||
{ "type": "text", "delta": [] },
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "subtype": "bulleted-list" },
|
||||
"delta": [{ "insert": "Use / to insert blocks" }]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"attributes": { "subtype": "bulleted-list" },
|
||||
"delta": [
|
||||
{
|
||||
"insert": "Select text to trigger to the toolbar to format your notes."
|
||||
}
|
||||
]
|
||||
},
|
||||
{ "type": "text", "delta": [] },
|
||||
{
|
||||
"type": "text",
|
||||
"delta": [
|
||||
{
|
||||
"insert": "If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders!"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
''';
|
||||
setUpAll(() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
});
|
||||
|
||||
test('parser document', () async {
|
||||
final data = Map<String, Object>.from(json.decode(example));
|
||||
final document = Document.fromJson(data);
|
||||
final result = DocumentMarkdownEncoder().convert(document);
|
||||
expect(result, '''
|
||||
## 👋 **Welcome to** ***[AppFlowy Editor](appflowy.io)***
|
||||
|
||||
AppFlowy Editor is a **highly customizable** _rich-text editor_ for <u>Flutter</u>
|
||||
- [x] Customizable
|
||||
- [x] Test-covered
|
||||
- [ ] more to come!
|
||||
|
||||
> Here is an example you can give a try
|
||||
|
||||
You can also use ***AppFlowy Editor*** as a component to build your own app.
|
||||
|
||||
* Use / to insert blocks
|
||||
* Select text to trigger to the toolbar to format your notes.
|
||||
|
||||
If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders!
|
||||
''');
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() async {
|
||||
group('image_node_parser.dart', () {
|
||||
test('parser image node', () {
|
||||
final node = Node(
|
||||
type: 'image',
|
||||
attributes: {
|
||||
'image_src': 'https://appflowy.io',
|
||||
},
|
||||
);
|
||||
final result = const ImageNodeParser().transform(node);
|
||||
expect(result, '![](https://appflowy.io)');
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() async {
|
||||
group('text_node_parser.dart', () {
|
||||
const text = 'Welcome to AppFlowy';
|
||||
|
||||
test('heading style', () {
|
||||
final h1 = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
|
||||
BuiltInAttributeKey.heading: BuiltInAttributeKey.h1,
|
||||
},
|
||||
);
|
||||
final h2 = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
|
||||
BuiltInAttributeKey.heading: BuiltInAttributeKey.h2,
|
||||
},
|
||||
);
|
||||
final h3 = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
|
||||
BuiltInAttributeKey.heading: BuiltInAttributeKey.h3,
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(h1), '# $text');
|
||||
expect(const TextNodeParser().transform(h2), '## $text');
|
||||
expect(const TextNodeParser().transform(h3), '### $text');
|
||||
});
|
||||
|
||||
test('bulleted list style', () {
|
||||
final node = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.bulletedList,
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(node), '* $text');
|
||||
});
|
||||
|
||||
test('number list style', () {
|
||||
final node = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.numberList,
|
||||
BuiltInAttributeKey.number: 1,
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(node), '1. $text');
|
||||
});
|
||||
|
||||
test('checkbox style', () {
|
||||
final checkbox = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.checkbox,
|
||||
BuiltInAttributeKey.checkbox: true,
|
||||
},
|
||||
);
|
||||
final unCheckbox = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.checkbox,
|
||||
BuiltInAttributeKey.checkbox: false,
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(checkbox), '- [x] $text');
|
||||
expect(const TextNodeParser().transform(unCheckbox), '- [ ] $text');
|
||||
});
|
||||
|
||||
test('quote style', () {
|
||||
final node = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: BuiltInAttributeKey.quote,
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(node), '> $text');
|
||||
});
|
||||
|
||||
test('code block style', () {
|
||||
final node = TextNode(
|
||||
delta: Delta(operations: [TextInsert(text)]),
|
||||
attributes: {
|
||||
BuiltInAttributeKey.subtype: 'code-block',
|
||||
},
|
||||
);
|
||||
expect(const TextNodeParser().transform(node), '```\n$text\n```');
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user