tableediting.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  8. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  9. import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
  10. import TableEditing from '../src/tableediting';
  11. import { modelTable } from './_utils/utils';
  12. import InsertRowCommand from '../src/commands/insertrowcommand';
  13. import InsertTableCommand from '../src/commands/inserttablecommand';
  14. import InsertColumnCommand from '../src/commands/insertcolumncommand';
  15. import RemoveRowCommand from '../src/commands/removerowcommand';
  16. import RemoveColumnCommand from '../src/commands/removecolumncommand';
  17. import SplitCellCommand from '../src/commands/splitcellcommand';
  18. import MergeCellCommand from '../src/commands/mergecellcommand';
  19. import SetHeaderRowCommand from '../src/commands/setheaderrowcommand';
  20. import SetHeaderColumnCommand from '../src/commands/setheadercolumncommand';
  21. import MediaEmbedEditing from '@ckeditor/ckeditor5-media-embed/src/mediaembedediting';
  22. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  23. describe( 'TableEditing', () => {
  24. let editor, model;
  25. beforeEach( () => {
  26. return VirtualTestEditor
  27. .create( {
  28. plugins: [ TableEditing, Paragraph, ImageEditing, MediaEmbedEditing ]
  29. } )
  30. .then( newEditor => {
  31. editor = newEditor;
  32. model = editor.model;
  33. } );
  34. } );
  35. afterEach( () => {
  36. editor.destroy();
  37. } );
  38. it( 'should have pluginName', () => {
  39. expect( TableEditing.pluginName ).to.equal( 'TableEditing' );
  40. } );
  41. it( 'should set proper schema rules', () => {
  42. // Table:
  43. expect( model.schema.isRegistered( 'table' ) ).to.be.true;
  44. expect( model.schema.isObject( 'table' ) ).to.be.true;
  45. expect( model.schema.isBlock( 'table' ) ).to.be.true;
  46. expect( model.schema.isLimit( 'table' ) ).to.be.true;
  47. expect( model.schema.checkChild( [ '$root' ], 'table' ) ).to.be.true;
  48. expect( model.schema.checkAttribute( [ '$root', 'table' ], 'headingRows' ) ).to.be.true;
  49. expect( model.schema.checkAttribute( [ '$root', 'table' ], 'headingColumns' ) ).to.be.true;
  50. // Table row:
  51. expect( model.schema.isRegistered( 'tableRow' ) ).to.be.true;
  52. expect( model.schema.isLimit( 'tableRow' ) ).to.be.true;
  53. expect( model.schema.checkChild( [ '$root' ], 'tableRow' ) ).to.be.false;
  54. expect( model.schema.checkChild( [ 'table' ], 'tableRow' ) ).to.be.true;
  55. // Table cell:
  56. expect( model.schema.isRegistered( 'tableCell' ) ).to.be.true;
  57. expect( model.schema.isLimit( 'tableCell' ) ).to.be.true;
  58. expect( model.schema.checkChild( [ '$root' ], 'tableCell' ) ).to.be.false;
  59. expect( model.schema.checkChild( [ 'table' ], 'tableCell' ) ).to.be.false;
  60. expect( model.schema.checkChild( [ 'tableRow' ], 'tableCell' ) ).to.be.true;
  61. expect( model.schema.checkChild( [ 'tableCell' ], 'tableCell' ) ).to.be.false;
  62. expect( model.schema.checkAttribute( [ 'tableCell' ], 'colspan' ) ).to.be.true;
  63. expect( model.schema.checkAttribute( [ 'tableCell' ], 'rowspan' ) ).to.be.true;
  64. // Table cell contents:
  65. expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], '$text' ) ).to.be.false;
  66. expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], '$block' ) ).to.be.true;
  67. expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], 'table' ) ).to.be.false;
  68. expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], 'image' ) ).to.be.true;
  69. } );
  70. it( 'adds insertTable command', () => {
  71. expect( editor.commands.get( 'insertTable' ) ).to.be.instanceOf( InsertTableCommand );
  72. } );
  73. it( 'adds insertRowAbove command', () => {
  74. expect( editor.commands.get( 'insertTableRowAbove' ) ).to.be.instanceOf( InsertRowCommand );
  75. } );
  76. it( 'adds insertRowBelow command', () => {
  77. expect( editor.commands.get( 'insertTableRowBelow' ) ).to.be.instanceOf( InsertRowCommand );
  78. } );
  79. it( 'adds insertColumnLeft command', () => {
  80. expect( editor.commands.get( 'insertTableColumnLeft' ) ).to.be.instanceOf( InsertColumnCommand );
  81. } );
  82. it( 'adds insertColumnRight command', () => {
  83. expect( editor.commands.get( 'insertTableColumnRight' ) ).to.be.instanceOf( InsertColumnCommand );
  84. } );
  85. it( 'adds removeRow command', () => {
  86. expect( editor.commands.get( 'removeTableRow' ) ).to.be.instanceOf( RemoveRowCommand );
  87. } );
  88. it( 'adds removeColumn command', () => {
  89. expect( editor.commands.get( 'removeTableColumn' ) ).to.be.instanceOf( RemoveColumnCommand );
  90. } );
  91. it( 'adds splitCellVertically command', () => {
  92. expect( editor.commands.get( 'splitTableCellVertically' ) ).to.be.instanceOf( SplitCellCommand );
  93. } );
  94. it( 'adds splitCellHorizontally command', () => {
  95. expect( editor.commands.get( 'splitTableCellHorizontally' ) ).to.be.instanceOf( SplitCellCommand );
  96. } );
  97. it( 'adds mergeCellRight command', () => {
  98. expect( editor.commands.get( 'mergeTableCellRight' ) ).to.be.instanceOf( MergeCellCommand );
  99. } );
  100. it( 'adds mergeCellLeft command', () => {
  101. expect( editor.commands.get( 'mergeTableCellLeft' ) ).to.be.instanceOf( MergeCellCommand );
  102. } );
  103. it( 'adds mergeCellDown command', () => {
  104. expect( editor.commands.get( 'mergeTableCellDown' ) ).to.be.instanceOf( MergeCellCommand );
  105. } );
  106. it( 'adds mergeCellUp command', () => {
  107. expect( editor.commands.get( 'mergeTableCellUp' ) ).to.be.instanceOf( MergeCellCommand );
  108. } );
  109. it( 'adds setColumnHeader command', () => {
  110. expect( editor.commands.get( 'setTableColumnHeader' ) ).to.be.instanceOf( SetHeaderColumnCommand );
  111. } );
  112. it( 'adds setRowHeader command', () => {
  113. expect( editor.commands.get( 'setTableRowHeader' ) ).to.be.instanceOf( SetHeaderRowCommand );
  114. } );
  115. describe( 'conversion in data pipeline', () => {
  116. describe( 'model to view', () => {
  117. it( 'should create tbody section', () => {
  118. setModelData( model, '<table><tableRow><tableCell><paragraph>foo[]</paragraph></tableCell></tableRow></table>' );
  119. expect( editor.getData() ).to.equal(
  120. '<figure class="table">' +
  121. '<table>' +
  122. '<tbody>' +
  123. '<tr><td>foo</td></tr>' +
  124. '</tbody>' +
  125. '</table>' +
  126. '</figure>'
  127. );
  128. } );
  129. it( 'should create thead section', () => {
  130. setModelData(
  131. model,
  132. '<table headingRows="1"><tableRow><tableCell><paragraph>foo[]</paragraph></tableCell></tableRow></table>'
  133. );
  134. expect( editor.getData() ).to.equal(
  135. '<figure class="table">' +
  136. '<table>' +
  137. '<thead>' +
  138. '<tr><th>foo</th></tr>' +
  139. '</thead>' +
  140. '</table>' +
  141. '</figure>'
  142. );
  143. } );
  144. } );
  145. describe( 'view to model', () => {
  146. it( 'should convert table', () => {
  147. editor.setData( '<table><tbody><tr><td>foo</td></tr></tbody></table>' );
  148. expect( getModelData( model, { withoutSelection: true } ) )
  149. .to.equal( '<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>' );
  150. } );
  151. it( 'should convert table with image', () => {
  152. editor.setData( '<table><tbody><tr><td><img src="sample.png"></td></tr></tbody></table>' );
  153. expect( getModelData( model, { withoutSelection: true } ) )
  154. .to.equal( '<table><tableRow><tableCell><image src="sample.png"></image></tableCell></tableRow></table>' );
  155. } );
  156. it( 'should insert a paragraph when the cell content is unsupported', () => {
  157. editor.setData(
  158. '<table><tbody><tr><td><foo></foo></td></tr></tbody></table>'
  159. );
  160. expect( getModelData( model, { withoutSelection: true } ) )
  161. .to.equal( '<table><tableRow><tableCell><paragraph></paragraph></tableCell></tableRow></table>' );
  162. } );
  163. it( 'should convert a table with media', () => {
  164. editor.setData(
  165. '<table><tbody><tr><td><oembed url="https://www.youtube.com/watch?v=H08tGjXNHO4"></oembed></td></tr></tbody></table>'
  166. );
  167. expect( getModelData( model, { withoutSelection: true } ) )
  168. .to.equal( '<table><tableRow><tableCell>' +
  169. '<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>' +
  170. '</tableCell></tableRow></table>' );
  171. } );
  172. } );
  173. } );
  174. describe( 'caret movement', () => {
  175. let domEvtDataStub;
  176. beforeEach( () => {
  177. domEvtDataStub = {
  178. keyCode: getCode( 'Tab' ),
  179. preventDefault: sinon.spy(),
  180. stopPropagation: sinon.spy()
  181. };
  182. } );
  183. it( 'should do nothing if not tab pressed', () => {
  184. setModelData( model, modelTable( [
  185. [ '11', '12[]' ]
  186. ] ) );
  187. domEvtDataStub.keyCode = getCode( 'a' );
  188. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  189. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  190. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  191. assertEqualMarkup( getModelData( model ), modelTable( [
  192. [ '11', '12[]' ]
  193. ] ) );
  194. } );
  195. it( 'should do nothing if Ctrl+Tab is pressed', () => {
  196. setModelData( model, modelTable( [
  197. [ '11', '12[]' ]
  198. ] ) );
  199. domEvtDataStub.ctrlKey = true;
  200. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  201. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  202. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  203. assertEqualMarkup( getModelData( model ), modelTable( [
  204. [ '11', '12[]' ]
  205. ] ) );
  206. } );
  207. describe( 'on TAB', () => {
  208. it( 'should do nothing if selection is not in a table', () => {
  209. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [ [ '11', '12' ] ] ) );
  210. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  211. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  212. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  213. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  214. [ '11', '12' ]
  215. ] ) );
  216. } );
  217. it( 'should move to next cell', () => {
  218. setModelData( model, modelTable( [
  219. [ '11[]', '12' ]
  220. ] ) );
  221. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  222. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  223. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  224. assertEqualMarkup( getModelData( model ), modelTable( [
  225. [ '11', '[12]' ]
  226. ] ) );
  227. } );
  228. it( 'should create another row and move to first cell in new row', () => {
  229. setModelData( model, modelTable( [
  230. [ '11', '[12]' ]
  231. ] ) );
  232. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  233. assertEqualMarkup( getModelData( model ), modelTable( [
  234. [ '11', '12' ],
  235. [ '[]', '' ]
  236. ] ) );
  237. } );
  238. it( 'should not create another row and not move the caret if insertTableRowBelow command is disabled', () => {
  239. setModelData( model, modelTable( [
  240. [ '11', '12[]' ]
  241. ] ) );
  242. const insertTableRowBelowCommand = editor.commands.get( 'insertTableRowBelow' );
  243. insertTableRowBelowCommand.forceDisabled( 'test' );
  244. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  245. assertEqualMarkup( getModelData( model ), modelTable( [
  246. [ '11', '12[]' ]
  247. ] ) );
  248. } );
  249. it( 'should move to the first cell of next row if on end of a row', () => {
  250. setModelData( model, modelTable( [
  251. [ '11', '12[]' ],
  252. [ '21', '22' ]
  253. ] ) );
  254. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  255. assertEqualMarkup( getModelData( model ), modelTable( [
  256. [ '11', '12' ],
  257. [ '[21]', '22' ]
  258. ] ) );
  259. } );
  260. it( 'should move to the next table cell if part of block content is selected', () => {
  261. setModelData( model, modelTable( [
  262. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  263. ] ) );
  264. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  265. assertEqualMarkup( getModelData( model ), modelTable( [
  266. [
  267. '11',
  268. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  269. '[13]'
  270. ]
  271. ] ) );
  272. } );
  273. it( 'should move to next cell with an image', () => {
  274. setModelData( model, modelTable( [
  275. [ '11[]', '<paragraph>foo</paragraph><image></image>' ]
  276. ] ) );
  277. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  278. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  279. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  280. assertEqualMarkup( getModelData( model ), modelTable( [
  281. [ '11', '<paragraph>[foo</paragraph><image></image>]' ]
  282. ] ) );
  283. } );
  284. it( 'should move to next cell with an blockQuote', () => {
  285. model.schema.register( 'blockQuote', {
  286. allowWhere: '$block',
  287. allowContentOf: '$root'
  288. } );
  289. editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
  290. setModelData( model, modelTable( [
  291. [ '11[]', '<blockQuote><paragraph>foo</paragraph></blockQuote>' ]
  292. ] ) );
  293. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  294. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  295. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  296. assertEqualMarkup( getModelData( model ), modelTable( [
  297. [ '11', '<blockQuote><paragraph>[foo]</paragraph></blockQuote>' ]
  298. ] ) );
  299. } );
  300. it( 'should listen with lower priority then its children', () => {
  301. // Cancel TAB event.
  302. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() );
  303. setModelData( model, modelTable( [
  304. [ '11[]', '12' ]
  305. ] ) );
  306. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  307. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  308. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  309. assertEqualMarkup( getModelData( model ), modelTable( [
  310. [ '11[]', '12' ]
  311. ] ) );
  312. } );
  313. describe( 'on table widget selected', () => {
  314. beforeEach( () => {
  315. editor.model.schema.register( 'block', {
  316. allowWhere: '$block',
  317. allowContentOf: '$block',
  318. isObject: true
  319. } );
  320. editor.conversion.elementToElement( { model: 'block', view: 'block' } );
  321. } );
  322. it( 'should move caret to the first table cell on TAB', () => {
  323. const spy = sinon.spy();
  324. editor.keystrokes.set( 'Tab', spy, { priority: 'lowest' } );
  325. setModelData( model, '[' + modelTable( [
  326. [ '11', '12' ]
  327. ] ) + ']' );
  328. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  329. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  330. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  331. assertEqualMarkup( getModelData( model ), modelTable( [
  332. [ '[11]', '12' ]
  333. ] ) );
  334. // Should cancel event - so no other tab handler is called.
  335. sinon.assert.notCalled( spy );
  336. } );
  337. it( 'shouldn\'t do anything on other blocks', () => {
  338. const spy = sinon.spy();
  339. editor.editing.view.document.on( 'keydown', spy );
  340. setModelData( model, '[<block>foo</block>]' );
  341. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  342. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  343. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  344. assertEqualMarkup( getModelData( model ), '[<block>foo</block>]' );
  345. // Should not cancel event.
  346. sinon.assert.calledOnce( spy );
  347. } );
  348. } );
  349. } );
  350. describe( 'on SHIFT+TAB', () => {
  351. beforeEach( () => {
  352. domEvtDataStub.shiftKey = true;
  353. } );
  354. it( 'should do nothing if selection is not in a table', () => {
  355. setModelData( model, '<paragraph>[]</paragraph>' + modelTable( [
  356. [ '11', '12' ]
  357. ] ) );
  358. domEvtDataStub.keyCode = getCode( 'Tab' );
  359. domEvtDataStub.shiftKey = true;
  360. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  361. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  362. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  363. assertEqualMarkup( getModelData( model ), '<paragraph>[]</paragraph>' + modelTable( [
  364. [ '11', '12' ]
  365. ] ) );
  366. } );
  367. it( 'should move to previous cell', () => {
  368. setModelData( model, modelTable( [
  369. [ '11', '12[]' ]
  370. ] ) );
  371. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  372. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  373. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  374. assertEqualMarkup( getModelData( model ), modelTable( [
  375. [ '[11]', '12' ]
  376. ] ) );
  377. } );
  378. it( 'should not move if caret is in first table cell', () => {
  379. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  380. [ '[]11', '12' ]
  381. ] ) );
  382. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  383. assertEqualMarkup( getModelData( model ),
  384. '<paragraph>foo</paragraph>' + modelTable( [ [ '[]11', '12' ] ] )
  385. );
  386. } );
  387. it( 'should move to the last cell of previous row if on beginning of a row', () => {
  388. setModelData( model, modelTable( [
  389. [ '11', '12' ],
  390. [ '[]21', '22' ]
  391. ] ) );
  392. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  393. assertEqualMarkup( getModelData( model ), modelTable( [
  394. [ '11', '[12]' ],
  395. [ '21', '22' ]
  396. ] ) );
  397. } );
  398. it( 'should move to the previous table cell if part of block content is selected', () => {
  399. setModelData( model, modelTable( [
  400. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  401. ] ) );
  402. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  403. assertEqualMarkup( getModelData( model ), modelTable( [
  404. [
  405. '[11]',
  406. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  407. '13'
  408. ]
  409. ] ) );
  410. } );
  411. it( 'should move to previous cell with an image', () => {
  412. setModelData( model, modelTable( [
  413. [ '<paragraph>foo</paragraph><image></image>', 'bar[]' ]
  414. ] ) );
  415. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  416. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  417. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  418. assertEqualMarkup( getModelData( model ), modelTable( [
  419. [ '<paragraph>[foo</paragraph><image></image>]', 'bar' ]
  420. ] ) );
  421. } );
  422. } );
  423. } );
  424. describe( 'enter key', () => {
  425. let evtDataStub, viewDocument;
  426. beforeEach( () => {
  427. evtDataStub = {
  428. preventDefault: sinon.spy(),
  429. stopPropagation: sinon.spy(),
  430. isSoft: false
  431. };
  432. return VirtualTestEditor
  433. .create( {
  434. plugins: [ TableEditing, Paragraph ]
  435. } )
  436. .then( newEditor => {
  437. editor = newEditor;
  438. sinon.stub( editor, 'execute' );
  439. viewDocument = editor.editing.view.document;
  440. model = editor.model;
  441. } );
  442. } );
  443. it( 'should do nothing if not in table cell', () => {
  444. setModelData( model, '<paragraph>[]foo</paragraph>' );
  445. viewDocument.fire( 'enter', evtDataStub );
  446. sinon.assert.notCalled( editor.execute );
  447. assertEqualMarkup( getModelData( model ), '<paragraph>[]foo</paragraph>' );
  448. } );
  449. it( 'should do nothing if table cell has already a block content', () => {
  450. setModelData( model, modelTable( [
  451. [ '<paragraph>[]11</paragraph>' ]
  452. ] ) );
  453. viewDocument.fire( 'enter', evtDataStub );
  454. sinon.assert.notCalled( editor.execute );
  455. assertEqualMarkup( getModelData( model ), modelTable( [
  456. [ '<paragraph>[]11</paragraph>' ]
  457. ] ) );
  458. } );
  459. it( 'should do nothing if table cell with a block content is selected as a whole', () => {
  460. setModelData( model, modelTable( [
  461. [ '<paragraph>[1</paragraph><paragraph>1]</paragraph>' ]
  462. ] ) );
  463. viewDocument.fire( 'enter', evtDataStub );
  464. sinon.assert.notCalled( editor.execute );
  465. setModelData( model, modelTable( [
  466. [ '<paragraph>[1</paragraph><paragraph>1]</paragraph>' ]
  467. ] ) );
  468. } );
  469. it( 'should allow default behavior of Shift+Enter pressed', () => {
  470. setModelData( model, modelTable( [
  471. [ '[]11' ]
  472. ] ) );
  473. evtDataStub.isSoft = true;
  474. viewDocument.fire( 'enter', evtDataStub );
  475. sinon.assert.notCalled( editor.execute );
  476. assertEqualMarkup( getModelData( model ), modelTable( [
  477. [ '[]11' ]
  478. ] ) );
  479. } );
  480. } );
  481. } );