highlightcommand.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import HighlightCommand from './../src/highlightcommand';
  6. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import Command from '@ckeditor/ckeditor5-core/src/command';
  8. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  9. describe( 'HighlightCommand', () => {
  10. let editor, doc, command;
  11. beforeEach( () => {
  12. return ModelTestEditor.create()
  13. .then( newEditor => {
  14. doc = newEditor.document;
  15. command = new HighlightCommand( newEditor );
  16. editor = newEditor;
  17. editor.commands.add( 'highlight', command );
  18. doc.schema.registerItem( 'paragraph', '$block' );
  19. doc.schema.allow( { name: '$inline', attributes: 'highlight', inside: '$block' } );
  20. } );
  21. } );
  22. afterEach( () => {
  23. editor.destroy();
  24. } );
  25. it( 'is a command', () => {
  26. expect( HighlightCommand.prototype ).to.be.instanceOf( Command );
  27. expect( command ).to.be.instanceOf( Command );
  28. } );
  29. describe( 'value', () => {
  30. it( 'is set to highlight attribute value when selection is in text with highlight attribute', () => {
  31. setModelData( doc, '<paragraph><$text highlight="marker">fo[]o</$text></paragraph>' );
  32. expect( command ).to.have.property( 'value', 'marker' );
  33. } );
  34. it( 'is undefined when selection is not in text with highlight attribute', () => {
  35. setModelData( doc, '<paragraph>fo[]o</paragraph>' );
  36. expect( command ).to.have.property( 'value', undefined );
  37. } );
  38. } );
  39. describe( 'isEnabled', () => {
  40. it( 'is true when selection is on text which can have highlight added', () => {
  41. setModelData( doc, '<paragraph>fo[]o</paragraph>' );
  42. expect( command ).to.have.property( 'isEnabled', true );
  43. } );
  44. } );
  45. describe.skip( 'execute()', () => {
  46. describe( 'applying highlight', () => {
  47. it( 'adds highlight to selected text element', () => {
  48. setModelData( doc, '<paragraph>f[o]o</paragraph>' );
  49. editor.execute( 'highlight', { class: 'marker' } );
  50. expect( getModelData( doc ) ).to.equal( '<paragraph>f<$text highlight="marker">[o]</$text>o</paragraph>' );
  51. } );
  52. } );
  53. } );
  54. } );