tablesediting.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import TablesEditing from '../src/tablesediting';
  6. import Paragraph from '../../ckeditor5-paragraph/src/paragraph';
  7. import VirtualTestEditor from '../../ckeditor5-core/tests/_utils/virtualtesteditor';
  8. import { getData as getModelData, setData as setModelData } from '../../ckeditor5-engine/src/dev-utils/model';
  9. describe( 'TablesEditing', () => {
  10. let editor, model;
  11. beforeEach( () => {
  12. return VirtualTestEditor
  13. .create( {
  14. plugins: [ TablesEditing, 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 tfoot section', () => {
  33. setModelData( model, '<table><tableRow isFooter="true"><tableCell>foo[]</tableCell></tableRow></table>' );
  34. expect( editor.getData() ).to.equal( '<table><tfoot><tr><td>foo</td></tr></tfoot></table>' );
  35. } );
  36. it( 'should create thead section', () => {
  37. setModelData( model, '<table><tableRow isHeading="true"><tableCell>foo[]</tableCell></tableRow></table>' );
  38. expect( editor.getData() ).to.equal( '<table><thead><tr><td>foo</td></tr></thead></table>' );
  39. } );
  40. it( 'should create thead, tbody and tfoot sections in proper order', () => {
  41. setModelData( model, '<table>' +
  42. '<tableRow><tableCell>foo[]</tableCell></tableRow>' +
  43. '<tableRow isFooter="true"><tableCell>foo[]</tableCell></tableRow>' +
  44. '<tableRow isHeading="true"><tableCell>foo[]</tableCell></tableRow>' +
  45. '</table>'
  46. );
  47. expect( editor.getData() ).to.equal( '<table>' +
  48. '<thead><tr><td>foo</td></tr></thead>' +
  49. '<tbody><tr><td>foo</td></tr></tbody>' +
  50. '<tfoot><tr><td>foo</td></tr></tfoot>' +
  51. '</table>'
  52. );
  53. } );
  54. it( 'should create th element for tableCell with attribute isHeading=true', () => {
  55. setModelData( model, '<table><tableRow isHeading="true"><tableCell isHeading="true">foo[]</tableCell></tableRow></table>' );
  56. expect( editor.getData() ).to.equal( '<table><thead><tr><th>foo</th></tr></thead></table>' );
  57. } );
  58. it( 'should convert rowspan on tableCell', () => {
  59. setModelData( model, '<table><tableRow><tableCell rowspan="2">foo[]</tableCell></tableRow></table>' );
  60. expect( editor.getData() ).to.equal( '<table><tbody><tr><td rowspan="2">foo</td></tr></tbody></table>' );
  61. } );
  62. it( 'should convert colspan on tableCell', () => {
  63. setModelData( model, '<table><tableRow><tableCell colspan="2">foo[]</tableCell></tableRow></table>' );
  64. expect( editor.getData() ).to.equal( '<table><tbody><tr><td colspan="2">foo</td></tr></tbody></table>' );
  65. } );
  66. } );
  67. describe( 'view to model', () => {
  68. it( 'should convert image figure', () => {
  69. editor.setData( '<table><tbody><tr><td>foo</td></tr></tbody></table>' );
  70. expect( getModelData( model, { withoutSelection: true } ) )
  71. .to.equal( '<table><tableRow><tableCell>foo</tableCell></tableRow></table>' );
  72. } );
  73. } );
  74. } );
  75. } );