8
0

removerowcommand.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * @license Copyright (c) 2003-2019, 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 { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import RemoveRowCommand from '../../src/commands/removerowcommand';
  8. import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
  9. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  10. describe( 'RemoveRowCommand', () => {
  11. let editor, model, command;
  12. beforeEach( () => {
  13. return ModelTestEditor.create()
  14. .then( newEditor => {
  15. editor = newEditor;
  16. model = editor.model;
  17. command = new RemoveRowCommand( editor );
  18. defaultSchema( model.schema );
  19. defaultConversion( editor.conversion );
  20. } );
  21. } );
  22. afterEach( () => {
  23. return editor.destroy();
  24. } );
  25. describe( 'isEnabled', () => {
  26. it( 'should be true if selection is inside table cell', () => {
  27. setData( model, modelTable( [
  28. [ '00[]', '01' ],
  29. [ '10', '11' ]
  30. ] ) );
  31. expect( command.isEnabled ).to.be.true;
  32. } );
  33. it( 'should be false if selection is inside table with one row only', () => {
  34. setData( model, modelTable( [
  35. [ '00[]', '01' ]
  36. ] ) );
  37. expect( command.isEnabled ).to.be.false;
  38. } );
  39. it( 'should be false if selection is outside a table', () => {
  40. setData( model, '<paragraph>11[]</paragraph>' );
  41. expect( command.isEnabled ).to.be.false;
  42. } );
  43. } );
  44. describe( 'execute()', () => {
  45. it( 'should remove a given row', () => {
  46. setData( model, modelTable( [
  47. [ '00', '01' ],
  48. [ '[]10', '11' ],
  49. [ '20', '21' ]
  50. ] ) );
  51. command.execute();
  52. assertEqualMarkup( getData( model ), modelTable( [
  53. [ '00', '<paragraph>01[]</paragraph>' ],
  54. [ '20', '21' ]
  55. ] ) );
  56. } );
  57. it( 'should remove a given row from a table start', () => {
  58. setData( model, modelTable( [
  59. [ '[]00', '01' ],
  60. [ '10', '11' ],
  61. [ '20', '21' ]
  62. ] ) );
  63. command.execute();
  64. assertEqualMarkup( getData( model ), modelTable( [
  65. [ '<paragraph>[]10</paragraph>', '11' ],
  66. [ '20', '21' ]
  67. ] ) );
  68. } );
  69. it( 'should change heading rows if removing a heading row', () => {
  70. setData( model, modelTable( [
  71. [ '00', '01' ],
  72. [ '[]10', '11' ],
  73. [ '20', '21' ]
  74. ], { headingRows: 2 } ) );
  75. command.execute();
  76. assertEqualMarkup( getData( model ), modelTable( [
  77. [ '00', '<paragraph>01[]</paragraph>' ],
  78. [ '20', '21' ]
  79. ], { headingRows: 1 } ) );
  80. } );
  81. it( 'should decrease rowspan of table cells from previous rows', () => {
  82. setData( model, modelTable( [
  83. [ { rowspan: 4, contents: '00' }, { rowspan: 3, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
  84. [ { rowspan: 2, contents: '13' }, '14' ],
  85. [ '22[]', '23', '24' ],
  86. [ '30', '31', '32', '33', '34' ]
  87. ] ) );
  88. command.execute();
  89. assertEqualMarkup( getData( model ), modelTable( [
  90. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
  91. [ '13', '<paragraph>14[]</paragraph>' ],
  92. [ '30', '31', '32', '33', '34' ]
  93. ] ) );
  94. } );
  95. it( 'should move rowspaned cells to row below removing it\'s row', () => {
  96. setData( model, modelTable( [
  97. [ { rowspan: 3, contents: '[]00' }, { rowspan: 2, contents: '01' }, '02' ],
  98. [ '12' ],
  99. [ '22' ],
  100. [ '30', '31', '32' ]
  101. ] ) );
  102. command.execute();
  103. assertEqualMarkup( getData( model ), modelTable( [
  104. [ { rowspan: 2, contents: '[]00' }, '01', '12' ],
  105. [ '22' ],
  106. [ '30', '31', '32' ]
  107. ] ) );
  108. } );
  109. } );
  110. } );