8
0

alignmentediting.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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( 'alignLeft', () => {
  35. it( 'adds converters to the data pipeline', () => {
  36. const data = '<p style="text-align:left;">x</p>';
  37. editor.setData( data );
  38. expect( getModelData( doc ) ).to.equal( '<paragraph alignment="left">[]x</paragraph>' );
  39. expect( editor.getData() ).to.equal( data );
  40. } );
  41. it( 'adds a converter to the view pipeline', () => {
  42. setModelData( doc, '<paragraph alignment="left">[]x</paragraph>' );
  43. expect( editor.getData() ).to.equal( '<p style="text-align:left;">x</p>' );
  44. } );
  45. } );
  46. describe( 'alignCenter', () => {
  47. it( 'adds converters to the data pipeline', () => {
  48. const data = '<p style="text-align:center;">x</p>';
  49. editor.setData( data );
  50. expect( getModelData( doc ) ).to.equal( '<paragraph alignment="center">[]x</paragraph>' );
  51. expect( editor.getData() ).to.equal( data );
  52. } );
  53. it( 'adds a converter to the view pipeline', () => {
  54. setModelData( doc, '<paragraph alignment="center">[]x</paragraph>' );
  55. expect( editor.getData() ).to.equal( '<p style="text-align:center;">x</p>' );
  56. } );
  57. } );
  58. describe( 'alignRight', () => {
  59. it( 'adds converters to the data pipeline', () => {
  60. const data = '<p style="text-align:right;">x</p>';
  61. editor.setData( data );
  62. expect( getModelData( doc ) ).to.equal( '<paragraph alignment="right">[]x</paragraph>' );
  63. expect( editor.getData() ).to.equal( data );
  64. } );
  65. it( 'adds a converter to the view pipeline', () => {
  66. setModelData( doc, '<paragraph alignment="right">[]x</paragraph>' );
  67. expect( editor.getData() ).to.equal( '<p style="text-align:right;">x</p>' );
  68. } );
  69. } );
  70. describe( 'alignJustify', () => {
  71. it( 'adds converters to the data pipeline', () => {
  72. const data = '<p style="text-align:justify;">x</p>';
  73. editor.setData( data );
  74. expect( getModelData( doc ) ).to.equal( '<paragraph alignment="justify">[]x</paragraph>' );
  75. expect( editor.getData() ).to.equal( data );
  76. } );
  77. it( 'adds a converter to the view pipeline', () => {
  78. setModelData( doc, '<paragraph alignment="justify">[]x</paragraph>' );
  79. expect( editor.getData() ).to.equal( '<p style="text-align:justify;">x</p>' );
  80. } );
  81. } );
  82. } );