tablecolumnrowproperties.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 TableEditing from '../src/tableediting';
  8. import TableColumnRowProperties from '../src/tablecolumnrowproperties';
  9. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  11. describe( 'TableColumnRowProperties', () => {
  12. let editor, model;
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ TableColumnRowProperties, Paragraph, TableEditing ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. model = editor.model;
  21. } );
  22. } );
  23. afterEach( () => {
  24. editor.destroy();
  25. } );
  26. it( 'should have pluginName', () => {
  27. expect( TableColumnRowProperties.pluginName ).to.equal( 'TableColumnRowProperties' );
  28. } );
  29. describe( 'column width', () => {
  30. it( 'should set proper schema rules', () => {
  31. expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'width' ) ).to.be.true;
  32. } );
  33. describe( 'upcast conversion', () => {
  34. it( 'should upcast width attribute on table cell', () => {
  35. editor.setData( '<table><tr><td style="width:20px">foo</td></tr></table>' );
  36. const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  37. expect( tableCell.getAttribute( 'width' ) ).to.equal( '20px' );
  38. } );
  39. } );
  40. describe( 'downcast conversion', () => {
  41. let tableCell;
  42. beforeEach( () => {
  43. setModelData(
  44. model,
  45. '<table headingRows="0" headingColumns="0">' +
  46. '<tableRow>' +
  47. '<tableCell>' +
  48. '<paragraph>foo</paragraph>' +
  49. '</tableCell>' +
  50. '</tableRow>' +
  51. '</table>'
  52. );
  53. tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  54. } );
  55. it( 'should downcast width attribute', () => {
  56. model.change( writer => writer.setAttribute( 'width', '20px', tableCell ) );
  57. assertEqualMarkup(
  58. editor.getData(),
  59. '<figure class="table"><table><tbody><tr><td style="width:20px;">foo</td></tr></tbody></table></figure>'
  60. );
  61. } );
  62. } );
  63. } );
  64. describe( 'row height', () => {
  65. it( 'should set proper schema rules', () => {
  66. expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'height' ) ).to.be.true;
  67. } );
  68. describe( 'upcast conversion', () => {
  69. it( 'should upcast height attribute on table cell', () => {
  70. editor.setData( '<table><tr><td style="height:20px">foo</td></tr></table>' );
  71. const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  72. expect( tableCell.getAttribute( 'height' ) ).to.equal( '20px' );
  73. } );
  74. } );
  75. describe( 'downcast conversion', () => {
  76. let tableCell;
  77. beforeEach( () => {
  78. setModelData(
  79. model,
  80. '<table headingRows="0" headingColumns="0">' +
  81. '<tableRow>' +
  82. '<tableCell>' +
  83. '<paragraph>foo</paragraph>' +
  84. '</tableCell>' +
  85. '</tableRow>' +
  86. '</table>'
  87. );
  88. tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
  89. } );
  90. it( 'should downcast height attribute', () => {
  91. model.change( writer => writer.setAttribute( 'height', '20px', tableCell ) );
  92. assertEqualMarkup(
  93. editor.getData(),
  94. '<figure class="table"><table><tbody><tr><td style="height:20px;">foo</td></tr></tbody></table></figure>'
  95. );
  96. } );
  97. } );
  98. } );
  99. } );