highlightediting.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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, model;
  12. beforeEach( () => {
  13. return VirtualTestEditor
  14. .create( {
  15. plugins: [ HighlightEditing, Paragraph ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. model = editor.model;
  20. } );
  21. } );
  22. afterEach( () => {
  23. editor.destroy();
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( editor.model.schema.checkAttribute( [ '$block', '$text' ], 'highlight' ) ).to.be.true;
  27. expect( editor.model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'highlight' ) ).to.be.true;
  28. expect( editor.model.schema.checkAttribute( [ '$block' ], 'highlight' ) ).to.be.false;
  29. } );
  30. it( 'adds highlight command', () => {
  31. expect( editor.commands.get( 'highlight' ) ).to.be.instanceOf( HighlightCommand );
  32. } );
  33. describe( 'data pipeline conversions', () => {
  34. it( 'should convert defined marker classes', () => {
  35. const data = '<p>f<mark class="marker">o</mark>o</p>';
  36. editor.setData( data );
  37. expect( getModelData( model ) ).to.equal( '<paragraph>[]f<$text highlight="marker">o</$text>o</paragraph>' );
  38. expect( editor.getData() ).to.equal( data );
  39. } );
  40. it( 'should convert only one defined marker classes', () => {
  41. editor.setData( '<p>f<mark class="marker-green marker">o</mark>o</p>' );
  42. expect( getModelData( model ) ).to.equal( '<paragraph>[]f<$text highlight="marker">o</$text>o</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p>f<mark class="marker">o</mark>o</p>' );
  44. } );
  45. it( 'should not convert undefined marker classes', () => {
  46. editor.setData( '<p>f<mark class="some-unknown-marker">o</mark>o</p>' );
  47. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  48. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  49. } );
  50. it( 'should not convert marker without class', () => {
  51. editor.setData( '<p>f<mark>o</mark>o</p>' );
  52. expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  53. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  54. } );
  55. } );
  56. describe( 'editing pipeline conversion', () => {
  57. it( 'should convert mark element with defined class', () => {
  58. setModelData( model, '<paragraph>f<$text highlight="marker">o</$text>o</paragraph>' );
  59. expect( editor.getData() ).to.equal( '<p>f<mark class="marker">o</mark>o</p>' );
  60. } );
  61. } );
  62. describe( 'config', () => {
  63. describe( 'default value', () => {
  64. it( 'should be set', () => {
  65. expect( editor.config.get( 'highlight' ) ).to.deep.equal( [
  66. { model: 'marker', view: { name: 'mark', class: 'marker' }, title: 'Marker', color: '#ffff66', type: 'marker' },
  67. {
  68. model: 'greenMarker',
  69. view: { name: 'mark', class: 'marker-green' },
  70. title: 'Green Marker',
  71. color: '#66ff00',
  72. type: 'marker'
  73. },
  74. {
  75. model: 'pinkMarker',
  76. view: { name: 'mark', class: 'marker-pink' },
  77. title: 'Pink Marker',
  78. color: '#ff6fff',
  79. type: 'marker'
  80. },
  81. { model: 'redPen', view: { name: 'mark', class: 'pen-red' }, title: 'Red Pen', color: '#ff2929', type: 'pen' },
  82. { model: 'bluePen', view: { name: 'mark', class: 'pen-blue' }, title: 'Blue Pen', color: '#0091ff', type: 'pen' }
  83. ] );
  84. } );
  85. } );
  86. } );
  87. } );