8
0

highlightediting.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import HighlightEditing from './../src/highlightediting';
  6. import HighlightCommand from './../src/highlightcommand';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. describe( 'HighlightEditing', () => {
  11. let editor, doc;
  12. beforeEach( () => {
  13. return VirtualTestEditor
  14. .create( {
  15. plugins: [ HighlightEditing, Paragraph ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. } );
  21. } );
  22. afterEach( () => {
  23. editor.destroy();
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( doc.schema.check( { name: '$inline', attributes: 'highlight', inside: '$block' } ) ).to.be.true;
  27. expect( doc.schema.check( { name: '$inline', attributes: 'highlight', inside: '$clipboardHolder' } ) ).to.be.true;
  28. } );
  29. it( 'adds highlight commands', () => {
  30. expect( editor.commands.get( 'highlight' ) ).to.be.instanceOf( HighlightCommand );
  31. } );
  32. describe( 'data pipeline conversions', () => {
  33. it( 'should convert defined marker classes', () => {
  34. const data = '<p>f<mark class="marker">o</mark>o</p>';
  35. editor.setData( data );
  36. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker">o</$text>o</paragraph>' );
  37. expect( editor.getData() ).to.equal( data );
  38. } );
  39. it( 'should convert only one defined marker classes', () => {
  40. editor.setData( '<p>f<mark class="marker-green marker">o</mark>o</p>' );
  41. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker-green">o</$text>o</paragraph>' );
  42. expect( editor.getData() ).to.equal( '<p>f<mark class="marker-green">o</mark>o</p>' );
  43. } );
  44. it( 'should not convert undefined marker classes', () => {
  45. editor.setData( '<p>f<mark class="some-unknown-marker">o</mark>o</p>' );
  46. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  47. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  48. } );
  49. it( 'should not convert marker without class', () => {
  50. editor.setData( '<p>f<mark>o</mark>o</p>' );
  51. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  52. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  53. } );
  54. } );
  55. describe( 'editing pipeline conversion', () => {
  56. it( 'should convert mark element with defined class', () => {
  57. setModelData( doc, '<paragraph>f<$text highlight="marker">o</$text>o</paragraph>' );
  58. expect( editor.getData() ).to.equal( '<p>f<mark class="marker">o</mark>o</p>' );
  59. } );
  60. } );
  61. describe( 'config', () => {
  62. describe( 'default value', () => {
  63. it( 'should be set', () => {
  64. expect( editor.config.get( 'highlight' ) ).to.deep.equal( [
  65. { class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
  66. { class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
  67. { class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
  68. { class: 'pen-red', title: 'Red Pen', color: '#ff0000', type: 'pen' },
  69. { class: 'pen-blue', title: 'Blue Pen', color: '#0000ff', type: 'pen' }
  70. ] );
  71. } );
  72. } );
  73. } );
  74. } );