|
4 | 4 | CODE_BLOCK_PLUGIN_DEFAULT_OPTIONS, |
5 | 5 | ClearFormattingPlugin, |
6 | 6 | CodeBlockPlugin, |
| 7 | + HardBreakPlugin, |
7 | 8 | HEADINGS_PLUGIN_DEFAULT_OPTIONS, |
8 | 9 | HeadingsPlugin, |
9 | 10 | HISTORY_PLUGIN_DEFAULT_OPTIONS, |
@@ -213,6 +214,122 @@ describe('App', () => { |
213 | 214 | editor.unmount(host); |
214 | 215 | }); |
215 | 216 |
|
| 217 | + it('should expose hard break commands through the public plugin', () => { |
| 218 | + const editor = createRteEditor({ |
| 219 | + content: '<p>Angular RTE</p>', |
| 220 | + plugins: [HardBreakPlugin], |
| 221 | + }); |
| 222 | + const host = document.createElement('div'); |
| 223 | + |
| 224 | + editor.mount(host); |
| 225 | + |
| 226 | + expect(HardBreakPlugin.key).toBe('hardBreak'); |
| 227 | + expect(editor.canExecute('insertHardBreak')).toBeTrue(); |
| 228 | + expect(editor.execute('insertHardBreak')).toBeTrue(); |
| 229 | + expect(editor.html()).toBe('<p><br>Angular RTE</p>'); |
| 230 | + |
| 231 | + editor.unmount(host); |
| 232 | + }); |
| 233 | + |
| 234 | + it('should parse serialized hard breaks through the public plugin', () => { |
| 235 | + const editor = createRteEditor({ |
| 236 | + content: '<p>Line one<br>Line two</p>', |
| 237 | + plugins: [HardBreakPlugin], |
| 238 | + }); |
| 239 | + const host = document.createElement('div'); |
| 240 | + |
| 241 | + editor.mount(host); |
| 242 | + |
| 243 | + expect(editor.html()).toBe('<p>Line one<br>Line two</p>'); |
| 244 | + |
| 245 | + editor.unmount(host); |
| 246 | + }); |
| 247 | + |
| 248 | + it('should insert hard breaks with Shift+Enter', () => { |
| 249 | + const editor = createRteEditor({ |
| 250 | + content: '<p>Angular RTE</p>', |
| 251 | + plugins: [HardBreakPlugin], |
| 252 | + }); |
| 253 | + const host = document.createElement('div'); |
| 254 | + |
| 255 | + editor.mount(host); |
| 256 | + |
| 257 | + const surface = host.querySelector('.ProseMirror'); |
| 258 | + const shiftEnterEvent = new KeyboardEvent('keydown', { |
| 259 | + bubbles: true, |
| 260 | + cancelable: true, |
| 261 | + key: 'Enter', |
| 262 | + shiftKey: true, |
| 263 | + }); |
| 264 | + |
| 265 | + surface?.dispatchEvent(shiftEnterEvent); |
| 266 | + |
| 267 | + expect(shiftEnterEvent.defaultPrevented).toBeTrue(); |
| 268 | + expect(editor.html()).toBe('<p><br>Angular RTE</p>'); |
| 269 | + |
| 270 | + editor.unmount(host); |
| 271 | + }); |
| 272 | + |
| 273 | + it('should keep Shift+Enter out of code blocks', () => { |
| 274 | + const editor = createRteEditor({ |
| 275 | + content: |
| 276 | + '<pre><code class="language-typescript">const answer = 42;</code></pre>', |
| 277 | + plugins: [ |
| 278 | + CodeBlockPlugin.configure({ |
| 279 | + languages: ['plaintext', 'typescript'], |
| 280 | + defaultLanguage: 'typescript', |
| 281 | + }), |
| 282 | + HardBreakPlugin, |
| 283 | + ], |
| 284 | + }); |
| 285 | + const host = document.createElement('div'); |
| 286 | + |
| 287 | + editor.mount(host); |
| 288 | + |
| 289 | + const surface = host.querySelector('.ProseMirror'); |
| 290 | + const shiftEnterEvent = new KeyboardEvent('keydown', { |
| 291 | + bubbles: true, |
| 292 | + cancelable: true, |
| 293 | + key: 'Enter', |
| 294 | + shiftKey: true, |
| 295 | + }); |
| 296 | + |
| 297 | + surface?.dispatchEvent(shiftEnterEvent); |
| 298 | + |
| 299 | + expect(shiftEnterEvent.defaultPrevented).toBeFalse(); |
| 300 | + expect(editor.canExecute('insertHardBreak')).toBeFalse(); |
| 301 | + expect(editor.html()).toBe( |
| 302 | + '<pre><code class="language-typescript">const answer = 42;</code></pre>', |
| 303 | + ); |
| 304 | + |
| 305 | + editor.unmount(host); |
| 306 | + }); |
| 307 | + |
| 308 | + it('should preserve code block line breaks when clearing formatting with hard breaks enabled', () => { |
| 309 | + const editor = createRteEditor({ |
| 310 | + content: |
| 311 | + '<pre><code class="language-typescript">const first = 1; const second = 2;</code></pre>', |
| 312 | + plugins: [ |
| 313 | + CodeBlockPlugin.configure({ |
| 314 | + languages: ['plaintext', 'typescript'], |
| 315 | + defaultLanguage: 'typescript', |
| 316 | + }), |
| 317 | + HardBreakPlugin, |
| 318 | + ClearFormattingPlugin, |
| 319 | + ], |
| 320 | + }); |
| 321 | + const host = document.createElement('div'); |
| 322 | + |
| 323 | + editor.mount(host); |
| 324 | + |
| 325 | + expect(editor.execute('clearFormatting')).toBeTrue(); |
| 326 | + expect(editor.html()).toBe( |
| 327 | + '<p>const first = 1;<br>const second = 2;</p>', |
| 328 | + ); |
| 329 | + |
| 330 | + editor.unmount(host); |
| 331 | + }); |
| 332 | + |
216 | 333 | it('should parse serialized code blocks through the public plugin', () => { |
217 | 334 | const snippet = [ |
218 | 335 | 'package main', |
|
0 commit comments