8
0

alignment.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import Alignment from '../src/alignment';
  7. import AlignmentEditing from '../src/alignmentediting';
  8. import AlignmentUI from '../src/alignmentui';
  9. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  10. describe( 'Alignment', () => {
  11. let editor, command, element;
  12. beforeEach( () => {
  13. element = document.createElement( 'div' );
  14. document.body.appendChild( element );
  15. return ClassicTestEditor
  16. .create( element, {
  17. plugins: [ Alignment ]
  18. } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. command = editor.commands.get( 'alignLeft' );
  22. } );
  23. } );
  24. afterEach( () => {
  25. element.remove();
  26. return editor.destroy();
  27. } );
  28. it( 'requires AlignmentEditing and AlignmentUI', () => {
  29. expect( Alignment.requires ).to.deep.equal( [ AlignmentEditing, AlignmentUI ] );
  30. } );
  31. describe( 'alignLeft button', () => {
  32. it( 'has the base properties', () => {
  33. const button = editor.ui.componentFactory.create( 'alignLeft' );
  34. expect( button ).to.have.property( 'label', 'Left' );
  35. expect( button ).to.have.property( 'icon' );
  36. expect( button ).to.have.property( 'tooltip', true );
  37. } );
  38. it( 'has isOn bound to command\'s value', () => {
  39. const button = editor.ui.componentFactory.create( 'alignLeft' );
  40. command.value = false;
  41. expect( button ).to.have.property( 'isOn', false );
  42. command.value = true;
  43. expect( button ).to.have.property( 'isOn', true );
  44. } );
  45. it( 'has isEnabled bound to command\'s isEnabled', () => {
  46. const button = editor.ui.componentFactory.create( 'alignLeft' );
  47. command.isEnabled = true;
  48. expect( button ).to.have.property( 'isEnabled', true );
  49. command.isEnabled = false;
  50. expect( button ).to.have.property( 'isEnabled', false );
  51. } );
  52. it( 'executes command when it\'s executed', () => {
  53. const button = editor.ui.componentFactory.create( 'alignLeft' );
  54. const spy = sinon.stub( editor, 'execute' );
  55. button.fire( 'execute' );
  56. expect( spy.calledOnce ).to.be.true;
  57. expect( spy.args[ 0 ][ 0 ] ).to.equal( 'alignLeft' );
  58. } );
  59. } );
  60. } );