|
| 1 | +import { createTestPage, pasteContent } from '../../support/paste-utils'; |
| 2 | +import { testLog } from '../../support/test-helpers'; |
| 3 | + |
| 4 | +describe('Paste Code Block Tests', () => { |
| 5 | + it('should paste all code block formats correctly', () => { |
| 6 | + createTestPage(); |
| 7 | + |
| 8 | + // HTML Code Blocks |
| 9 | + { |
| 10 | + const html = '<pre><code>const x = 10;\nconsole.log(x);</code></pre>'; |
| 11 | + const plainText = 'const x = 10;\nconsole.log(x);'; |
| 12 | + |
| 13 | + testLog.info('=== Pasting HTML Code Block ==='); |
| 14 | + pasteContent(html, plainText); |
| 15 | + |
| 16 | + cy.wait(1000); |
| 17 | + |
| 18 | + // CodeBlock component structure: .relative.w-full > pre > code |
| 19 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'const x = 10'); |
| 20 | + testLog.info('✓ HTML code block pasted successfully'); |
| 21 | + } |
| 22 | + |
| 23 | + { |
| 24 | + const html = '<pre><code class="language-javascript">function hello() {\n console.log("Hello");\n}</code></pre>'; |
| 25 | + const plainText = 'function hello() {\n console.log("Hello");\n}'; |
| 26 | + |
| 27 | + testLog.info('=== Pasting HTML Code Block with Language ==='); |
| 28 | + pasteContent(html, plainText); |
| 29 | + |
| 30 | + cy.wait(1000); |
| 31 | + |
| 32 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'function hello'); |
| 33 | + testLog.info('✓ HTML code block with language pasted successfully'); |
| 34 | + } |
| 35 | + |
| 36 | + { |
| 37 | + const html = ` |
| 38 | + <pre><code class="language-python">def greet(): |
| 39 | + print("Hello")</code></pre> |
| 40 | + <pre><code class="language-typescript">const greeting: string = "Hello";</code></pre> |
| 41 | + `; |
| 42 | + const plainText = 'def greet():\n print("Hello")\nconst greeting: string = "Hello";'; |
| 43 | + |
| 44 | + testLog.info('=== Pasting HTML Multiple Language Code Blocks ==='); |
| 45 | + pasteContent(html, plainText); |
| 46 | + |
| 47 | + cy.wait(1000); |
| 48 | + |
| 49 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'def greet'); |
| 50 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'const greeting'); |
| 51 | + testLog.info('✓ HTML multiple language code blocks pasted successfully'); |
| 52 | + } |
| 53 | + |
| 54 | + { |
| 55 | + const html = '<blockquote>This is a quoted text</blockquote>'; |
| 56 | + const plainText = 'This is a quoted text'; |
| 57 | + |
| 58 | + testLog.info('=== Pasting HTML Blockquote ==='); |
| 59 | + pasteContent(html, plainText); |
| 60 | + |
| 61 | + cy.wait(1000); |
| 62 | + |
| 63 | + // AppFlowy renders blockquote as div with data-block-type="quote" |
| 64 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'This is a quoted text'); |
| 65 | + testLog.info('✓ HTML blockquote pasted successfully'); |
| 66 | + } |
| 67 | + |
| 68 | + { |
| 69 | + const html = ` |
| 70 | + <blockquote> |
| 71 | + First level quote |
| 72 | + <blockquote>Second level quote</blockquote> |
| 73 | + </blockquote> |
| 74 | + `; |
| 75 | + const plainText = 'First level quote\nSecond level quote'; |
| 76 | + |
| 77 | + testLog.info('=== Pasting HTML Nested Blockquotes ==='); |
| 78 | + pasteContent(html, plainText); |
| 79 | + |
| 80 | + cy.wait(1000); |
| 81 | + |
| 82 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'First level quote'); |
| 83 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'Second level quote'); |
| 84 | + testLog.info('✓ HTML nested blockquotes pasted successfully'); |
| 85 | + } |
| 86 | + |
| 87 | + // Markdown Code Blocks |
| 88 | + { |
| 89 | + const markdown = `\`\`\`javascript |
| 90 | +const x = 10; |
| 91 | +console.log(x); |
| 92 | +\`\`\``; |
| 93 | + |
| 94 | + testLog.info('=== Pasting Markdown Code Block with Language ==='); |
| 95 | + pasteContent('', markdown); |
| 96 | + |
| 97 | + cy.wait(1000); |
| 98 | + |
| 99 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'const x = 10'); |
| 100 | + testLog.info('✓ Markdown code block with language pasted successfully'); |
| 101 | + } |
| 102 | + |
| 103 | + { |
| 104 | + const markdown = `\`\`\` |
| 105 | +function hello() { |
| 106 | + console.log("Hello"); |
| 107 | +} |
| 108 | +\`\`\``; |
| 109 | + |
| 110 | + testLog.info('=== Pasting Markdown Code Block without Language ==='); |
| 111 | + pasteContent('', markdown); |
| 112 | + |
| 113 | + cy.wait(1000); |
| 114 | + |
| 115 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'function hello'); |
| 116 | + testLog.info('✓ Markdown code block without language pasted successfully'); |
| 117 | + } |
| 118 | + |
| 119 | + { |
| 120 | + const markdown = 'Use the `console.log()` function to print output.'; |
| 121 | + |
| 122 | + testLog.info('=== Pasting Markdown Inline Code ==='); |
| 123 | + pasteContent('', markdown); |
| 124 | + |
| 125 | + cy.wait(1000); |
| 126 | + |
| 127 | + // Inline code is usually a span with specific style |
| 128 | + cy.get('[contenteditable="true"]').find('span.bg-border-primary').should('contain', 'console.log'); |
| 129 | + testLog.info('✓ Markdown inline code pasted successfully'); |
| 130 | + } |
| 131 | + |
| 132 | + { |
| 133 | + const markdown = `\`\`\`python |
| 134 | +def greet(): |
| 135 | + print("Hello") |
| 136 | +\`\`\` |
| 137 | +
|
| 138 | +\`\`\`typescript |
| 139 | +const greeting: string = "Hello"; |
| 140 | +\`\`\` |
| 141 | +
|
| 142 | +\`\`\`bash |
| 143 | +echo "Hello World" |
| 144 | +\`\`\``; |
| 145 | + |
| 146 | + testLog.info('=== Pasting Markdown Multiple Language Code Blocks ==='); |
| 147 | + pasteContent('', markdown); |
| 148 | + |
| 149 | + cy.wait(1000); |
| 150 | + |
| 151 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'def greet'); |
| 152 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'const greeting'); |
| 153 | + cy.get('[contenteditable="true"]').find('pre').find('code').should('contain', 'echo'); |
| 154 | + testLog.info('✓ Markdown multiple language code blocks pasted successfully'); |
| 155 | + } |
| 156 | + |
| 157 | + { |
| 158 | + const markdown = '> This is a quoted text'; |
| 159 | + |
| 160 | + testLog.info('=== Pasting Markdown Blockquote ==='); |
| 161 | + pasteContent('', markdown); |
| 162 | + |
| 163 | + cy.wait(1000); |
| 164 | + |
| 165 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'This is a quoted text'); |
| 166 | + testLog.info('✓ Markdown blockquote pasted successfully'); |
| 167 | + } |
| 168 | + |
| 169 | + { |
| 170 | + const markdown = `> First level quote |
| 171 | +>> Second level quote |
| 172 | +>>> Third level quote`; |
| 173 | + |
| 174 | + testLog.info('=== Pasting Markdown Nested Blockquotes ==='); |
| 175 | + pasteContent('', markdown); |
| 176 | + |
| 177 | + cy.wait(1000); |
| 178 | + |
| 179 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'First level quote'); |
| 180 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'Second level quote'); |
| 181 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').should('contain', 'Third level quote'); |
| 182 | + testLog.info('✓ Markdown nested blockquotes pasted successfully'); |
| 183 | + } |
| 184 | + |
| 185 | + { |
| 186 | + const markdown = '> **Important:** This is a *quoted* text with `code`'; |
| 187 | + |
| 188 | + testLog.info('=== Pasting Markdown Blockquote with Formatting ==='); |
| 189 | + pasteContent('', markdown); |
| 190 | + |
| 191 | + cy.wait(1000); |
| 192 | + |
| 193 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').find('strong').should('contain', 'Important'); |
| 194 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').find('em').should('contain', 'quoted'); |
| 195 | + cy.get('[contenteditable="true"]').find('[data-block-type="quote"]').find('span.bg-border-primary').should('contain', 'code'); |
| 196 | + testLog.info('✓ Markdown blockquote with formatting pasted successfully'); |
| 197 | + } |
| 198 | + }); |
| 199 | +}); |
| 200 | + |
0 commit comments