selectallui.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  8. import SelectAllEditing from '../src/selectallediting';
  9. import SelectAllUI from '../src/selectallui';
  10. describe( 'SelectAllUI', () => {
  11. let editor, editorElement, button;
  12. beforeEach( () => {
  13. editorElement = document.createElement( 'div' );
  14. document.body.appendChild( editorElement );
  15. return ClassicTestEditor
  16. .create( editorElement, {
  17. plugins: [ SelectAllEditing, SelectAllUI ]
  18. } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. button = editor.ui.componentFactory.create( 'selectAll' );
  22. } );
  23. } );
  24. afterEach( () => {
  25. editorElement.remove();
  26. return editor.destroy();
  27. } );
  28. it( 'should have a name', () => {
  29. expect( SelectAllUI.pluginName ).to.equal( 'SelectAllUI' );
  30. } );
  31. describe( 'the "selectAll" button', () => {
  32. it( 'should be an instance of ButtonView', () => {
  33. expect( button ).to.be.instanceOf( ButtonView );
  34. } );
  35. it( 'should have a label', () => {
  36. expect( button.label ).to.equal( 'Select all' );
  37. } );
  38. it( 'should have an icon', () => {
  39. expect( button.icon ).to.match( /^<svg/ );
  40. } );
  41. it( 'should have a keystroke', () => {
  42. expect( button.keystroke ).to.equal( 'Ctrl+A' );
  43. } );
  44. it( 'should have a tooltip', () => {
  45. expect( button.tooltip ).to.be.true;
  46. } );
  47. it( 'should have #isEnabled bound to the command state', () => {
  48. expect( button.isEnabled ).to.be.true;
  49. editor.commands.get( 'selectAll' ).isEnabled = false;
  50. expect( button.isEnabled ).to.be.false;
  51. } );
  52. it( 'should execute the "selectAll" command and focus the editing view', () => {
  53. sinon.spy( editor, 'execute' );
  54. sinon.spy( editor.editing.view, 'focus' );
  55. button.fire( 'execute' );
  56. sinon.assert.calledOnce( editor.execute );
  57. sinon.assert.calledWithExactly( editor.execute, 'selectAll' );
  58. sinon.assert.calledOnce( editor.editing.view.focus );
  59. } );
  60. } );
  61. } );