8
0

selectallediting.js 2.1 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. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import SelectAllEditing from '../src/selectallediting';
  7. import SelectAllCommand from '../src/selectallcommand';
  8. import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
  9. describe( 'SelectAllEditing', () => {
  10. let editor, viewDocument;
  11. beforeEach( () => {
  12. return ModelTestEditor
  13. .create( {
  14. plugins: [ SelectAllEditing ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. viewDocument = editor.editing.view.document;
  19. sinon.spy( editor, 'execute' );
  20. } );
  21. } );
  22. afterEach( () => {
  23. return editor.destroy();
  24. } );
  25. it( 'should have a name', () => {
  26. expect( SelectAllEditing.pluginName ).to.equal( 'SelectAllEditing' );
  27. } );
  28. it( 'should register the "selectAll" command', () => {
  29. const command = editor.commands.get( 'selectAll' );
  30. expect( command ).to.be.instanceOf( SelectAllCommand );
  31. } );
  32. describe( 'Ctrl+A keystroke listener', () => {
  33. it( 'should execute the "selectAll" command', () => {
  34. const domEventDataMock = {
  35. keyCode: keyCodes.a,
  36. ctrlKey: true,
  37. preventDefault: sinon.spy()
  38. };
  39. viewDocument.fire( 'keydown', domEventDataMock );
  40. sinon.assert.calledOnce( editor.execute );
  41. sinon.assert.calledWithExactly( editor.execute, 'selectAll' );
  42. } );
  43. it( 'should prevent the default action', () => {
  44. const domEventDataMock = {
  45. keyCode: keyCodes.a,
  46. ctrlKey: true,
  47. preventDefault: sinon.spy()
  48. };
  49. viewDocument.fire( 'keydown', domEventDataMock );
  50. sinon.assert.calledOnce( domEventDataMock.preventDefault );
  51. } );
  52. it( 'should not react to other keystrokes', () => {
  53. const domEventDataMock = {
  54. keyCode: keyCodes.x,
  55. ctrlKey: true,
  56. preventDefault: sinon.spy()
  57. };
  58. viewDocument.fire( 'keydown', domEventDataMock );
  59. sinon.assert.notCalled( editor.execute );
  60. sinon.assert.notCalled( domEventDataMock.preventDefault );
  61. } );
  62. } );
  63. } );