8
0

undoui.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import UndoEditing from '../src/undoediting';
  8. import UndoUI from '../src/undoui';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. describe( 'UndoUI', () => {
  12. let editor, editorElement;
  13. testUtils.createSinonSandbox();
  14. beforeEach( () => {
  15. editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, { plugins: [ UndoEditing, UndoUI ] } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. } );
  21. } );
  22. afterEach( () => {
  23. editorElement.remove();
  24. return editor.destroy();
  25. } );
  26. testButton( 'undo', 'Undo', 'CTRL+Z' );
  27. testButton( 'redo', 'Redo', 'CTRL+Y' );
  28. function testButton( featureName, label, featureKeystroke ) {
  29. describe( `${ featureName } button`, () => {
  30. let button;
  31. beforeEach( () => {
  32. button = editor.ui.componentFactory.create( featureName );
  33. } );
  34. it( 'should register feature component', () => {
  35. expect( button ).to.be.instanceOf( ButtonView );
  36. } );
  37. it( 'should create UI component with correct attribute values', () => {
  38. expect( button.isOn ).to.be.false;
  39. expect( button.label ).to.equal( label );
  40. expect( button.icon ).to.match( /<svg / );
  41. expect( button.keystroke ).to.equal( featureKeystroke );
  42. } );
  43. it( `should execute ${ featureName } command on model execute event`, () => {
  44. const executeSpy = testUtils.sinon.stub( editor, 'execute' );
  45. button.fire( 'execute' );
  46. sinon.assert.calledOnce( executeSpy );
  47. sinon.assert.calledWithExactly( executeSpy, featureName );
  48. } );
  49. it( `should bind model to ${ featureName } command`, () => {
  50. const command = editor.commands.get( featureName );
  51. expect( button.isOn ).to.be.false;
  52. const initState = command.isEnabled;
  53. expect( button.isEnabled ).to.equal( initState );
  54. command.isEnabled = !initState;
  55. expect( button.isEnabled ).to.equal( !initState );
  56. } );
  57. it( 'should set keystroke in the model', () => {
  58. expect( button.keystroke ).to.equal( featureKeystroke );
  59. } );
  60. } );
  61. }
  62. } );