highlightediting.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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( 'adds highlight commands', () => {
  26. expect( editor.commands.get( 'highlight' ) ).to.be.instanceOf( HighlightCommand );
  27. } );
  28. describe( 'data pipeline conversions', () => {
  29. it( 'should convert defined marker classes', () => {
  30. const data = '<p>f<mark class="marker">o</mark>o</p>';
  31. editor.setData( data );
  32. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker">o</$text>o</paragraph>' );
  33. expect( editor.getData() ).to.equal( data );
  34. } );
  35. it( 'should convert only one defined marker classes', () => {
  36. editor.setData( '<p>f<mark class="marker-green marker">o</mark>o</p>' );
  37. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker-green">o</$text>o</paragraph>' );
  38. expect( editor.getData() ).to.equal( '<p>f<mark class="marker-green">o</mark>o</p>' );
  39. } );
  40. it( 'should not convert undefined marker classes', () => {
  41. editor.setData( '<p>f<mark class="some-unknown-marker">o</mark>o</p>' );
  42. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  44. } );
  45. it( 'should not convert marker without class', () => {
  46. editor.setData( '<p>f<mark>o</mark>o</p>' );
  47. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  48. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  49. } );
  50. } );
  51. describe( 'editing pipeline conversion', () => {
  52. it( 'should convert mark element with defined class', () => {
  53. setModelData( doc, '<paragraph>f<$text highlight="marker">o</$text>o</paragraph>' );
  54. expect( editor.getData() ).to.equal( '<p>f<mark class="marker">o</mark>o</p>' );
  55. } );
  56. } );
  57. describe( 'config', () => {
  58. describe( 'default value', () => {
  59. it( 'should be set', () => {
  60. expect( editor.config.get( 'highlight' ) ).to.deep.equal( [
  61. { class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
  62. { class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
  63. { class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
  64. { class: 'pen-red', title: 'Red Pen', color: '#ff0000', type: 'pen' },
  65. { class: 'pen-blue', title: 'Blue Pen', color: '#0000ff', type: 'pen' }
  66. ] );
  67. } );
  68. } );
  69. } );
  70. } );