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('InsertOperationsTest', () => { Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '' + '
??
A1B1
A2B2
', '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), '' + '' + '' + '' + '
A1B1
??
A2B2
', '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowBefore, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '' + '
??
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertRowBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), '' + '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
??
A2B2
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertRowBefore, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 2, column: 0 }), '' + '' + '' + '' + '
A1B1
A2B2
??
', '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowAfter, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 2, column: 0 }), '' + '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
??
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertRowAfter, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '
?A1B1C1D1
?A2B2C2D2
', '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.insertColumnBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '
?' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
?A2B2
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertColumnBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 1, column: 1 }), '' + '' + '' + '
A1?B1C1D1
A2?B2C2D2
', '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.insertColumnAfter, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 1 }), '' + '' + '' + '
A1?B1C1D1
A2?B2C2D2
', '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.insertColumnAfter, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 2 }), '' + '' + '' + '
A1B1?C1D1
A2B2?C2D2
', '' + '' + '' + '
A1B1C1D1
A2B2C2D2
', TableOperations.insertColumnAfter, 0, 0, 1 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 1 }), '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
?B1
A2?B2
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertColumnAfter, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 2 }), '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1?
A2B2?
', '' + '' + '' + '
' + '' + '' + '' + '
1A1B
2A2B
' + 'A1
B1
A2B2
', TableOperations.insertColumnAfter, 0, 0, 1 ); Assertions.checkStructure({ section: 0, row: 1, column: 1 }, [ [ 'A', '?', 'B', 'C' ], [ 'D', '?', 'E' ], [ 'F' ], [ 'G' ], [ 'H' ], [ 'I', '?', 'J', 'K' ], [ 'L', 'M' ] ], '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
ABC
DE
F
G
H
IJK
LM
', TableOperations.insertColumnAfter, 0, 1, 0 ); // Irregular tables (inserting row where one row has an irregular cell. Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 2, column: 0 }), '' + '' + '' + '' + '
A1B1IRREGULAR CELL
A2B2?
???
', '' + '' + '' + '
A1B1IRREGULAR CELL
A2B2
', TableOperations.insertRowAfter, 0, 1, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '' + '' + '' + '
??
A1B1
A2B2
', '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 1, row: 0, column: 0 }), '' + '' + '' + '' + '' + '' + '
A1B1
??
A2B2
', '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowBefore, 1, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 1, column: 0 }), '' + '' + '' + '' + '' + '' + '
A1B1
??
A2B2
', '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowAfter, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 1, row: 1, column: 0 }), '' + '' + '' + '' + '' + '' + '
A1B1
A2B2
??
', '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowAfter, 1, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 0, row: 0, column: 0 }), '' + '' + '' + '' + '
??
A1B1
A2B2
', '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowBefore, 0, 0, 0 ); Assertions.checkOld( 'TBA', Optional.some({ section: 1, row: 1, column: 1 }), '' + '' + '' + '' + '' + '' + '
A1B1
A2B2
??
', '' + '' + '' + '' + '' + '
A1B1
A2B2
', TableOperations.insertRowAfter, 1, 0, 1 ); Assertions.checkOld( 'Check column can be inserted before with colgroup table and a locked column is present but is not selected', Optional.some({ section: 1, row: 0, column: 0 }), generateTestTable( [ '?' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', '?A2B2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 2 ] } ), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnBefore, 1, 0, 0 ); Assertions.checkOld( 'Check column can be inserted after with colgroup table and a locked column is present but is not selected', Optional.some({ section: 1, row: 0, column: 2 }), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1?', 'A2B2?' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertColumnAfter, 1, 0, 1 ); Assertions.checkOld( 'Check row can be inserted before with colgroup table and a locked column is present', Optional.some({ section: 1, row: 0, column: 0 }), generateTestTable( [ '??', '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertRowBefore, 1, 0, 0 ); Assertions.checkOld( 'Check row can be inserted after with colgroup table and a locked column is present', Optional.some({ section: 1, row: 1, column: 0 }), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', '??', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ '' + generateTestTable([ '1A1B', '2A2B' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] }) + 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertRowAfter, 1, 0, 0 ); Assertions.checkOld( 'TINY-6765: Check column cannot be inserted before if first column is selected and is locked (collapsed)', Optional.none(), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertColumnBefore, 1, 0, 0 ); Assertions.checkOldMultiple( 'TINY-6765: Check column cannot be inserted before if first column is selected and is locked (multi-col selection)', Optional.none(), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertColumnsBefore, [ { section: 1, row: 0, column: 0 }, { section: 1, row: 0, column: 1 } ] ); Assertions.checkOld( 'TINY-6765: Check column can be inserted after if first column is selected and is locked (collapsed)', Optional.some({ section: 1, row: 0, column: 1 }), generateTestTable( [ 'A1?B1', 'A2?B2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 0 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 0 ] } ), TableOperations.insertColumnAfter, 1, 0, 0 ); Assertions.checkOld( 'TINY-6765: Check column cannot be inserted after if last column is selected and is locked (collapsed)', Optional.none(), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnAfter, 1, 0, 1 ); Assertions.checkOldMultiple( 'TINY-6765: Check column cannot be inserted after if last column is selected and is locked (multi-col selection)', Optional.none(), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnsAfter, [ { section: 1, row: 0, column: 0 }, { section: 1, row: 0, column: 1 } ] ); Assertions.checkOld( 'TINY-6765: Check column cannot be inserted after if colspan column is selected, is locked and would result in a column being inserted at the end of the table (collapsed)', Optional.none(), generateTestTable( [ 'A1B1', 'A2B2C2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), generateTestTable( [ 'A1B1', 'A2B2C2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnAfter, 1, 0, 1 ); Assertions.checkOld( 'TINY-6765: Check column can be inserted before if last column is selected and is locked (collapsed)', Optional.none(), generateTestTable( [ 'A1?B1', 'A2?B2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 2 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnBefore, 1, 0, 1 ); Assertions.checkOld( 'TINY-6765: Check that column can be inserted before if start of selection is a locked column that is not the first column in the table (collapsed)', Optional.none(), generateTestTable( [ 'A1?B1C1', 'A2?B2C2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 2 ] } ), generateTestTable( [ 'A1B1C1', 'A2B2C2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnBefore, 1, 0, 1 ); Assertions.checkOld( 'TINY-6765: Check that column can be inserted after if end of selection is a locked column that is not the last column in the table (collapsed)', Optional.none(), generateTestTable( [ 'A1B1?C1', 'A2B2?C2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 1 ] } ), generateTestTable( [ 'A1B1C1', 'A2B2C2' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [ 1 ] } ), TableOperations.insertColumnAfter, 1, 0, 1 ); Assertions.checkOldMultiple( 'TINY-6765: Check that column can be inserted before if start of selection is a locked column that is not the first column in the table (multi-col selection) (locked column should count towards the number of columns inserted before)', Optional.none(), generateTestTable( [ 'A1???B1C1D1', 'A2???B2C2D2' ], [], [], { numCols: 7, colgroup: true, lockedColumns: [ 4, 6 ] } ), generateTestTable( [ 'A1B1C1D1', 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 1, 3 ] } ), TableOperations.insertColumnsBefore, [ { section: 1, row: 0, column: 1 }, { section: 1, row: 0, column: 2 }, { section: 1, row: 0, column: 3 } ] ); Assertions.checkOldMultiple( 'TINY-6765: Check that column can be inserted after if end of selection is a locked column that is not the last column in the table (multi-col selection) (locked columns should count towards the number of columns inserted after)', Optional.none(), generateTestTable( [ 'A1B1C1???D1', 'A2B2C2???D2' ], [], [], { numCols: 7, colgroup: true, lockedColumns: [ 0, 2 ] } ), generateTestTable( [ 'A1B1C1D1', 'A2B2C2D2' ], [], [], { numCols: 4, colgroup: true, lockedColumns: [ 0, 2 ] } ), TableOperations.insertColumnsAfter, [ { section: 1, row: 0, column: 0 }, { section: 1, row: 0, column: 1 }, { section: 1, row: 0, column: 2 } ] ); });