8
0

codeblock-integration.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  6. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';
  9. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  10. import CodeBlockEditing from '../src/codeblockediting';
  11. // A simple plugin that enables the GFM data processor.
  12. class CodeBlockIntegration extends Plugin {
  13. constructor( editor ) {
  14. super( editor );
  15. editor.data.processor = new GFMDataProcessor( editor.data.viewDocument );
  16. }
  17. }
  18. function getEditor( initialData = '' ) {
  19. return ClassicTestEditor
  20. .create( initialData, {
  21. plugins: [ CodeBlockIntegration, CodeBlockEditing, Enter, Paragraph ]
  22. } );
  23. }
  24. describe( 'CodeBlock - integration', () => {
  25. describe( 'with Markdown GFM', () => {
  26. it( 'should be loaded and returned from the editor (for plain text)', async () => {
  27. const editor = await getEditor(
  28. '```\n' +
  29. 'test()\n' +
  30. '```'
  31. );
  32. expect( editor.getData() ).to.equal(
  33. '```plaintext\n' +
  34. 'test()\n' +
  35. '```'
  36. );
  37. await editor.destroy();
  38. } );
  39. it( 'should be loaded and returned from the editor (for defined language)', async () => {
  40. const editor = await getEditor(
  41. '```javascript\n' +
  42. 'test()\n' +
  43. '```'
  44. );
  45. expect( editor.getData() ).to.equal(
  46. '```javascript\n' +
  47. 'test()\n' +
  48. '```'
  49. );
  50. await editor.destroy();
  51. } );
  52. } );
  53. } );