8
0
Просмотр исходного кода

Add test cases for TableUtils#removeColumn().

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
3cbaaa312c
1 измененных файлов с 191 добавлено и 0 удалено
  1. 191 0
      packages/ckeditor5-table/tests/tableutils.js

+ 191 - 0
packages/ckeditor5-table/tests/tableutils.js

@@ -960,4 +960,195 @@ describe( 'TableUtils', () => {
 			} );
 			} );
 		} );
 		} );
 	} );
 	} );
+
+	describe( 'removeColumn()', () => {
+		describe( 'single row', () => {
+			it( 'should remove a given column', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02' ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 1 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00', '02' ],
+					[ '10', '12' ],
+					[ '20', '22' ]
+				] ) );
+			} );
+
+			it( 'should remove a given column from a table start', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ],
+					[ '10', '11' ],
+					[ '20', '21' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 0 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '01' ],
+					[ '11' ],
+					[ '21' ]
+				] ) );
+			} );
+
+			it( 'should change heading columns if removing a heading column', () => {
+				setData( model, modelTable( [
+					[ '00', '01' ],
+					[ '10', '11' ],
+					[ '20', '21' ]
+				], { headingColumns: 2 } ) );
+
+				tableUtils.removeColumn( { at: 0 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '01' ],
+					[ '11' ],
+					[ '21' ]
+				], { headingColumns: 1 } ) );
+			} );
+
+			it( 'should decrease colspan of table cells from previous column', () => {
+				setData( model, modelTable( [
+					[ { colspan: 4, contents: '00' }, '03' ],
+					[ { colspan: 3, contents: '10' }, '13' ],
+					[ { colspan: 2, contents: '20' }, '22', '23' ],
+					[ '30', { colspan: 2, contents: '31' }, '33' ],
+					[ '40', '41', '42', '43' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ { colspan: 3, contents: '00' }, '03' ],
+					[ { colspan: 2, contents: '10' }, '13' ],
+					[ { colspan: 2, contents: '20' }, '23' ],
+					[ '30', '31', '33' ],
+					[ '40', '41', '43' ]
+
+				] ) );
+			} );
+
+			it( 'should decrease colspan of cells that are on removed column', () => {
+				setData( model, modelTable( [
+					[ { colspan: 3, contents: '00' }, '03' ],
+					[ { colspan: 2, contents: '10' }, '13' ],
+					[ '20', '21', '22', '23' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 0 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ { colspan: 2, contents: '00' }, '03' ],
+					[ '10', '13' ],
+					[ '21', '22', '23' ]
+				] ) );
+			} );
+
+			it( 'should move focus to previous column of removed cell if in last column', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02' ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00', '01' ],
+					[ '10', '11' ],
+					[ '20', '21' ]
+				] ) );
+			} );
+		} );
+
+		describe( 'multiple columns', () => {
+			it( 'should properly remove two first columns', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02' ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ],
+					[ '30', '31', '32' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 0, columns: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '02' ],
+					[ '12' ],
+					[ '22' ],
+					[ '32' ]
+				] ) );
+			} );
+
+			it( 'should properly remove two middle columns', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02', '03' ],
+					[ '10', '11', '12', '13' ],
+					[ '20', '21', '22', '23' ],
+					[ '30', '31', '32', '33' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 1, columns: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00', '03' ],
+					[ '10', '13' ],
+					[ '20', '23' ],
+					[ '30', '33' ]
+				] ) );
+			} );
+
+			it( 'should properly remove two last columns', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02' ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ],
+					[ '30', '31', '32' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 1, columns: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00' ],
+					[ '10' ],
+					[ '20' ],
+					[ '30' ]
+				] ) );
+			} );
+
+			it( 'should properly remove multiple heading columns', () => {
+				setData( model, modelTable( [
+					[ '00', '01', '02', '03', '04' ],
+					[ '10', '11', '12', '13', '14' ]
+				], { headingColumns: 3 } ) );
+
+				tableUtils.removeColumn( { at: 1, columns: 3 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00', '04' ],
+					[ '10', '14' ]
+				], { headingColumns: 1 } ) );
+			} );
+
+			it( 'should properly calculate truncated colspans', () => {
+				setData( model, modelTable( [
+					[ { contents: '00', colspan: 3 } ],
+					[ '10', '11', '12' ],
+					[ '20', '21', '22' ]
+				] ) );
+
+				tableUtils.removeColumn( { at: 0, columns: 2 } );
+
+				assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
+					[ '00' ],
+					[ '12' ],
+					[ '22' ]
+				] ) );
+			} );
+		} );
+	} );
 } );
 } );