8
0

alignmentcommand.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import AlignmentEditing from '../src/alignmentediting';
  6. import AlignmentCommand from '../src/alignmentcommand';
  7. import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
  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. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  11. import Command from '@ckeditor/ckeditor5-core/src/command';
  12. describe( 'AlignmentCommand', () => {
  13. let editor, doc, command;
  14. beforeEach( () => {
  15. return VirtualTestEditor
  16. .create( {
  17. plugins: [ AlignmentEditing ]
  18. } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. doc = editor.document;
  22. doc.schema.registerItem( 'paragraph', '$block' );
  23. doc.schema.registerItem( 'heading', '$block' );
  24. buildModelConverter().for( editor.editing.modelToView )
  25. .fromElement( 'paragraph' )
  26. .toElement( 'p' );
  27. buildModelConverter().for( editor.editing.modelToView )
  28. .fromElement( 'heading' )
  29. .toElement( 'h' );
  30. command = editor.commands.get( 'alignLeft' );
  31. } );
  32. } );
  33. afterEach( () => {
  34. editor.destroy();
  35. } );
  36. it( 'is a command', () => {
  37. expect( AlignmentCommand.prototype ).to.be.instanceOf( Command );
  38. expect( command ).to.be.instanceOf( Command );
  39. } );
  40. describe( 'value', () => {
  41. it( 'is false when selection is not in aligned block', () => {
  42. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  43. expect( command ).to.have.property( 'value', false );
  44. } );
  45. } );
  46. describe( 'isEnabled', () => {
  47. it( 'is true when selection is in a block which can have added alignment', () => {
  48. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  49. expect( command ).to.have.property( 'isEnabled', true );
  50. } );
  51. } );
  52. describe( 'execute()', () => {
  53. describe( 'applying right alignment', () => {
  54. it( 'add alignment to block element', () => {
  55. setModelData( doc, '<paragraph>x[]x</paragraph>' );
  56. editor.execute( 'alignRight' );
  57. expect( getModelData( doc ) ).to.equal(
  58. '<paragraph alignment="right">x[]x</paragraph>'
  59. );
  60. expect( getViewData( editor.editing.view ) ).to.equal(
  61. '<p style="text-align:right;">x{}x</p>'
  62. );
  63. } );
  64. } );
  65. } );
  66. } );