8
0

selectallcommand.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  9. import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
  10. import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  11. describe( 'SelectAllCommand', () => {
  12. let editor, model, command;
  13. beforeEach( () => {
  14. return ModelTestEditor
  15. .create( {
  16. plugins: [ SelectAllEditing, Paragraph, ImageEditing, ImageCaptionEditing ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. command = editor.commands.get( 'selectAll' );
  22. } );
  23. } );
  24. afterEach( () => {
  25. return editor.destroy();
  26. } );
  27. describe( 'isEnabled', () => {
  28. it( 'should always be "true" because the command is stateless', () => {
  29. expect( command.isEnabled ).to.be.true;
  30. } );
  31. } );
  32. describe( 'execute()', () => {
  33. it( 'should select all (collapsed selection in a block with text)', () => {
  34. setData( model, '<paragraph>f[]oo</paragraph>' );
  35. editor.execute( 'selectAll' );
  36. expect( getData( model ) ).to.equal( '<paragraph>[foo]</paragraph>' );
  37. } );
  38. it( 'should select all (collapsed selection in a content with an object)', () => {
  39. setData( model, '<paragraph>fo[]o</paragraph><image src="foo.png"><caption></caption></image>' );
  40. editor.execute( 'selectAll' );
  41. expect( getData( model ) ).to.equal( '<paragraph>[foo</paragraph><image src="foo.png"><caption></caption></image>]' );
  42. } );
  43. it( 'should select all (selection on an object)', () => {
  44. setData( model, '<paragraph>foo</paragraph>[<image src="foo.png"><caption></caption></image>]' );
  45. editor.execute( 'selectAll' );
  46. expect( getData( model ) ).to.equal( '<paragraph>[foo</paragraph><image src="foo.png"><caption></caption></image>]' );
  47. } );
  48. it( 'should select all (collapsed selection in a nested editable)', () => {
  49. setData( model, '<paragraph>foo</paragraph><image src="foo.png"><caption>b[]ar</caption></image>' );
  50. editor.execute( 'selectAll' );
  51. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  52. } );
  53. it( 'should select all (selection in a nested editable)', () => {
  54. setData( model, '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  55. editor.execute( 'selectAll' );
  56. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  57. } );
  58. } );
  59. } );