8
0

selectallcommand.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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>b[ar]</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( 'when entire editable is selected, should select all in parent limit element', () => {
  60. setData( model, '<paragraph>foo</paragraph><image src="foo.png"><caption>[bar]</caption></image>' );
  61. editor.execute( 'selectAll' );
  62. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>[<image src="foo.png"><caption>bar</caption></image>]' );
  63. } );
  64. it( 'should select all in the closest nested editable (nested editable inside another nested editable)', () => {
  65. setData( model,
  66. '<paragraph>foo</paragraph>' +
  67. '<table>' +
  68. '<tableRow>' +
  69. '<tableCell>' +
  70. '<paragraph>foo</paragraph>' +
  71. '<image src="foo.png"><caption>b[]ar</caption></image>' +
  72. '</tableCell>' +
  73. '</tableRow>' +
  74. '</table>'
  75. );
  76. editor.execute( 'selectAll' );
  77. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>' +
  78. '<table>' +
  79. '<tableRow>' +
  80. '<tableCell>' +
  81. '<paragraph>foo</paragraph>' +
  82. '<image src="foo.png"><caption>[bar]</caption></image>' +
  83. '</tableCell>' +
  84. '</tableRow>' +
  85. '</table>'
  86. );
  87. } );
  88. it( 'consecutive execute() on nested editable, should select all in the parent limit element', () => {
  89. setData( model,
  90. '<paragraph>foo</paragraph>' +
  91. '<table>' +
  92. '<tableRow>' +
  93. '<tableCell>' +
  94. '<paragraph>foo</paragraph>' +
  95. '<image src="foo.png"><caption>b[]ar</caption></image>' +
  96. '</tableCell>' +
  97. '</tableRow>' +
  98. '</table>'
  99. );
  100. editor.execute( 'selectAll' );
  101. editor.execute( 'selectAll' );
  102. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>' +
  103. '<table>' +
  104. '<tableRow>' +
  105. '<tableCell>' +
  106. '<paragraph>foo</paragraph>' +
  107. '[<image src="foo.png"><caption>bar</caption></image>]' +
  108. '</tableCell>' +
  109. '</tableRow>' +
  110. '</table>'
  111. );
  112. editor.execute( 'selectAll' );
  113. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>' +
  114. '<table>' +
  115. '<tableRow>' +
  116. '<tableCell>' +
  117. '<paragraph>[foo</paragraph>' +
  118. '<image src="foo.png"><caption>bar</caption></image>]' +
  119. '</tableCell>' +
  120. '</tableRow>' +
  121. '</table>'
  122. );
  123. editor.execute( 'selectAll' );
  124. expect( getData( model ) ).to.equal( '<paragraph>foo</paragraph>' +
  125. '[<table>' +
  126. '<tableRow>' +
  127. '<tableCell>' +
  128. '<paragraph>foo</paragraph>' +
  129. '<image src="foo.png"><caption>bar</caption></image>' +
  130. '</tableCell>' +
  131. '</tableRow>' +
  132. '</table>]'
  133. );
  134. } );
  135. } );
  136. } );