From d3f5ede27ea19dd1aaf76f9c0380c998626d41f1 Mon Sep 17 00:00:00 2001 From: vnniz Date: Mon, 11 Sep 2023 20:10:04 +0700 Subject: [PATCH] Add tests for parsing a header with alignment, also updating the 'example doc' and 'example doc 1' --- .../test/super_editor_markdown_test.dart | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/super_editor_markdown/test/super_editor_markdown_test.dart b/super_editor_markdown/test/super_editor_markdown_test.dart index 72f435573a..77acce10ed 100644 --- a/super_editor_markdown/test/super_editor_markdown_test.dart +++ b/super_editor_markdown/test/super_editor_markdown_test.dart @@ -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(), @@ -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'); @@ -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()); expect((document.nodes[0] as ParagraphNode).getMetadataValue('blockType'), header1Attribution); @@ -974,7 +1026,25 @@ with multiple lines expect(document.nodes[19], isA()); - expect(document.nodes[20], isA()); + expect(document.nodes[20], isA()); + + expect(document.nodes[21], isA()); + expect((document.nodes[21] as ParagraphNode).getMetadataValue('blockType'), header1Attribution); + expect((document.nodes[21] as ParagraphNode).getMetadataValue('textAlign'), 'left'); + + expect(document.nodes[22], isA()); + expect((document.nodes[22] as ParagraphNode).getMetadataValue('blockType'), header1Attribution); + expect((document.nodes[22] as ParagraphNode).getMetadataValue('textAlign'), 'center'); + + expect(document.nodes[23], isA()); + expect((document.nodes[23] as ParagraphNode).getMetadataValue('blockType'), header1Attribution); + expect((document.nodes[23] as ParagraphNode).getMetadataValue('textAlign'), 'right'); + + expect(document.nodes[24], isA()); + expect((document.nodes[24] as ParagraphNode).getMetadataValue('blockType'), header1Attribution); + expect((document.nodes[24] as ParagraphNode).getMetadataValue('textAlign'), 'justify'); + + expect(document.nodes[25], isA()); }); test('paragraph with strikethrough', () { @@ -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! ''';