alignmentediting.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  8. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  9. import AlignmentCommand from '../src/alignmentcommand';
  10. describe( 'AlignmentEditing', () => {
  11. let editor, doc;
  12. beforeEach( () => {
  13. return VirtualTestEditor
  14. .create( {
  15. plugins: [ AlignmentEditing, Paragraph ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. } );
  21. } );
  22. afterEach( () => {
  23. editor.destroy();
  24. } );
  25. it( 'adds alignment commands', () => {
  26. expect( editor.commands.get( 'alignLeft' ) ).to.be.instanceOf( AlignmentCommand );
  27. expect( editor.commands.get( 'alignRight' ) ).to.be.instanceOf( AlignmentCommand );
  28. expect( editor.commands.get( 'alignCenter' ) ).to.be.instanceOf( AlignmentCommand );
  29. expect( editor.commands.get( 'alignJustify' ) ).to.be.instanceOf( AlignmentCommand );
  30. } );
  31. it( 'allows for alignment in the $blocks', () => {
  32. expect( doc.schema.check( { name: '$block', inside: '$root', attributes: 'alignment' } ) ).to.be.true;
  33. } );
  34. // describe('alignLef')
  35. it( 'adds converters to the data pipeline', () => {
  36. const data = '<p style="text-align:center;">x</p>';
  37. editor.setData( data );
  38. expect( getModelData( doc ) ).to.equal( '<paragraph alignment="center">[]x</paragraph>' );
  39. expect( editor.getData() ).to.equal( data );
  40. } );
  41. it( 'adds a converter to the view pipeline', () => {
  42. setModelData( doc, '<paragraph alignment="right">[]x</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p style="text-align:right;">x</p>' );
  44. } );
  45. } );