highlightcommand.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: '$block', inside: '$root', attributes: 'highlight' } );
  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 true when selection is in block with commend type highlight', () => {
  31. setModelData( doc, '<paragraph highlight="center"><$text highlight="true">fo[]o</$text></paragraph>' );
  32. expect( command ).to.have.property( 'value', true );
  33. } );
  34. } );
  35. describe( 'isEnabled', () => {
  36. it( 'is true when selection is in a block which can have added highlight', () => {
  37. setModelData( doc, '<paragraph highlight="center"><$text highlight="true">fo[]o</$text></paragraph>' );
  38. expect( command ).to.have.property( 'isEnabled', true );
  39. } );
  40. } );
  41. describe.skip( 'execute()', () => {
  42. describe( 'applying highlight', () => {
  43. it( 'adds highlight to selected text element', () => {
  44. setModelData( doc, '<paragraph>f[o]o</paragraph>' );
  45. editor.execute( 'highlight' );
  46. expect( getModelData( doc ) ).to.equal( '<paragraph>f<$text highlight="true">[o]</$text>o</paragraph>' );
  47. } );
  48. } );
  49. } );
  50. } );