tableediting.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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 TableEditing from '../src/tableediting';
  9. describe( 'TableEditing', () => {
  10. let editor, model;
  11. beforeEach( () => {
  12. return VirtualTestEditor
  13. .create( {
  14. plugins: [ TableEditing, Paragraph ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. model = editor.model;
  19. } );
  20. } );
  21. afterEach( () => {
  22. editor.destroy();
  23. } );
  24. it( 'should set proper schema rules', () => {
  25. } );
  26. describe( 'conversion in data pipeline', () => {
  27. describe( 'model to view', () => {
  28. it( 'should create tbody section', () => {
  29. setModelData( model, '<table><tableRow><tableCell>foo[]</tableCell></tableRow></table>' );
  30. expect( editor.getData() ).to.equal( '<table><tbody><tr><td>foo</td></tr></tbody></table>' );
  31. } );
  32. it( 'should create thead section', () => {
  33. setModelData( model, '<table headingRows="1"><tableRow><tableCell>foo[]</tableCell></tableRow></table>' );
  34. expect( editor.getData() ).to.equal( '<table><thead><tr><th>foo</th></tr></thead></table>' );
  35. } );
  36. it( 'should create thead and tbody sections in proper order', () => {
  37. setModelData( model, '<table headingRows="1">' +
  38. '<tableRow><tableCell>foo</tableCell></tableRow>' +
  39. '<tableRow><tableCell>bar</tableCell></tableRow>' +
  40. '<tableRow><tableCell>baz[]</tableCell></tableRow>' +
  41. '</table>'
  42. );
  43. expect( editor.getData() ).to.equal( '<table>' +
  44. '<thead><tr><th>foo</th></tr></thead>' +
  45. '<tbody><tr><td>bar</td></tr><tr><td>baz</td></tr></tbody>' +
  46. '</table>'
  47. );
  48. } );
  49. it( 'should convert rowspan on tableCell', () => {
  50. setModelData( model, '<table><tableRow><tableCell rowspan="2">foo[]</tableCell></tableRow></table>' );
  51. expect( editor.getData() ).to.equal( '<table><tbody><tr><td rowspan="2">foo</td></tr></tbody></table>' );
  52. } );
  53. it( 'should convert colspan on tableCell', () => {
  54. setModelData( model, '<table><tableRow><tableCell colspan="2">foo[]</tableCell></tableRow></table>' );
  55. expect( editor.getData() ).to.equal( '<table><tbody><tr><td colspan="2">foo</td></tr></tbody></table>' );
  56. } );
  57. } );
  58. describe( 'view to model', () => {
  59. it( 'should convert table', () => {
  60. editor.setData( '<table><tbody><tr><td>foo</td></tr></tbody></table>' );
  61. expect( getModelData( model, { withoutSelection: true } ) )
  62. .to.equal( '<table><tableRow><tableCell>foo</tableCell></tableRow></table>' );
  63. } );
  64. } );
  65. } );
  66. } );