alignmentcommand.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import AlignmentCommand from '../src/alignmentcommand';
  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 '../../ckeditor5-core/tests/_utils/modeltesteditor';
  9. describe( 'AlignmentCommand', () => {
  10. let editor, doc, command;
  11. beforeEach( () => {
  12. return ModelTestEditor.create()
  13. .then( newEditor => {
  14. doc = newEditor.document;
  15. command = new AlignmentCommand( newEditor, 'center' );
  16. editor = newEditor;
  17. editor.commands.add( 'alignCenter', new AlignmentCommand( editor, 'center' ) );
  18. doc.schema.registerItem( 'paragraph', '$block' );
  19. doc.schema.registerItem( 'heading', '$block' );
  20. doc.schema.allow( { name: '$block', inside: '$root', attributes: 'alignment' } );
  21. } );
  22. } );
  23. afterEach( () => {
  24. editor.destroy();
  25. } );
  26. it( 'is a command', () => {
  27. expect( AlignmentCommand.prototype ).to.be.instanceOf( Command );
  28. expect( command ).to.be.instanceOf( Command );
  29. } );
  30. describe( 'value', () => {
  31. it( 'is false when selection is not in aligned block', () => {
  32. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  33. expect( command ).to.have.property( 'value', false );
  34. } );
  35. } );
  36. describe( 'isEnabled', () => {
  37. it( 'is true when selection is in a block which can have added alignment', () => {
  38. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  39. expect( command ).to.have.property( 'isEnabled', true );
  40. } );
  41. } );
  42. describe( 'execute()', () => {
  43. describe( 'applying alignment', () => {
  44. it( 'add alignment to block element', () => {
  45. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  46. editor.execute( 'alignCenter' );
  47. expect( getModelData( doc ) ).to.equal(
  48. '<paragraph alignment="center">x[]x</paragraph>'
  49. );
  50. } );
  51. } );
  52. } );
  53. } );