8
0

highlightediting.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. it.skip( 'allows for highlight in $blocks', () => {
  29. expect( doc.schema.check( { name: '$text', inside: '$root', attributes: 'highlight' } ) ).to.be.true;
  30. } );
  31. describe.skip( 'integration', () => {
  32. beforeEach( () => {
  33. return VirtualTestEditor
  34. .create( {
  35. plugins: [ HighlightEditing, Paragraph ]
  36. } )
  37. .then( newEditor => {
  38. editor = newEditor;
  39. doc = editor.document;
  40. } );
  41. } );
  42. it( 'is allowed inside paragraph', () => {
  43. expect( doc.schema.check( { name: 'paragraph', attributes: 'highlight' } ) ).to.be.true;
  44. } );
  45. } );
  46. describe( 'data pipeline conversions', () => {
  47. it( 'should convert defined marker classes', () => {
  48. const data = '<p>f<mark class="marker">o</mark>o</p>';
  49. editor.setData( data );
  50. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker">o</$text>o</paragraph>' );
  51. expect( editor.getData() ).to.equal( data );
  52. } );
  53. it( 'should convert only one defined marker classes', () => {
  54. editor.setData( '<p>f<mark class="marker-green marker">o</mark>o</p>' );
  55. expect( getModelData( doc ) ).to.equal( '<paragraph>[]f<$text highlight="marker-green">o</$text>o</paragraph>' );
  56. expect( editor.getData() ).to.equal( '<p>f<mark class="marker-green">o</mark>o</p>' );
  57. } );
  58. it( 'should not convert undefined marker classes', () => {
  59. editor.setData( '<p>f<mark class="some-unknown-marker">o</mark>o</p>' );
  60. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  61. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  62. } );
  63. it( 'should not convert marker without class', () => {
  64. editor.setData( '<p>f<mark>o</mark>o</p>' );
  65. expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
  66. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  67. } );
  68. } );
  69. describe( 'editing pipeline conversion', () => {
  70. it( 'should convert mark element with defined class', () => {
  71. setModelData( doc, '<paragraph>f<$text highlight="marker">o</$text>o</paragraph>' );
  72. expect( editor.getData() ).to.equal( '<p>f<mark class="marker">o</mark>o</p>' );
  73. } );
  74. } );
  75. describe( 'config', () => {
  76. describe( 'default value', () => {
  77. it( 'should be set', () => {
  78. expect( editor.config.get( 'highlight' ) ).to.deep.equal( [
  79. { class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
  80. { class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
  81. { class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
  82. { class: 'pen-red', title: 'Red Pen', color: '#ff0000', type: 'pen' },
  83. { class: 'pen-blue', title: 'Blue Pen', color: '#0000ff', type: 'pen' }
  84. ] );
  85. } );
  86. } );
  87. } );
  88. } );