tableediting.js 20 KB

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