highlightediting.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.skip( '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="">o</$text>o</paragraph>' );
  51. expect( editor.getData() ).to.equal( '<p>x</p>' );
  52. } );
  53. } );
  54. describe.skip( 'editing pipeline conversion', () => {
  55. it( 'adds a converter to the view pipeline for removing attribute', () => {
  56. setModelData( doc, '<paragraph>f<$text highlight="">o</$text>o</paragraph>' );
  57. expect( editor.getData() ).to.equal( '<p>f<mark>o</mark>o</p>' );
  58. const command = editor.commands.get( 'highlight' );
  59. command.execute();
  60. expect( editor.getData() ).to.equal( '<p>x</p>' );
  61. } );
  62. } );
  63. describe( 'config', () => {
  64. describe( 'default value', () => {
  65. it( 'should be set', () => {
  66. expect( editor.config.get( 'highlight' ) ).to.deep.equal( [
  67. { class: 'marker', title: 'Marker', color: '#ffff66', type: 'marker' },
  68. { class: 'marker-green', title: 'Green Marker', color: '#66ff00', type: 'marker' },
  69. { class: 'marker-pink', title: 'Pink Marker', color: '#ff6fff', type: 'marker' },
  70. { class: 'pen-red', title: 'Red Pen', color: '#ff0000', type: 'pen' },
  71. { class: 'pen-blue', title: 'Blue Pen', color: '#0000ff', type: 'pen' }
  72. ] );
  73. } );
  74. } );
  75. } );
  76. } );