Skip to content

Commit

Permalink
Add tests for parsing a header with alignment, also updating the 'exa…
Browse files Browse the repository at this point in the history
…mple doc' and 'example doc 1'
  • Loading branch information
lamnhan066 committed Sep 13, 2023
1 parent 7ea5a04 commit d3f5ede
Showing 1 changed file with 83 additions and 2 deletions.
85 changes: 83 additions & 2 deletions super_editor_markdown/test/super_editor_markdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,26 @@ with multiple lines
text: AttributedText('Example Doc'),
metadata: {'blockType': header1Attribution},
),
ParagraphNode(
id: Editor.createNodeId(),
text: AttributedText('Example Doc With Left Alignment'),
metadata: {'blockType': header1Attribution, 'textAlign': 'left'},
),
ParagraphNode(
id: Editor.createNodeId(),
text: AttributedText('Example Doc With Center Alignment'),
metadata: {'blockType': header1Attribution, 'textAlign': 'center'},
),
ParagraphNode(
id: Editor.createNodeId(),
text: AttributedText('Example Doc With Right Alignment'),
metadata: {'blockType': header1Attribution, 'textAlign': 'right'},
),
ParagraphNode(
id: Editor.createNodeId(),
text: AttributedText('Example Doc With Justify Alignment'),
metadata: {'blockType': header1Attribution, 'textAlign': 'justify'},
),
HorizontalRuleNode(id: Editor.createNodeId()),
ParagraphNode(
id: Editor.createNodeId(),
Expand Down Expand Up @@ -729,6 +749,38 @@ with multiple lines
expect((header6Doc.nodes.first as ParagraphNode).getMetadataValue('blockType'), header6Attribution);
});

test('header with left alignment', () {
final headerLeftAlignment1 = deserializeMarkdownToDocument(':---\n# Header 1');
final header = headerLeftAlignment1.nodes.first as ParagraphNode;
expect(header.getMetadataValue('blockType'), header1Attribution);
expect(header.getMetadataValue('textAlign'), 'left');
expect(header.text.text, 'Header 1');
});

test('header with center alignment', () {
final headerLeftAlignment1 = deserializeMarkdownToDocument(':---:\n# Header 1');
final header = headerLeftAlignment1.nodes.first as ParagraphNode;
expect(header.getMetadataValue('blockType'), header1Attribution);
expect(header.getMetadataValue('textAlign'), 'center');
expect(header.text.text, 'Header 1');
});

test('header with right alignment', () {
final headerLeftAlignment1 = deserializeMarkdownToDocument('---:\n# Header 1');
final header = headerLeftAlignment1.nodes.first as ParagraphNode;
expect(header.getMetadataValue('blockType'), header1Attribution);
expect(header.getMetadataValue('textAlign'), 'right');
expect(header.text.text, 'Header 1');
});

test('header with justify alignment', () {
final headerLeftAlignment1 = deserializeMarkdownToDocument('-::-\n# Header 1');
final header = headerLeftAlignment1.nodes.first as ParagraphNode;
expect(header.getMetadataValue('blockType'), header1Attribution);
expect(header.getMetadataValue('textAlign'), 'justify');
expect(header.text.text, 'Header 1');
});

test('blockquote', () {
final blockquoteDoc = deserializeMarkdownToDocument('> This is a blockquote');

Expand Down Expand Up @@ -943,7 +995,7 @@ with multiple lines
test('example doc 1', () {
final document = deserializeMarkdownToDocument(exampleMarkdownDoc1);

expect(document.nodes.length, 21);
expect(document.nodes.length, 26);

expect(document.nodes[0], isA<ParagraphNode>());
expect((document.nodes[0] as ParagraphNode).getMetadataValue('blockType'), header1Attribution);
Expand Down Expand Up @@ -974,7 +1026,25 @@ with multiple lines

expect(document.nodes[19], isA<TaskNode>());

expect(document.nodes[20], isA<ParagraphNode>());
expect(document.nodes[20], isA<HorizontalRuleNode>());

expect(document.nodes[21], isA<ParagraphNode>());
expect((document.nodes[21] as ParagraphNode).getMetadataValue('blockType'), header1Attribution);
expect((document.nodes[21] as ParagraphNode).getMetadataValue('textAlign'), 'left');

expect(document.nodes[22], isA<ParagraphNode>());
expect((document.nodes[22] as ParagraphNode).getMetadataValue('blockType'), header1Attribution);
expect((document.nodes[22] as ParagraphNode).getMetadataValue('textAlign'), 'center');

expect(document.nodes[23], isA<ParagraphNode>());
expect((document.nodes[23] as ParagraphNode).getMetadataValue('blockType'), header1Attribution);
expect((document.nodes[23] as ParagraphNode).getMetadataValue('textAlign'), 'right');

expect(document.nodes[24], isA<ParagraphNode>());
expect((document.nodes[24] as ParagraphNode).getMetadataValue('blockType'), header1Attribution);
expect((document.nodes[24] as ParagraphNode).getMetadataValue('textAlign'), 'justify');

expect(document.nodes[25], isA<ParagraphNode>());
});

test('paragraph with strikethrough', () {
Expand Down Expand Up @@ -1210,5 +1280,16 @@ Another paragraph
- [x] Completed task
---
:---
# Example 1 With Left Alignment
:---:
# Example 1 With Center Alignment
---:
# Example 1 With Right Alignment
-::-
# Example 1 With Justify Alignment
The end!
''';

0 comments on commit d3f5ede

Please sign in to comment.