Browse Source

Tests: Added a test for #6265.

Piotrek Koszuliński 5 years ago
parent
commit
698e2d877a

+ 42 - 0
packages/ckeditor5-table/tests/tableproperties/tablepropertiesediting-integration.js

@@ -10,7 +10,11 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
 import TableEditing from '../../src/tableediting';
 import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting';
 
+import TableCellPropertiesEditing from '../../src/tablecellproperties/tablecellpropertiesediting';
+
 import AlignmentEditing from '@ckeditor/ckeditor5-alignment/src/alignmentediting';
+import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
+
 import { assertTableStyle } from '../_utils/utils';
 
 describe( 'table properties', () => {
@@ -39,6 +43,44 @@ describe( 'table properties', () => {
 			} );
 		} );
 
+		describe( 'Undo', () => {
+			let table;
+
+			beforeEach( async () => {
+				editor = await createEditorWithAdditionalPlugins( [ UndoEditing, TableCellPropertiesEditing ] );
+
+				model = editor.model;
+
+				table = createEmptyTable();
+			} );
+
+			// See https://github.com/ckeditor/ckeditor5/issues/6265.
+			it( 'should correctly undo setting table and then cell style', () => {
+				const firstCell = table.getChild( 0 ).getChild( 0 );
+
+				editor.model.change( writer => {
+					writer.setSelection( firstCell, 0 );
+				} );
+
+				editor.execute( 'tableBackgroundColor', { value: 'red' } );
+
+				editor.execute( 'tableCellBackgroundColor', { value: 'green' } );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.equal( 'green' );
+
+				editor.execute( 'undo' );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+
+				editor.execute( 'undo' );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+			} );
+		} );
+
 		function createEmptyTable() {
 			setModelData(
 				model,