8
0

selectallcommand.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 TableEditing from '@ckeditor/ckeditor5-table/src/tableediting';
  11. import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  12. describe( 'SelectAllCommand', () => {
  13. let editor, model, command;
  14. beforeEach( () => {
  15. return ModelTestEditor
  16. .create( {
  17. plugins: [ SelectAllEditing, Paragraph, ImageEditing, ImageCaptionEditing, TableEditing ]
  18. } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. model = editor.model;
  22. command = editor.commands.get( 'selectAll' );
  23. } );
  24. } );
  25. afterEach( () => {
  26. return editor.destroy();
  27. } );
  28. describe( 'isEnabled', () => {
  29. it( 'should always be "true" because the command is stateless', () => {
  30. expect( command.isEnabled ).to.be.true;
  31. } );
  32. } );
  33. describe( 'execute()', () => {
  34. it( 'should select all (collapsed selection in a block with text)', () => {
  35. setData( model, '<paragraph>f[]oo</paragraph>' );
  36. editor.execute( 'selectAll' );
  37. expect( getData( model ) ).to.equal( '<paragraph>[foo]</paragraph>' );
  38. } );
  39. it( 'should select all (collapsed selection in a content with an object)', () => {
  40. setData( model, '<paragraph>fo[]o</paragraph><image src="foo.png"><caption></caption></image>' );
  41. editor.execute( 'selectAll' );
  42. expect( getData( model ) ).to.equal( '<paragraph>[foo</paragraph><image src="foo.png"><caption></caption></image>]' );
  43. } );
  44. it( 'should select all (selection on an object)', () => {
  45. setData( model, '<paragraph>foo</paragraph>[<image src="foo.png"><caption></caption></image>]' );
  46. editor.execute( 'selectAll' );
  47. expect( getData( model ) ).to.equal( '<paragraph>[foo</paragraph><image src="foo.png"><caption></caption></image>]' );
  48. } );
  49. it( 'should select all (collapsed selection in a nested editable)', () => {
  50. setData( model, '<paragraph>foo</paragraph><image src="foo.png"><caption>b[]ar</caption></image>' );
  51. editor.execute( 'selectAll' );
  52. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  53. } );
  54. it( 'should select all (selection in a nested editable)', () => {
  55. setData( model, '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  56. editor.execute( 'selectAll' );
  57. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  58. } );
  59. it( 'should select all in the closest nested editable (nested editable inside another nested editable)', () => {
  60. setData( model,
  61. '<paragraph>foo</paragraph>' +
  62. '<table>' +
  63. '<tableRow>' +
  64. '<tableCell>' +
  65. '<paragraph>foo</paragraph>' +
  66. '<image src="foo.png"><caption>b[]ar</caption></image>' +
  67. '</tableCell>' +
  68. '</tableRow>' +
  69. '</table>'
  70. );
  71. editor.execute( 'selectAll' );
  72. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>' +
  73. '<table>' +
  74. '<tableRow>' +
  75. '<tableCell>' +
  76. '<paragraph>foo</paragraph>' +
  77. '<image src="foo.png"><caption>[bar]</caption></image>' +
  78. '</tableCell>' +
  79. '</tableRow>' +
  80. '</table>'
  81. );
  82. } );
  83. } );
  84. } );