8
0

tablepropertiesediting-integration.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  8. import TableEditing from '../../src/tableediting';
  9. import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting';
  10. import TableCellPropertiesEditing from '../../src/tablecellproperties/tablecellpropertiesediting';
  11. import AlignmentEditing from '@ckeditor/ckeditor5-alignment/src/alignmentediting';
  12. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  13. import { assertTableStyle } from '../_utils/utils';
  14. describe( 'table properties', () => {
  15. describe( 'TablePropertiesEditing integration', () => {
  16. let editor, model;
  17. afterEach( async () => {
  18. await editor.destroy();
  19. } );
  20. describe( 'Alignment', () => {
  21. let table;
  22. beforeEach( async () => {
  23. editor = await createEditorWithAdditionalPlugins( [ AlignmentEditing ] );
  24. model = editor.model;
  25. table = createEmptyTable();
  26. } );
  27. it( 'should properly downcast table with Alignment plugin enabled', () => {
  28. model.change( writer => writer.setAttribute( 'alignment', 'right', table ) );
  29. assertTableStyle( editor, null, 'float:right;' );
  30. } );
  31. } );
  32. describe( 'Undo', () => {
  33. let table;
  34. beforeEach( async () => {
  35. editor = await createEditorWithAdditionalPlugins( [ UndoEditing, TableCellPropertiesEditing ] );
  36. model = editor.model;
  37. table = createEmptyTable();
  38. } );
  39. // See https://github.com/ckeditor/ckeditor5/issues/6265.
  40. it( 'should correctly undo setting table and then cell style', () => {
  41. const firstCell = table.getChild( 0 ).getChild( 0 );
  42. editor.model.change( writer => {
  43. writer.setSelection( firstCell, 0 );
  44. } );
  45. editor.execute( 'tableBackgroundColor', { value: 'red' } );
  46. editor.execute( 'tableCellBackgroundColor', { value: 'green' } );
  47. expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
  48. expect( firstCell.getAttribute( 'backgroundColor' ) ).to.equal( 'green' );
  49. editor.execute( 'undo' );
  50. expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
  51. expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
  52. editor.execute( 'undo' );
  53. expect( table.getAttribute( 'backgroundColor' ) ).to.be.undefined;
  54. expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
  55. } );
  56. } );
  57. function createEmptyTable() {
  58. setModelData(
  59. model,
  60. '<table headingRows="0" headingColumns="0">' +
  61. '<tableRow>' +
  62. '<tableCell>' +
  63. '<paragraph>foo</paragraph>' +
  64. '</tableCell>' +
  65. '</tableRow>' +
  66. '</table>'
  67. );
  68. return model.document.getRoot().getNodeByPath( [ 0 ] );
  69. }
  70. } );
  71. function createEditorWithAdditionalPlugins( plugins ) {
  72. return VirtualTestEditor.create( {
  73. plugins: [ ...plugins, TablePropertiesEditing, Paragraph, TableEditing ]
  74. } );
  75. }
  76. } );