8
0

highlightediting.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @license Copyright (c) 2003-2018, 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-yellow">o</mark>o</p>';
  36. editor.setData( data );
  37. expect( getModelData( model ) ).to.equal( '<paragraph>[]f<$text highlight="yellowMarker">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-yellow">o</mark>o</p>' );
  42. expect( getModelData( model ) ).to.equal( '<paragraph>[]f<$text highlight="yellowMarker">o</$text>o</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p>f<mark class="marker-yellow">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="yellowMarker">o</$text>o</paragraph>' );
  59. expect( editor.getData() ).to.equal( '<p>f<mark class="marker-yellow">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. options: [
  67. { model: 'yellowMarker', class: 'marker-yellow', title: 'Yellow marker', color: '#fdfd77', type: 'marker' },
  68. { model: 'greenMarker', class: 'marker-green', title: 'Green marker', color: '#63f963', type: 'marker' },
  69. { model: 'pinkMarker', class: 'marker-pink', title: 'Pink marker', color: '#fc7999', type: 'marker' },
  70. { model: 'blueMarker', class: 'marker-blue', title: 'Blue marker', color: '#72cdfd', type: 'marker' },
  71. { model: 'redPen', class: 'pen-red', title: 'Red pen', color: '#e91313', type: 'pen' },
  72. { model: 'greenPen', class: 'pen-green', title: 'Green pen', color: '#118800', type: 'pen' }
  73. ]
  74. } );
  75. } );
  76. } );
  77. } );
  78. } );