tableediting.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 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, '[]' + modelTable( [
  210. [ '11', '12' ]
  211. ] ) );
  212. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  213. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  214. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  215. assertEqualMarkup( getModelData( model ), '[]' + modelTable( [
  216. [ '11', '12' ]
  217. ] ) );
  218. } );
  219. it( 'should move to next cell', () => {
  220. setModelData( model, modelTable( [
  221. [ '11[]', '12' ]
  222. ] ) );
  223. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  224. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  225. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  226. assertEqualMarkup( getModelData( model ), modelTable( [
  227. [ '11', '[12]' ]
  228. ] ) );
  229. } );
  230. it( 'should create another row and move to first cell in new row', () => {
  231. setModelData( model, modelTable( [
  232. [ '11', '[12]' ]
  233. ] ) );
  234. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  235. assertEqualMarkup( getModelData( model ), modelTable( [
  236. [ '11', '12' ],
  237. [ '[]', '' ]
  238. ] ) );
  239. } );
  240. it( 'should not create another row and not move the caret if insertTableRowBelow command is disabled', () => {
  241. setModelData( model, modelTable( [
  242. [ '11', '12[]' ]
  243. ] ) );
  244. const insertTableRowBelowCommand = editor.commands.get( 'insertTableRowBelow' );
  245. insertTableRowBelowCommand.forceDisabled( 'test' );
  246. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  247. assertEqualMarkup( getModelData( model ), modelTable( [
  248. [ '11', '12[]' ]
  249. ] ) );
  250. } );
  251. it( 'should move to the first cell of next row if on end of a row', () => {
  252. setModelData( model, modelTable( [
  253. [ '11', '12[]' ],
  254. [ '21', '22' ]
  255. ] ) );
  256. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  257. assertEqualMarkup( getModelData( model ), modelTable( [
  258. [ '11', '12' ],
  259. [ '[21]', '22' ]
  260. ] ) );
  261. } );
  262. it( 'should move to the next table cell if part of block content is selected', () => {
  263. setModelData( model, modelTable( [
  264. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  265. ] ) );
  266. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  267. assertEqualMarkup( getModelData( model ), modelTable( [
  268. [
  269. '11',
  270. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  271. '[13]'
  272. ]
  273. ] ) );
  274. } );
  275. it( 'should move to next cell with an image', () => {
  276. setModelData( model, modelTable( [
  277. [ '11[]', '<paragraph>foo</paragraph><image></image>' ]
  278. ] ) );
  279. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  280. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  281. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  282. assertEqualMarkup( getModelData( model ), modelTable( [
  283. [ '11', '<paragraph>[foo</paragraph><image></image>]' ]
  284. ] ) );
  285. } );
  286. it( 'should move to next cell with an blockQuote', () => {
  287. model.schema.register( 'blockQuote', {
  288. allowWhere: '$block',
  289. allowContentOf: '$root'
  290. } );
  291. editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } );
  292. setModelData( model, modelTable( [
  293. [ '11[]', '<blockQuote><paragraph>foo</paragraph></blockQuote>' ]
  294. ] ) );
  295. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  296. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  297. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  298. assertEqualMarkup( getModelData( model ), modelTable( [
  299. [ '11', '<blockQuote><paragraph>[foo]</paragraph></blockQuote>' ]
  300. ] ) );
  301. } );
  302. it( 'should listen with lower priority then its children', () => {
  303. // Cancel TAB event.
  304. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() );
  305. setModelData( model, modelTable( [
  306. [ '11[]', '12' ]
  307. ] ) );
  308. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  309. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  310. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  311. assertEqualMarkup( getModelData( model ), modelTable( [
  312. [ '11[]', '12' ]
  313. ] ) );
  314. } );
  315. describe( 'on table widget selected', () => {
  316. beforeEach( () => {
  317. editor.model.schema.register( 'block', {
  318. allowWhere: '$block',
  319. allowContentOf: '$block',
  320. isObject: true
  321. } );
  322. editor.conversion.elementToElement( { model: 'block', view: 'block' } );
  323. } );
  324. it( 'should move caret to the first table cell on TAB', () => {
  325. const spy = sinon.spy();
  326. editor.keystrokes.set( 'Tab', spy, { priority: 'lowest' } );
  327. setModelData( model, '[' + modelTable( [
  328. [ '11', '12' ]
  329. ] ) + ']' );
  330. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  331. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  332. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  333. assertEqualMarkup( getModelData( model ), modelTable( [
  334. [ '[11]', '12' ]
  335. ] ) );
  336. // Should cancel event - so no other tab handler is called.
  337. sinon.assert.notCalled( spy );
  338. } );
  339. it( 'shouldn\'t do anything on other blocks', () => {
  340. const spy = sinon.spy();
  341. editor.editing.view.document.on( 'keydown', spy );
  342. setModelData( model, '[<block>foo</block>]' );
  343. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  344. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  345. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  346. assertEqualMarkup( getModelData( model ), '[<block>foo</block>]' );
  347. // Should not cancel event.
  348. sinon.assert.calledOnce( spy );
  349. } );
  350. } );
  351. } );
  352. describe( 'on SHIFT+TAB', () => {
  353. beforeEach( () => {
  354. domEvtDataStub.shiftKey = true;
  355. } );
  356. it( 'should do nothing if selection is not in a table', () => {
  357. setModelData( model, '[]' + modelTable( [
  358. [ '11', '12' ]
  359. ] ) );
  360. domEvtDataStub.keyCode = getCode( 'Tab' );
  361. domEvtDataStub.shiftKey = true;
  362. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  363. sinon.assert.notCalled( domEvtDataStub.preventDefault );
  364. sinon.assert.notCalled( domEvtDataStub.stopPropagation );
  365. assertEqualMarkup( getModelData( model ), '[]' + modelTable( [
  366. [ '11', '12' ]
  367. ] ) );
  368. } );
  369. it( 'should move to previous cell', () => {
  370. setModelData( model, modelTable( [
  371. [ '11', '12[]' ]
  372. ] ) );
  373. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  374. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  375. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  376. assertEqualMarkup( getModelData( model ), modelTable( [
  377. [ '[11]', '12' ]
  378. ] ) );
  379. } );
  380. it( 'should not move if caret is in first table cell', () => {
  381. setModelData( model, '<paragraph>foo</paragraph>' + modelTable( [
  382. [ '[]11', '12' ]
  383. ] ) );
  384. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  385. assertEqualMarkup( getModelData( model ),
  386. '<paragraph>foo</paragraph>' + modelTable( [ [ '[]11', '12' ] ] )
  387. );
  388. } );
  389. it( 'should move to the last cell of previous row if on beginning of a row', () => {
  390. setModelData( model, modelTable( [
  391. [ '11', '12' ],
  392. [ '[]21', '22' ]
  393. ] ) );
  394. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  395. assertEqualMarkup( getModelData( model ), modelTable( [
  396. [ '11', '[12]' ],
  397. [ '21', '22' ]
  398. ] ) );
  399. } );
  400. it( 'should move to the previous table cell if part of block content is selected', () => {
  401. setModelData( model, modelTable( [
  402. [ '11', '<paragraph>12</paragraph><paragraph>[foo]</paragraph><paragraph>bar</paragraph>', '13' ]
  403. ] ) );
  404. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  405. assertEqualMarkup( getModelData( model ), modelTable( [
  406. [
  407. '[11]',
  408. '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
  409. '13'
  410. ]
  411. ] ) );
  412. } );
  413. it( 'should move to previous cell with an image', () => {
  414. setModelData( model, modelTable( [
  415. [ '<paragraph>foo</paragraph><image></image>', 'bar[]' ]
  416. ] ) );
  417. editor.editing.view.document.fire( 'keydown', domEvtDataStub );
  418. sinon.assert.calledOnce( domEvtDataStub.preventDefault );
  419. sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
  420. assertEqualMarkup( getModelData( model ), modelTable( [
  421. [ '<paragraph>[foo</paragraph><image></image>]', 'bar' ]
  422. ] ) );
  423. } );
  424. } );
  425. } );
  426. describe( 'enter key', () => {
  427. let evtDataStub, viewDocument;
  428. beforeEach( () => {
  429. evtDataStub = {
  430. preventDefault: sinon.spy(),
  431. stopPropagation: sinon.spy(),
  432. isSoft: false
  433. };
  434. return VirtualTestEditor
  435. .create( {
  436. plugins: [ TableEditing, Paragraph ]
  437. } )
  438. .then( newEditor => {
  439. editor = newEditor;
  440. sinon.stub( editor, 'execute' );
  441. viewDocument = editor.editing.view.document;
  442. model = editor.model;
  443. } );
  444. } );
  445. it( 'should do nothing if not in table cell', () => {
  446. setModelData( model, '<paragraph>[]foo</paragraph>' );
  447. viewDocument.fire( 'enter', evtDataStub );
  448. sinon.assert.notCalled( editor.execute );
  449. assertEqualMarkup( getModelData( model ), '<paragraph>[]foo</paragraph>' );
  450. } );
  451. it( 'should do nothing if table cell has already a block content', () => {
  452. setModelData( model, modelTable( [
  453. [ '<paragraph>[]11</paragraph>' ]
  454. ] ) );
  455. viewDocument.fire( 'enter', evtDataStub );
  456. sinon.assert.notCalled( editor.execute );
  457. assertEqualMarkup( getModelData( model ), modelTable( [
  458. [ '<paragraph>[]11</paragraph>' ]
  459. ] ) );
  460. } );
  461. it( 'should do nothing if table cell with a block content is selected as a whole', () => {
  462. setModelData( model, modelTable( [
  463. [ '<paragraph>[1</paragraph><paragraph>1]</paragraph>' ]
  464. ] ) );
  465. viewDocument.fire( 'enter', evtDataStub );
  466. sinon.assert.notCalled( editor.execute );
  467. setModelData( model, modelTable( [
  468. [ '<paragraph>[1</paragraph><paragraph>1]</paragraph>' ]
  469. ] ) );
  470. } );
  471. it( 'should allow default behavior of Shift+Enter pressed', () => {
  472. setModelData( model, modelTable( [
  473. [ '[]11' ]
  474. ] ) );
  475. evtDataStub.isSoft = true;
  476. viewDocument.fire( 'enter', evtDataStub );
  477. sinon.assert.notCalled( editor.execute );
  478. assertEqualMarkup( getModelData( model ), modelTable( [
  479. [ '[]11' ]
  480. ] ) );
  481. } );
  482. } );
  483. } );