import { UnitTest } from '@ephox/bedrock-client'; import { Optional } from '@ephox/katamari'; import * as TableOperations from 'ephox/snooker/api/TableOperations'; import * as Assertions from 'ephox/snooker/test/Assertions'; import { generateTestTable } from 'ephox/snooker/test/CreateTableUtils'; UnitTest.test('EraseOperationsTest', () => { const deleteExpected1 = '' + '' + '' + '
B1C1D1
B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), Optional.some(deleteExpected1), '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 1, column: 0 } ] ); const deleteExpected2 = '' + '' + '' + '
C1D1
C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected2), '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 0 }, { section: 0, row: 0, column: 1 } ] ); const deleteExpected3 = '' + '' + '' + '
B1C1D1
B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), Optional.some(deleteExpected3), '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 1, column: 0 } ] ); const deleteExpected4 = '' + '' + '' + '
A1D1
A2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 1 }), Optional.some(deleteExpected4), '' + '' + '' + '
A1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 1, column: 1 } ] ); const deleteExpected5 = '' + '' + '
A2B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected5), '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected6 = '' + '' + '
A3B3C3D3
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected6), '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
A3B3C3D3
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 }, { section: 0, row: 1, column: 0 } ] ); const deleteExpected7 = '' + '' + '
A2B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected7), '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected8 = '' + '' + '' + '
A1B2C2D2
B3C3D3
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected8), '' + '' + '' + '' + '
A1B1C1D1
B2C2D2
B3C3D3
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected9 = '' + '
GHI
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected9), '' + '' + '' + '
ABC
DEF
GHI
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 }, { section: 0, row: 1, column: 2 } ] ); const deleteExpected10 = '' + '' + '' + '' + '' + '' + '' + '
0123456789
50515233 34 43 44 53 54 5556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 2 }), Optional.some(deleteExpected10), '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
', TableOperations.eraseRows, [ { section: 0, row: 1, column: 2 }, { section: 0, row: 3, column: 2 }, { section: 0, row: 4, column: 2 } ] ); const deleteExpected11 = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
023456789
101213141516171819
202223242526272829
303233 34 43 44 53 54 3536373839
40424546474849
50525556575859
606263646566676869
707273747576777879
808283848586878889
909293949596979899
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 1 }), Optional.some(deleteExpected11), '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
', TableOperations.eraseColumns, [ { section: 0, row: 1, column: 1 }, { section: 0, row: 3, column: 1 }, { section: 0, row: 4, column: 1 } ] ); const deleteExpected12 = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
012456789
1011 2112141516171819
2022242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
606162646566676869
707172747576777879
808182848586878889
909192949596979899
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 3, column: 3 }), Optional.some(deleteExpected12), '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
', TableOperations.eraseColumns, [ { section: 0, row: 3, column: 3 } ] ); const deleteExpected13 = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
40414233 34 43 44 53 54 4546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 3, column: 3 }), Optional.some(deleteExpected13), '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
', TableOperations.eraseRows, [ { section: 0, row: 3, column: 3 } ] ); const deleteExpected14 = '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 4, column: 7 }), Optional.some(deleteExpected14), '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
0123456789
1011 211213141516171819
202223242526272829
30313233 34 43 44 53 54 3536373839
4041424546474849
5051525556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899
', TableOperations.eraseRows, [ { section: 0, row: 4, column: 5 }, { section: 0, row: 5, column: 5 } ] ); const deleteExpected15 = '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 1 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 1 }), Optional.some(deleteExpected15), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 1 } ] ); const deleteExpected16 = '' + '' + '' + '' + '
row 2 cell 0row 2 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 1 }), Optional.some(deleteExpected16), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 1 }, { section: 0, row: 1, column: 0 } // Note: this one is 0 because hierarchy doesn't account for merged cells, here we are actually targeting cell 1,1 but in the dom structure is in position 0 ] ); const deleteExpected17 = '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 2 row 1 cell 2 row 2 cell 2
row 2 cell 0
row 3 cell 0row 3 cell 2
row 4 cell 0row 4 cell 2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 1 }), Optional.some(deleteExpected17), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 1 }, { section: 0, row: 1, column: 0 } // Note: this one is 0 because hierarchy doesn't account for merged cells, here we are actually targeting cell 1,1 but in the dom structure is in position 0 ] ); const deleteExpected18 = '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0
row 2 cell 0
row 3 cell 0
row 4 cell 0
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 2, column: 0 }), Optional.some(deleteExpected18), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 2 }, { section: 0, row: 2, column: 1 }, { section: 0, row: 3, column: 1 }, { section: 0, row: 3, column: 2 }, { section: 0, row: 4, column: 1 }, { section: 0, row: 4, column: 2 } ] ); Assertions.checkDelete( 'TBA', Optional.none(), Optional.none(), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 2 }, { section: 0, row: 2, column: 1 }, { section: 0, row: 3, column: 1 }, { section: 0, row: 3, column: 2 }, { section: 0, row: 4, column: 1 }, { section: 0, row: 4, column: 2 } ] ); Assertions.checkDelete( 'TBA', Optional.none(), Optional.none(), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseColumns, [ { section: 0, row: 4, column: 0 }, { section: 0, row: 4, column: 1 }, { section: 0, row: 4, column: 2 } ] ); const deleteExpected19 = '' + '' + '
A2B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected19), '' + '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected20 = '' + '' + '
A1B1C1D1
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected20), '' + '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 1, row: 0, column: 0 } ] ); Assertions.checkDelete( 'TBA', Optional.none(), Optional.none(), '' + '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 }, { section: 1, row: 0, column: 0 } ] ); const deleteExpected21 = '' + '' + '' + '' + '' + '
B1C1D1
B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected21), '' + '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected22 = '' + '' + '' + '' + '' + '
B1C1D1
B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected22), '' + '' + '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 0 }, { section: 1, row: 0, column: 0 } ] ); const deleteExpected23 = '' + '' + '' + '
B1C1D1
B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), Optional.some(deleteExpected23), '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseColumns, [ { section: 0, row: 1, column: 0 } ] ); const deleteExpected24 = '' + '' + '
A2B2C2D2
'; Assertions.checkDelete( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), Optional.some(deleteExpected24), '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.eraseRows, [ { section: 0, row: 0, column: 0 } ] ); const deleteExpected25 = generateTestTable( [ 'B2C2D2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [] } ); Assertions.checkDelete( 'Check that columns in a colgroup table can be erased', Optional.some({ section: 1, row: 0, column: 0 }), Optional.some(deleteExpected25), generateTestTable( [ 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [] } ), TableOperations.eraseColumns, [ { section: 1, row: 0, column: 0 } ] ); const deleteExpected26 = generateTestTable( [ 'A3B3C3D3' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [] } ); Assertions.checkDelete( 'Check that rows in a colgroup table can be erased', Optional.some({ section: 1, row: 0, column: 0 }), Optional.some(deleteExpected26), generateTestTable( [ 'A2B2C2D2', 'A3B3C3D3' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [] } ), TableOperations.eraseRows, [ { section: 1, row: 0, column: 0 } ] ); const deleteExpected27 = generateTestTable( [ 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0 ] } ); Assertions.checkDelete( 'TINY-6765: Check that selected locked column cannot be erased', Optional.none(), Optional.some(deleteExpected27), generateTestTable( [ 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.eraseColumns, [ { section: 1, row: 0, column: 0 } ] ); const deleteExpected28 = generateTestTable( [ 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0 ] } ); Assertions.checkDelete( 'TINY-6765: Check that locked columns does not affect erasing rows', Optional.none(), Optional.some(deleteExpected28), generateTestTable( [ 'A2B2C2D2', 'A3B3C3D3' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.eraseRows, [ { section: 1, row: 1, column: 1 } ] ); const deleteExpected29 = generateTestTable( [ 'A2C2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0, 1 ] } ); Assertions.checkDelete( 'TINY-6765: Check that for a multi-column selection, non-locked columns are erased and locked columns are kept', Optional.none(), Optional.some(deleteExpected29), generateTestTable( [ 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0, 2 ] } ), TableOperations.eraseColumns, [ { section: 1, row: 0, column: 0 }, { section: 1, row: 0, column: 1 }, { section: 1, row: 0, column: 2 }, { section: 1, row: 0, column: 3 }, ] ); const deleteExpected30 = '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
'; Assertions.checkDelete( 'TINY-7695: Deleting the last 2 rows should keep the cursor in the last row', Optional.some({ section: 0, row: 2, column: 1 }), Optional.some(deleteExpected30), '' + '' + '' + '' + '' + '' + '
row 0 cell 0 row 1 cell 0 row 0 cell 1row 0 cell 2 row 1 cell 2 row 2 cell 2
row 1 cell 1
row 2 cell 0row 2 cell 1
row 3 cell 0row 3 cell 1row 3 cell 2
row 4 cell 0row 4 cell 1row 4 cell 2
', TableOperations.eraseRows, [ { section: 0, row: 3, column: 1 }, { section: 0, row: 3, column: 2 }, { section: 0, row: 4, column: 1 }, { section: 0, row: 4, column: 2 }, ] ); const deleteExpected31 = '' + '' + '' + '' + '
A1B1
'; Assertions.checkDelete( 'TINY-7695: Deleting the last row should not move the selection into a cef element', Optional.some({ section: 0, row: 0, column: 1 }), Optional.some(deleteExpected31), '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.eraseRows, [ { section: 0, row: 1, column: 0 }, { section: 0, row: 1, column: 1 } ] ); const deleteExpected32 = '' + '' + '' + '' + '' + '
A1
A2
'; Assertions.checkDelete( 'TINY-7695: Deleting the last column should not move the selection into a cef element', Optional.some({ section: 0, row: 1, column: 0 }), Optional.some(deleteExpected32), '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.eraseColumns, [ { section: 0, row: 0, column: 1 }, { section: 0, row: 1, column: 1 } ] ); });