8
0

tableutils.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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 { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import { defaultConversion, defaultSchema, modelTable } from './_utils/utils';
  8. import TableUtils from '../src/tableutils';
  9. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  10. describe( 'TableUtils', () => {
  11. let editor, model, root, tableUtils;
  12. beforeEach( () => {
  13. return ModelTestEditor.create( {
  14. plugins: [ TableUtils ]
  15. } ).then( newEditor => {
  16. editor = newEditor;
  17. model = editor.model;
  18. root = model.document.getRoot( 'main' );
  19. tableUtils = editor.plugins.get( TableUtils );
  20. defaultSchema( model.schema );
  21. defaultConversion( editor.conversion );
  22. } );
  23. } );
  24. afterEach( () => {
  25. return editor.destroy();
  26. } );
  27. describe( '#pluginName', () => {
  28. it( 'should provide plugin name', () => {
  29. expect( TableUtils.pluginName ).to.equal( 'TableUtils' );
  30. } );
  31. } );
  32. describe( 'getCellLocation()', () => {
  33. it( 'should return proper table cell location', () => {
  34. setData( model, modelTable( [
  35. [ { rowspan: 2, colspan: 2, contents: '00[]' }, '02' ],
  36. [ '12' ]
  37. ] ) );
  38. expect( tableUtils.getCellLocation( root.getNodeByPath( [ 0, 0, 0 ] ) ) ).to.deep.equal( { row: 0, column: 0 } );
  39. expect( tableUtils.getCellLocation( root.getNodeByPath( [ 0, 0, 1 ] ) ) ).to.deep.equal( { row: 0, column: 2 } );
  40. expect( tableUtils.getCellLocation( root.getNodeByPath( [ 0, 1, 0 ] ) ) ).to.deep.equal( { row: 1, column: 2 } );
  41. } );
  42. } );
  43. describe( 'insertRows()', () => {
  44. it( 'should insert row in given table at given index', () => {
  45. setData( model, modelTable( [
  46. [ '11[]', '12' ],
  47. [ '21', '22' ]
  48. ] ) );
  49. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  50. assertEqualMarkup( getData( model ), modelTable( [
  51. [ '11[]', '12' ],
  52. [ '', '' ],
  53. [ '21', '22' ]
  54. ] ) );
  55. } );
  56. it( 'should insert row in given table at default index', () => {
  57. setData( model, modelTable( [
  58. [ '11[]', '12' ],
  59. [ '21', '22' ]
  60. ] ) );
  61. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ) );
  62. assertEqualMarkup( getData( model ), modelTable( [
  63. [ '', '' ],
  64. [ '11[]', '12' ],
  65. [ '21', '22' ]
  66. ] ) );
  67. } );
  68. it( 'should update table heading rows attribute when inserting row in headings section', () => {
  69. setData( model, modelTable( [
  70. [ '11[]', '12' ],
  71. [ '21', '22' ],
  72. [ '31', '32' ]
  73. ], { headingRows: 2 } ) );
  74. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  75. assertEqualMarkup( getData( model ), modelTable( [
  76. [ '11[]', '12' ],
  77. [ '', '' ],
  78. [ '21', '22' ],
  79. [ '31', '32' ]
  80. ], { headingRows: 3 } ) );
  81. } );
  82. it( 'should not update table heading rows attribute when inserting row after headings section', () => {
  83. setData( model, modelTable( [
  84. [ '11[]', '12' ],
  85. [ '21', '22' ],
  86. [ '31', '32' ]
  87. ], { headingRows: 2 } ) );
  88. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2 } );
  89. assertEqualMarkup( getData( model ), modelTable( [
  90. [ '11[]', '12' ],
  91. [ '21', '22' ],
  92. [ '', '' ],
  93. [ '31', '32' ]
  94. ], { headingRows: 2 } ) );
  95. } );
  96. it( 'should expand rowspan of a cell that overlaps inserted rows', () => {
  97. setData( model, modelTable( [
  98. [ { colspan: 2, contents: '11[]' }, '13', '14' ],
  99. [ { colspan: 2, rowspan: 4, contents: '21' }, '23', '24' ],
  100. [ '33', '34' ]
  101. ], { headingColumns: 3, headingRows: 1 } ) );
  102. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
  103. assertEqualMarkup( getData( model ), modelTable( [
  104. [ { colspan: 2, contents: '11[]' }, '13', '14' ],
  105. [ { colspan: 2, rowspan: 7, contents: '21' }, '23', '24' ],
  106. [ '', '' ],
  107. [ '', '' ],
  108. [ '', '' ],
  109. [ '33', '34' ]
  110. ], { headingColumns: 3, headingRows: 1 } ) );
  111. } );
  112. it( 'should not expand rowspan of a cell that does not overlaps inserted rows', () => {
  113. setData( model, modelTable( [
  114. [ { rowspan: 2, contents: '11[]' }, '12', '13' ],
  115. [ '22', '23' ],
  116. [ '31', '32', '33' ]
  117. ], { headingColumns: 3, headingRows: 1 } ) );
  118. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
  119. assertEqualMarkup( getData( model ), modelTable( [
  120. [ { rowspan: 2, contents: '11[]' }, '12', '13' ],
  121. [ '22', '23' ],
  122. [ '', '', '' ],
  123. [ '', '', '' ],
  124. [ '', '', '' ],
  125. [ '31', '32', '33' ]
  126. ], { headingColumns: 3, headingRows: 1 } ) );
  127. } );
  128. it( 'should properly calculate columns if next row has colspans', () => {
  129. setData( model, modelTable( [
  130. [ { rowspan: 2, contents: '11[]' }, '12', '13' ],
  131. [ '22', '23' ],
  132. [ { colspan: 3, contents: '31' } ]
  133. ], { headingColumns: 3, headingRows: 1 } ) );
  134. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
  135. assertEqualMarkup( getData( model ), modelTable( [
  136. [ { rowspan: 2, contents: '11[]' }, '12', '13' ],
  137. [ '22', '23' ],
  138. [ '', '', '' ],
  139. [ '', '', '' ],
  140. [ '', '', '' ],
  141. [ { colspan: 3, contents: '31' } ]
  142. ], { headingColumns: 3, headingRows: 1 } ) );
  143. } );
  144. it( 'should insert rows at the end of a table', () => {
  145. setData( model, modelTable( [
  146. [ '11[]', '12' ],
  147. [ '21', '22' ]
  148. ] ) );
  149. tableUtils.insertRows( root.getNodeByPath( [ 0 ] ), { at: 2, rows: 3 } );
  150. assertEqualMarkup( getData( model ), modelTable( [
  151. [ '11[]', '12' ],
  152. [ '21', '22' ],
  153. [ '', '' ],
  154. [ '', '' ],
  155. [ '', '' ]
  156. ] ) );
  157. } );
  158. } );
  159. describe( 'insertColumns()', () => {
  160. it( 'should insert column in given table at given index', () => {
  161. setData( model, modelTable( [
  162. [ '11[]', '12' ],
  163. [ '21', '22' ]
  164. ] ) );
  165. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  166. assertEqualMarkup( getData( model ), modelTable( [
  167. [ '11[]', '', '12' ],
  168. [ '21', '', '22' ]
  169. ] ) );
  170. } );
  171. it( 'should insert column in given table with default values', () => {
  172. setData( model, modelTable( [
  173. [ '11[]', '12' ],
  174. [ '21', '22' ]
  175. ] ) );
  176. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ) );
  177. assertEqualMarkup( getData( model ), modelTable( [
  178. [ '', '11[]', '12' ],
  179. [ '', '21', '22' ]
  180. ] ) );
  181. } );
  182. it( 'should insert column in given table at default index', () => {
  183. setData( model, modelTable( [
  184. [ '11[]', '12' ],
  185. [ '21', '22' ]
  186. ] ) );
  187. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ) );
  188. assertEqualMarkup( getData( model ), modelTable( [
  189. [ '', '11[]', '12' ],
  190. [ '', '21', '22' ]
  191. ] ) );
  192. } );
  193. it( 'should insert columns at the end of a row', () => {
  194. setData( model, modelTable( [
  195. [ '00[]', '01' ],
  196. [ { colspan: 2, contents: '10' } ],
  197. [ '20', { rowspan: 2, contents: '21' } ],
  198. [ '30' ]
  199. ] ) );
  200. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 2, columns: 2 } );
  201. assertEqualMarkup( getData( model ), modelTable( [
  202. [ '00[]', '01', '', '' ],
  203. [ { colspan: 2, contents: '10' }, '', '' ],
  204. [ '20', { rowspan: 2, contents: '21' }, '', '' ],
  205. [ '30', '', '' ]
  206. ] ) );
  207. } );
  208. it( 'should insert columns at the beginning of a row', () => {
  209. setData( model, modelTable( [
  210. [ '00[]', '01' ],
  211. [ { colspan: 2, contents: '10' } ],
  212. [ '20', { rowspan: 2, contents: '21' } ],
  213. [ { rowspan: 2, contents: '30' } ],
  214. [ '41' ]
  215. ] ) );
  216. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 0, columns: 2 } );
  217. assertEqualMarkup( getData( model ), modelTable( [
  218. [ '', '', '00[]', '01' ],
  219. [ '', '', { colspan: 2, contents: '10' } ],
  220. [ '', '', '20', { rowspan: 2, contents: '21' } ],
  221. [ '', '', { rowspan: 2, contents: '30' } ],
  222. [ '', '', '41' ]
  223. ] ) );
  224. } );
  225. it( 'should properly insert column at beginning of row-col-spanned cell', () => {
  226. setData( model, modelTable( [
  227. [ '11', '12', '13' ],
  228. [ '21', { colspan: 2, rowspan: 2, contents: '22[]' } ],
  229. [ '31' ],
  230. [ '41', '42', '43' ]
  231. ] ) );
  232. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 1 } );
  233. assertEqualMarkup( getData( model ), modelTable( [
  234. [ '11', '', '12', '13' ],
  235. [ '21', '', { colspan: 2, rowspan: 2, contents: '22[]' } ],
  236. [ '31', '' ],
  237. [ '41', '', '42', '43' ]
  238. ] ) );
  239. } );
  240. it( 'should update table heading columns attribute when inserting column in headings section', () => {
  241. setData( model, modelTable( [
  242. [ '11[]', '12' ],
  243. [ '21', '22' ],
  244. [ '31', '32' ]
  245. ], { headingColumns: 2 } ) );
  246. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  247. assertEqualMarkup( getData( model ), modelTable( [
  248. [ '11[]', '', '12' ],
  249. [ '21', '', '22' ],
  250. [ '31', '', '32' ]
  251. ], { headingColumns: 3 } ) );
  252. } );
  253. it( 'should not update table heading columns attribute when inserting column after headings section', () => {
  254. setData( model, modelTable( [
  255. [ '11[]', '12', '13' ],
  256. [ '21', '22', '23' ],
  257. [ '31', '32', '33' ]
  258. ], { headingColumns: 2 } ) );
  259. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 2 } );
  260. assertEqualMarkup( getData( model ), modelTable( [
  261. [ '11[]', '12', '', '13' ],
  262. [ '21', '22', '', '23' ],
  263. [ '31', '32', '', '33' ]
  264. ], { headingColumns: 2 } ) );
  265. } );
  266. it( 'should expand spanned columns', () => {
  267. setData( model, modelTable( [
  268. [ '00[]', '01' ],
  269. [ { colspan: 2, contents: '10' } ],
  270. [ '20', '21' ]
  271. ], { headingColumns: 2 } ) );
  272. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  273. assertEqualMarkup( getData( model ), modelTable( [
  274. [ '00[]', '', '01' ],
  275. [ { colspan: 3, contents: '10' } ],
  276. [ '20', '', '21' ]
  277. ], { headingColumns: 3 } ) );
  278. } );
  279. it( 'should skip wide spanned columns', () => {
  280. setData( model, modelTable( [
  281. [ '11[]', '12', '13', '14', '15' ],
  282. [ '21', '22', { colspan: 2, contents: '23' }, '25' ],
  283. [ { colspan: 4, contents: '31' }, { colspan: 2, contents: '34' } ]
  284. ], { headingColumns: 4 } ) );
  285. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 2, columns: 2 } );
  286. assertEqualMarkup( getData( model ), modelTable( [
  287. [ '11[]', '12', '', '', '13', '14', '15' ],
  288. [ '21', '22', '', '', { colspan: 2, contents: '23' }, '25' ],
  289. [ { colspan: 6, contents: '31' }, { colspan: 2, contents: '34' } ]
  290. ], { headingColumns: 6 } ) );
  291. } );
  292. it( 'should skip row & column spanned cells', () => {
  293. setData( model, modelTable( [
  294. [ { colspan: 2, rowspan: 2, contents: '00[]' }, '02' ],
  295. [ '12' ],
  296. [ '20', '21', '22' ]
  297. ], { headingColumns: 2 } ) );
  298. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 2 } );
  299. assertEqualMarkup( getData( model ), modelTable( [
  300. [ { colspan: 4, rowspan: 2, contents: '00[]' }, '02' ],
  301. [ '12' ],
  302. [ '20', '', '', '21', '22' ]
  303. ], { headingColumns: 4 } ) );
  304. } );
  305. it( 'should properly insert column while table has rowspanned cells', () => {
  306. setData( model, modelTable( [
  307. [ { rowspan: 4, contents: '00[]' }, { rowspan: 2, contents: '01' }, '02' ],
  308. [ '12' ],
  309. [ { rowspan: 2, contents: '21' }, '22' ],
  310. [ '32' ]
  311. ], { headingColumns: 2 } ) );
  312. tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 1 } );
  313. assertEqualMarkup( getData( model ), modelTable( [
  314. [ { rowspan: 4, contents: '00[]' }, '', { rowspan: 2, contents: '01' }, '02' ],
  315. [ '', '12' ],
  316. [ '', { rowspan: 2, contents: '21' }, '22' ],
  317. [ '', '32' ]
  318. ], { headingColumns: 3 } ) );
  319. } );
  320. } );
  321. describe( 'splitCellVertically()', () => {
  322. it( 'should split table cell to given table cells number', () => {
  323. setData( model, modelTable( [
  324. [ '00', '01', '02' ],
  325. [ '10', '[]11', '12' ],
  326. [ '20', { colspan: 2, contents: '21' } ],
  327. [ { colspan: 2, contents: '30' }, '32' ]
  328. ] ) );
  329. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 1 ] ), 3 );
  330. assertEqualMarkup( getData( model ), modelTable( [
  331. [ '00', { colspan: 3, contents: '01' }, '02' ],
  332. [ '10', '[]11', '', '', '12' ],
  333. [ '20', { colspan: 4, contents: '21' } ],
  334. [ { colspan: 4, contents: '30' }, '32' ]
  335. ] ) );
  336. } );
  337. it( 'should split table cell for two table cells as a default', () => {
  338. setData( model, modelTable( [
  339. [ '00', '01', '02' ],
  340. [ '10', '[]11', '12' ],
  341. [ '20', { colspan: 2, contents: '21' } ],
  342. [ { colspan: 2, contents: '30' }, '32' ]
  343. ] ) );
  344. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 1 ] ) );
  345. assertEqualMarkup( getData( model ), modelTable( [
  346. [ '00', { colspan: 2, contents: '01' }, '02' ],
  347. [ '10', '[]11', '', '12' ],
  348. [ '20', { colspan: 3, contents: '21' } ],
  349. [ { colspan: 3, contents: '30' }, '32' ]
  350. ] ) );
  351. } );
  352. it( 'should split table cell if split is equal to colspan', () => {
  353. setData( model, modelTable( [
  354. [ '00', '01', '02' ],
  355. [ '10', '11', '12' ],
  356. [ '20', { colspan: 2, contents: '21[]' } ],
  357. [ { colspan: 2, contents: '30' }, '32' ]
  358. ] ) );
  359. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 2, 1 ] ), 2 );
  360. assertEqualMarkup( getData( model ), modelTable( [
  361. [ '00', '01', '02' ],
  362. [ '10', '11', '12' ],
  363. [ '20', '21[]', '' ],
  364. [ { colspan: 2, contents: '30' }, '32' ]
  365. ] ) );
  366. } );
  367. it( 'should properly split table cell if split is uneven', () => {
  368. setData( model, modelTable( [
  369. [ '00', '01', '02' ],
  370. [ { colspan: 3, contents: '10[]' } ]
  371. ] ) );
  372. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 2 );
  373. assertEqualMarkup( getData( model ), modelTable( [
  374. [ '00', '01', '02' ],
  375. [ { colspan: 2, contents: '10[]' }, '' ]
  376. ] ) );
  377. } );
  378. it( 'should properly set colspan of inserted cells', () => {
  379. setData( model, modelTable( [
  380. [ '00', '01', '02', '03' ],
  381. [ { colspan: 4, contents: '10[]' } ]
  382. ] ) );
  383. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 2 );
  384. assertEqualMarkup( getData( model ), modelTable( [
  385. [ '00', '01', '02', '03' ],
  386. [ { colspan: 2, contents: '10[]' }, { colspan: 2, contents: '' } ]
  387. ] ) );
  388. } );
  389. it( 'should keep rowspan attribute for newly inserted cells', () => {
  390. setData( model, modelTable( [
  391. [ '00', '01', '02', '03', '04', '05' ],
  392. [ { colspan: 5, rowspan: 2, contents: '10[]' }, '15' ],
  393. [ '25' ]
  394. ] ) );
  395. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 2 );
  396. assertEqualMarkup( getData( model ), modelTable( [
  397. [ '00', '01', '02', '03', '04', '05' ],
  398. [ { colspan: 3, rowspan: 2, contents: '10[]' }, { colspan: 2, rowspan: 2, contents: '' }, '15' ],
  399. [ '25' ]
  400. ] ) );
  401. } );
  402. it( 'should keep rowspan attribute of for newly inserted cells if number of cells is bigger then curren colspan', () => {
  403. setData( model, modelTable( [
  404. [ '00', '01', '02' ],
  405. [ { colspan: 2, rowspan: 2, contents: '10[]' }, '12' ],
  406. [ '22' ]
  407. ] ) );
  408. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 3 );
  409. assertEqualMarkup( getData( model ), modelTable( [
  410. [ { colspan: 2, contents: '00' }, '01', '02' ],
  411. [ { rowspan: 2, contents: '10[]' }, { rowspan: 2, contents: '' }, { rowspan: 2, contents: '' }, '12' ],
  412. [ '22' ]
  413. ] ) );
  414. } );
  415. it( 'should properly break a cell if it has colspan and number of created cells is bigger then colspan', () => {
  416. setData( model, modelTable( [
  417. [ '00', '01', '02', '03' ],
  418. [ { colspan: 4, contents: '10[]' } ]
  419. ] ) );
  420. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 6 );
  421. assertEqualMarkup( getData( model ), modelTable( [
  422. [ { colspan: 3, contents: '00' }, '01', '02', '03' ],
  423. [ '10[]', '', '', '', '', '' ]
  424. ] ) );
  425. } );
  426. it( 'should update heading columns is split cell is in heading section', () => {
  427. setData( model, modelTable( [
  428. [ '00', '01' ],
  429. [ '10[]', '11' ]
  430. ], { headingColumns: 1 } ) );
  431. tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 1, 0 ] ), 3 );
  432. assertEqualMarkup( getData( model ), modelTable( [
  433. [ { colspan: 3, contents: '00' }, '01' ],
  434. [ '10[]', '', '', '11' ]
  435. ], { headingColumns: 3 } ) );
  436. } );
  437. } );
  438. describe( 'splitCellHorizontally()', () => {
  439. it( 'should split table cell to default table cells number', () => {
  440. setData( model, modelTable( [
  441. [ '00', '01', '02' ],
  442. [ '10', '[]11', '12' ],
  443. [ '20', '21', '22' ]
  444. ] ) );
  445. tableUtils.splitCellHorizontally( root.getNodeByPath( [ 0, 1, 1 ] ) );
  446. assertEqualMarkup( getData( model ), modelTable( [
  447. [ '00', '01', '02' ],
  448. [ { rowspan: 2, contents: '10' }, '[]11', { rowspan: 2, contents: '12' } ],
  449. [ '' ],
  450. [ '20', '21', '22' ]
  451. ] ) );
  452. } );
  453. it( 'should split table cell to given table cells number', () => {
  454. setData( model, modelTable( [
  455. [ '00', '01', '02' ],
  456. [ '10', '[]11', '12' ],
  457. [ '20', '21', '22' ]
  458. ] ) );
  459. tableUtils.splitCellHorizontally( root.getNodeByPath( [ 0, 1, 1 ] ), 4 );
  460. assertEqualMarkup( getData( model ), modelTable( [
  461. [ '00', '01', '02' ],
  462. [ { rowspan: 4, contents: '10' }, '[]11', { rowspan: 4, contents: '12' } ],
  463. [ '' ],
  464. [ '' ],
  465. [ '' ],
  466. [ '20', '21', '22' ]
  467. ] ) );
  468. } );
  469. it( 'should properly update rowspanned cells overlapping selected cell', () => {
  470. setData( model, modelTable( [
  471. [ { rowspan: 2, contents: '00' }, '01', { rowspan: 3, contents: '02' } ],
  472. [ '[]11' ],
  473. [ '20', '21' ]
  474. ] ) );
  475. tableUtils.splitCellHorizontally( root.getNodeByPath( [ 0, 1, 0 ] ), 3 );
  476. assertEqualMarkup( getData( model ), modelTable( [
  477. [ { rowspan: 4, contents: '00' }, '01', { rowspan: 5, contents: '02' } ],
  478. [ '[]11' ],
  479. [ '' ],
  480. [ '' ],
  481. [ '20', '21' ]
  482. ] ) );
  483. } );
  484. it( 'should split rowspanned cell', () => {
  485. setData( model, modelTable( [
  486. [ '00', { rowspan: 2, contents: '01[]' } ],
  487. [ '10' ],
  488. [ '20', '21' ]
  489. ] ) );
  490. const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
  491. tableUtils.splitCellHorizontally( tableCell, 2 );
  492. assertEqualMarkup( getData( model ), modelTable( [
  493. [ '00', '01[]' ],
  494. [ '10', '' ],
  495. [ '20', '21' ]
  496. ] ) );
  497. } );
  498. it( 'should copy colspan while splitting rowspanned cell', () => {
  499. setData( model, modelTable( [
  500. [ '00', { rowspan: 2, colspan: 2, contents: '01[]' } ],
  501. [ '10' ],
  502. [ '20', '21', '22' ]
  503. ] ) );
  504. const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
  505. tableUtils.splitCellHorizontally( tableCell, 2 );
  506. assertEqualMarkup( getData( model ), modelTable( [
  507. [ '00', { colspan: 2, contents: '01[]' } ],
  508. [ '10', { colspan: 2, contents: '' } ],
  509. [ '20', '21', '22' ]
  510. ] ) );
  511. } );
  512. it( 'should evenly distribute rowspan attribute', () => {
  513. setData( model, modelTable( [
  514. [ '00', { rowspan: 7, contents: '01[]' } ],
  515. [ '10' ],
  516. [ '20' ],
  517. [ '30' ],
  518. [ '40' ],
  519. [ '50' ],
  520. [ '60' ],
  521. [ '70', '71' ]
  522. ] ) );
  523. const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
  524. tableUtils.splitCellHorizontally( tableCell, 3 );
  525. assertEqualMarkup( getData( model ), modelTable( [
  526. [ '00', { rowspan: 3, contents: '01[]' } ],
  527. [ '10' ],
  528. [ '20' ],
  529. [ '30', { rowspan: 2, contents: '' } ],
  530. [ '40' ],
  531. [ '50', { rowspan: 2, contents: '' } ],
  532. [ '60' ],
  533. [ '70', '71' ]
  534. ] ) );
  535. } );
  536. it( 'should split rowspanned cell and updated other cells rowspan when splitting to bigger number of cells', () => {
  537. setData( model, modelTable( [
  538. [ '00', { rowspan: 2, contents: '01[]' } ],
  539. [ '10' ],
  540. [ '20', '21' ]
  541. ] ) );
  542. const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
  543. tableUtils.splitCellHorizontally( tableCell, 3 );
  544. assertEqualMarkup( getData( model ), modelTable( [
  545. [ { rowspan: 2, contents: '00' }, '01[]' ],
  546. [ '' ],
  547. [ '10', '' ],
  548. [ '20', '21' ]
  549. ] ) );
  550. } );
  551. it( 'should split rowspanned & colspaned cell', () => {
  552. setData( model, modelTable( [
  553. [ '00', { colspan: 2, contents: '01[]' } ],
  554. [ '10', '11' ]
  555. ] ) );
  556. const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
  557. tableUtils.splitCellHorizontally( tableCell, 3 );
  558. assertEqualMarkup( getData( model ), modelTable( [
  559. [ { rowspan: 3, contents: '00' }, { colspan: 2, contents: '01[]' } ],
  560. [ { colspan: 2, contents: '' } ],
  561. [ { colspan: 2, contents: '' } ],
  562. [ '10', '11' ]
  563. ] ) );
  564. } );
  565. it( 'should split table cell from a heading section', () => {
  566. setData( model, modelTable( [
  567. [ '00[]', '01', '02' ],
  568. [ '10', '11', '12' ],
  569. [ '20', '21', '22' ]
  570. ], { headingRows: 1 } ) );
  571. tableUtils.splitCellHorizontally( root.getNodeByPath( [ 0, 0, 0 ] ), 3 );
  572. assertEqualMarkup( getData( model ), modelTable( [
  573. [ '00[]', { rowspan: 3, contents: '01' }, { rowspan: 3, contents: '02' } ],
  574. [ '' ],
  575. [ '' ],
  576. [ '10', '11', '12' ],
  577. [ '20', '21', '22' ]
  578. ], { headingRows: 3 } ) );
  579. } );
  580. } );
  581. describe( 'getColumns()', () => {
  582. it( 'should return proper number of columns', () => {
  583. setData( model, modelTable( [
  584. [ '00', { colspan: 3, contents: '01' }, '04' ]
  585. ] ) );
  586. expect( tableUtils.getColumns( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 5 );
  587. } );
  588. } );
  589. describe( 'getRows()', () => {
  590. it( 'should return proper number of columns for simple table', () => {
  591. setData( model, modelTable( [
  592. [ '00', '01' ],
  593. [ '10', '11' ]
  594. ] ) );
  595. expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 2 );
  596. } );
  597. it( 'should return proper number of columns for a table with header', () => {
  598. setData( model, modelTable( [
  599. [ '00', '01' ],
  600. [ '10', '11' ]
  601. ], { headingRows: 1 } ) );
  602. expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 2 );
  603. } );
  604. it( 'should return proper number of columns for rowspan table', () => {
  605. setData( model, modelTable( [
  606. [ '00', '01' ],
  607. [ { rowspan: 2, contents: '10' }, '11' ],
  608. [ '21' ]
  609. ] ) );
  610. expect( tableUtils.getRows( root.getNodeByPath( [ 0 ] ) ) ).to.equal( 3 );
  611. } );
  612. } );
  613. describe( 'removeRows()', () => {
  614. describe( 'single row', () => {
  615. it( 'should remove a given row from a table start', () => {
  616. setData( model, modelTable( [
  617. [ '00', '01' ],
  618. [ '10', '11' ],
  619. [ '20', '21' ]
  620. ] ) );
  621. tableUtils.removeRows( root.getChild( 0 ), { at: 0 } );
  622. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  623. [ '10', '11' ],
  624. [ '20', '21' ]
  625. ] ) );
  626. } );
  627. it( 'should remove last row', () => {
  628. setData( model, modelTable( [
  629. [ '00', '01' ],
  630. [ '10', '11' ]
  631. ] ) );
  632. tableUtils.removeRows( root.getChild( 0 ), { at: 1 } );
  633. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  634. [ '00', '01' ]
  635. ] ) );
  636. } );
  637. it( 'should change heading rows if removing a heading row', () => {
  638. setData( model, modelTable( [
  639. [ '00', '01' ],
  640. [ '10', '11' ],
  641. [ '20', '21' ]
  642. ], { headingRows: 2 } ) );
  643. tableUtils.removeRows( root.getChild( 0 ), { at: 1 } );
  644. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  645. [ '00', '01' ],
  646. [ '20', '21' ]
  647. ], { headingRows: 1 } ) );
  648. } );
  649. it( 'should decrease rowspan of table cells from previous rows', () => {
  650. setData( model, modelTable( [
  651. [ { rowspan: 4, contents: '00' }, { rowspan: 3, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
  652. [ { rowspan: 2, contents: '13' }, '14' ],
  653. [ '22', '23', '24' ],
  654. [ '31', '32', '33', '34' ]
  655. ] ) );
  656. tableUtils.removeRows( root.getChild( 0 ), { at: 2 } );
  657. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  658. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
  659. [ '13', '14' ],
  660. [ '31', '32', '33', '34' ]
  661. ] ) );
  662. } );
  663. it( 'should move rowspaned cells to a row below removing it\'s row', () => {
  664. setData( model, modelTable( [
  665. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, '02' ],
  666. [ '12' ],
  667. [ '21', '22' ],
  668. [ '30', '31', '32' ]
  669. ] ) );
  670. tableUtils.removeRows( root.getChild( 0 ), { at: 0 } );
  671. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  672. [ { rowspan: 2, contents: '00' }, '01', '12' ],
  673. [ '21', '22' ],
  674. [ '30', '31', '32' ]
  675. ] ) );
  676. } );
  677. it( 'should move rowspaned cells to a row below removing it\'s row (other cell is overlapping removed row)', () => {
  678. setData( model, modelTable( [
  679. [ '00', { rowspan: 3, contents: '01' }, '02', '03', '04' ],
  680. [ '10', { rowspan: 2, contents: '12' }, '13', '14' ],
  681. [ '20', '23', '24' ]
  682. ] ) );
  683. tableUtils.removeRows( root.getChild( 0 ), { at: 1 } );
  684. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  685. [ '00', { rowspan: 2, contents: '01' }, '02', '03', '04' ],
  686. [ '20', '12', '23', '24' ]
  687. ] ) );
  688. } );
  689. } );
  690. describe( 'many rows', () => {
  691. it( 'should properly remove middle rows', () => {
  692. setData( model, modelTable( [
  693. [ '00', '01' ],
  694. [ '10', '11' ],
  695. [ '20', '21' ],
  696. [ '30', '31' ]
  697. ] ) );
  698. tableUtils.removeRows( root.getChild( 0 ), { at: 1, rows: 2 } );
  699. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  700. [ '00', '01' ],
  701. [ '30', '31' ]
  702. ] ) );
  703. } );
  704. it( 'should properly remove tailing rows', () => {
  705. setData( model, modelTable( [
  706. [ '00', '01' ],
  707. [ '10', '11' ],
  708. [ '20', '21' ],
  709. [ '30', '31' ]
  710. ] ) );
  711. tableUtils.removeRows( root.getChild( 0 ), { at: 2, rows: 2 } );
  712. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  713. [ '00', '01' ],
  714. [ '10', '11' ]
  715. ] ) );
  716. } );
  717. it( 'should properly remove beginning rows', () => {
  718. setData( model, modelTable( [
  719. [ '00', '01' ],
  720. [ '10', '11' ],
  721. [ '20', '21' ],
  722. [ '30', '31' ]
  723. ] ) );
  724. tableUtils.removeRows( root.getChild( 0 ), { at: 0, rows: 2 } );
  725. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  726. [ '20', '21' ],
  727. [ '30', '31' ]
  728. ] ) );
  729. } );
  730. it( 'should support removing multiple headings (removed rows in heading section)', () => {
  731. setData( model, modelTable( [
  732. [ '00', '01' ],
  733. [ '10', '11' ],
  734. [ '20', '21' ],
  735. [ '30', '31' ]
  736. ], { headingRows: 3 } ) );
  737. tableUtils.removeRows( root.getChild( 0 ), { at: 0, rows: 2 } );
  738. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  739. [ '20', '21' ],
  740. [ '30', '31' ]
  741. ], { headingRows: 1 } ) );
  742. } );
  743. it( 'should support removing multiple headings (removed rows in heading and body section)', () => {
  744. setData( model, modelTable( [
  745. [ '00', '01' ],
  746. [ '10', '11' ],
  747. [ '20', '21' ],
  748. [ '30', '31' ],
  749. [ '40', '41' ]
  750. ], { headingRows: 3 } ) );
  751. tableUtils.removeRows( root.getChild( 0 ), { at: 1, rows: 3 } );
  752. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  753. [ '00', '01' ],
  754. [ '40', '41' ]
  755. ], { headingRows: 1 } ) );
  756. } );
  757. it( 'should support removing mixed heading and cell rows', () => {
  758. setData( model, modelTable( [
  759. [ '00', '01' ],
  760. [ '10', '11' ],
  761. [ '20', '21' ]
  762. ], { headingRows: 1 } ) );
  763. tableUtils.removeRows( root.getChild( 0 ), { at: 0, rows: 2 } );
  764. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  765. [ '20', '21' ]
  766. ] ) );
  767. } );
  768. it( 'should properly calculate truncated rowspans', () => {
  769. setData( model, modelTable( [
  770. [ '00', { contents: '01', rowspan: 3 } ],
  771. [ '10' ],
  772. [ '20' ]
  773. ] ) );
  774. tableUtils.removeRows( root.getChild( 0 ), { at: 0, rows: 2 } );
  775. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  776. [ '20', '01' ]
  777. ] ) );
  778. } );
  779. it( 'should decrease rowspan of table cells from rows before removed rows section', () => {
  780. setData( model, modelTable( [
  781. [ { rowspan: 4, contents: '00' }, { rowspan: 3, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
  782. [ '13', '14' ],
  783. [ '22', '23', '24' ],
  784. [ '31', '32', '33', '34' ]
  785. ] ) );
  786. tableUtils.removeRows( root.getChild( 0 ), { at: 1, rows: 2 } );
  787. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  788. [ { rowspan: 2, contents: '00' }, '01', '02', '03', '04' ],
  789. [ '31', '32', '33', '34' ]
  790. ] ) );
  791. } );
  792. it( 'should create one undo step (1 batch)', () => {
  793. setData( model, modelTable( [
  794. [ '00', '01' ],
  795. [ '10', '11' ],
  796. [ '20', '21' ],
  797. [ '30', '31' ]
  798. ], { headingRows: 3 } ) );
  799. const createdBatches = new Set();
  800. model.on( 'applyOperation', ( evt, args ) => {
  801. const operation = args[ 0 ];
  802. createdBatches.add( operation.batch );
  803. } );
  804. tableUtils.removeRows( root.getChild( 0 ), { at: 0, rows: 2 } );
  805. expect( createdBatches.size ).to.equal( 1 );
  806. } );
  807. } );
  808. } );
  809. describe( 'removeColumns()', () => {
  810. describe( 'single row', () => {
  811. it( 'should remove a given column', () => {
  812. setData( model, modelTable( [
  813. [ '00', '01', '02' ],
  814. [ '10', '11', '12' ],
  815. [ '20', '21', '22' ]
  816. ] ) );
  817. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  818. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  819. [ '00', '02' ],
  820. [ '10', '12' ],
  821. [ '20', '22' ]
  822. ] ) );
  823. } );
  824. it( 'should remove a given column from a table start', () => {
  825. setData( model, modelTable( [
  826. [ '00', '01' ],
  827. [ '10', '11' ],
  828. [ '20', '21' ]
  829. ] ) );
  830. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  831. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  832. [ '01' ],
  833. [ '11' ],
  834. [ '21' ]
  835. ] ) );
  836. } );
  837. it( 'should change heading columns if removing a heading column', () => {
  838. setData( model, modelTable( [
  839. [ '00', '01' ],
  840. [ '10', '11' ],
  841. [ '20', '21' ]
  842. ], { headingColumns: 2 } ) );
  843. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  844. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  845. [ '01' ],
  846. [ '11' ],
  847. [ '21' ]
  848. ], { headingColumns: 1 } ) );
  849. } );
  850. it( 'should decrease colspan of table cells from previous column', () => {
  851. setData( model, modelTable( [
  852. [ { colspan: 4, contents: '00' }, '04' ],
  853. [ { colspan: 3, contents: '10' }, '13', '14' ],
  854. [ { colspan: 2, contents: '20' }, '22', '23', '24' ],
  855. [ '30', { colspan: 2, contents: '31' }, '33', '34' ],
  856. [ '40', '41', '42', '43', '44' ]
  857. ] ) );
  858. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 2 } );
  859. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  860. [ { colspan: 3, contents: '00' }, '04' ],
  861. [ { colspan: 2, contents: '10' }, '13', '14' ],
  862. [ { colspan: 2, contents: '20' }, '23', '24' ],
  863. [ '30', '31', '33', '34' ],
  864. [ '40', '41', '43', '44' ]
  865. ] ) );
  866. } );
  867. it( 'should decrease colspan of cells that are on removed column', () => {
  868. setData( model, modelTable( [
  869. [ { colspan: 3, contents: '00' }, '03' ],
  870. [ { colspan: 2, contents: '10' }, '12', '13' ],
  871. [ '20', '21', '22', '23' ]
  872. ] ) );
  873. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  874. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  875. [ { colspan: 2, contents: '00' }, '03' ],
  876. [ '10', '12', '13' ],
  877. [ '21', '22', '23' ]
  878. ] ) );
  879. } );
  880. it( 'should remove column with rowspan (first column)', () => {
  881. setData( model, modelTable( [
  882. [ { rowspan: 2, contents: '00' }, '01' ],
  883. [ '11' ]
  884. ] ) );
  885. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  886. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  887. [ '01' ],
  888. [ '11' ]
  889. ] ) );
  890. } );
  891. it( 'should remove column with rowspan (last column)', () => {
  892. setData( model, modelTable( [
  893. [ '00', { rowspan: 2, contents: '01' } ],
  894. [ '10' ]
  895. ] ) );
  896. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  897. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  898. [ '00' ],
  899. [ '10' ]
  900. ] ) );
  901. } );
  902. it( 'should remove column if other column is rowspanned (last column)', () => {
  903. setData( model, modelTable( [
  904. [ '00', { rowspan: 2, contents: '01' } ],
  905. [ '10' ]
  906. ] ) );
  907. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  908. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  909. [ '01' ]
  910. ] ) );
  911. } );
  912. it( 'should remove column if other column is rowspanned (first column)', () => {
  913. setData( model, modelTable( [
  914. [ { rowspan: 2, contents: '00' }, '01' ],
  915. [ '11' ]
  916. ] ) );
  917. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1 } );
  918. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  919. [ '00' ]
  920. ] ) );
  921. } );
  922. it( 'should remove column if removing row with one column - other columns are spanned', () => {
  923. setData( model, modelTable( [
  924. [ '00', { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' } ],
  925. [ '10' ],
  926. [ '20', '21', '22' ]
  927. ] ) );
  928. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0 } );
  929. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  930. [ '01', '02' ],
  931. [ '21', '22' ]
  932. ] ) );
  933. } );
  934. } );
  935. describe( 'multiple columns', () => {
  936. it( 'should properly remove two first columns', () => {
  937. setData( model, modelTable( [
  938. [ '00', '01', '02' ],
  939. [ '10', '11', '12' ],
  940. [ '20', '21', '22' ],
  941. [ '30', '31', '32' ]
  942. ] ) );
  943. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0, columns: 2 } );
  944. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  945. [ '02' ],
  946. [ '12' ],
  947. [ '22' ],
  948. [ '32' ]
  949. ] ) );
  950. } );
  951. it( 'should properly remove two middle columns', () => {
  952. setData( model, modelTable( [
  953. [ '00', '01', '02', '03' ],
  954. [ '10', '11', '12', '13' ],
  955. [ '20', '21', '22', '23' ],
  956. [ '30', '31', '32', '33' ]
  957. ] ) );
  958. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 2 } );
  959. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  960. [ '00', '03' ],
  961. [ '10', '13' ],
  962. [ '20', '23' ],
  963. [ '30', '33' ]
  964. ] ) );
  965. } );
  966. it( 'should properly remove two last columns', () => {
  967. setData( model, modelTable( [
  968. [ '00', '01', '02' ],
  969. [ '10', '11', '12' ],
  970. [ '20', '21', '22' ],
  971. [ '30', '31', '32' ]
  972. ] ) );
  973. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 2 } );
  974. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  975. [ '00' ],
  976. [ '10' ],
  977. [ '20' ],
  978. [ '30' ]
  979. ] ) );
  980. } );
  981. it( 'should properly remove multiple heading columns', () => {
  982. setData( model, modelTable( [
  983. [ '00', '01', '02', '03', '04' ],
  984. [ '10', '11', '12', '13', '14' ]
  985. ], { headingColumns: 3 } ) );
  986. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 3 } );
  987. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  988. [ '00', '04' ],
  989. [ '10', '14' ]
  990. ], { headingColumns: 1 } ) );
  991. } );
  992. it( 'should properly calculate truncated colspans', () => {
  993. setData( model, modelTable( [
  994. [ { contents: '00', colspan: 3 } ],
  995. [ '10', '11', '12' ],
  996. [ '20', '21', '22' ]
  997. ] ) );
  998. tableUtils.removeColumns( root.getNodeByPath( [ 0 ] ), { at: 0, columns: 2 } );
  999. assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
  1000. [ '00' ],
  1001. [ '12' ],
  1002. [ '22' ]
  1003. ] ) );
  1004. } );
  1005. } );
  1006. } );
  1007. } );