import { UnitTest } from '@ephox/bedrock-client'; 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('PasteCellsOperationsTest', () => { Assertions.checkPasteRaw( 'Test pasting 1x1 table into 2x2 table', generateTestTable( [ 'P1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 1x2 table into 2x2 table', generateTestTable( [ 'P1P2', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1P2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 2x1 table into 2x2 table', generateTestTable( [ 'P1B1', 'P2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1', 'P2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 2x2 table into 2x2 table', generateTestTable( [ 'P1P3', 'P2P4' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1B1', 'P2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1P3', 'P2P4' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 1x3 table into 2x2 table', generateTestTable( [ 'P1P2P3', 'A2B2?' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1P2P3' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 3x1 table into 2x2 table', generateTestTable( [ 'P1B1', 'P2B2', 'P3?' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1', 'P2', 'P3' ], [], [], { numCols: 1, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'Test pasting 3x3 table into 2x2 table', generateTestTable( [ 'P1P4P7', 'P2P5P8', 'P3P6P9' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1B1', 'P2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'P1P4P7', 'P2P5P8', 'P3P6P9' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); // TODO: TINY-6910: Add colspan and rowspan tests Assertions.checkPasteRaw( 'TINY-6765: Test pasting 1x1 table on selected locked column - check that locked column is not pasted into', generateTestTable( [ 'A1P1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0 ] } ), generateTestTable( [ 'P1' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'TINY-6765: Test pasting 1x1 table on table with only locked columns - check that locked columns are not pasted into (first and last locked columns should remain as first and last columns)', generateTestTable( [ 'A1P1B1', 'A2?B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0, 2 ] } ), generateTestTable( [ 'A1B1', 'A2B2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0, 1 ] } ), generateTestTable( [ 'P1' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'TINY-6765: Test pasting 2x2 table on table with interspersed locked columns (1) - check that locked columns are not pasted into (first and last locked columns should remain as first and last columns)', generateTestTable( [ 'A1P1P3C1', 'A2P2P4C2' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [ 0, 3 ] } ), generateTestTable( [ 'A1B1C1', 'A2B2C2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0, 2 ] } ), generateTestTable( [ 'P1P3', 'P2P4' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'TINY-6765: Test pasting 2x2 table on table with interspersed locked columns (2) - check that locked columns are not pasted into (first and last locked columns should remain as first and last columns)', generateTestTable( [ 'A1B1?C1', 'A2P1P3C2', '?P2P4?' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [ 0, 3 ] } ), generateTestTable( [ 'A1B1C1', 'A2B2C2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0, 2 ] } ), generateTestTable( [ 'P1P3', 'P2P4' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 1, 1 ); Assertions.checkPasteRaw( 'TINY-6765: Test pasting 2x2 table on table with only locked columns check that locked columns are not pasted into (first and last locked columns should remain as first and last columns)', generateTestTable( [ 'A1B1??C1', 'A2B2P1P3C2', '??P2P4?' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [ 0, 1, 4 ] } ), generateTestTable( [ 'A1B1C1', 'A2B2C2' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [ 0, 1, 2 ] } ), generateTestTable( [ 'P1P3', 'P2P4' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 0, 1, 1 ); Assertions.checkPasteRaw( 'TINY-6675: Paste cells/col from colgroup table into non-colgroup table', generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A2B2', 'A3B3' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] } ), TableOperations.pasteCells, 0, 0, 0 ); Assertions.checkPasteRaw( 'TINY-6675: Paste cells/col from colgroup table into non-colgroup table (adding new column and row)', generateTestTable( [ 'A2B2?', 'A3X1C2', '?X2C3' ], [], [], { numCols: 3, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'A2B2', 'A3B3' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] } ), TableOperations.pasteCells, 0, 1, 1 ); Assertions.checkPasteRaw( 'TINY-6675: Paste cells/col from non-colgroup table into colgroup table', generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] } ), generateTestTable( [ 'A2B2', 'A3B3' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] } ), generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 1, 0, 0 ); Assertions.checkPasteRaw( 'TINY-6675: Paste cells/col from non-colgroup table into colgroup table (adding new column and row)', generateTestTable( [ 'A2B2?', 'A3X1C2', '?X2C3' ], [], [], { numCols: 3, colgroup: true, lockedColumns: [] } ), generateTestTable( [ 'A2B2', 'A3B3' ], [], [], { numCols: 2, colgroup: true, lockedColumns: [] } ), generateTestTable( [ 'X1C2', 'X2C3' ], [], [], { numCols: 2, colgroup: false, lockedColumns: [] } ), TableOperations.pasteCells, 1, 1, 1 ); });