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('PasteRowOperationsTest', () => {
Assertions.checkPaste(
'TBA',
(
'
' +
'' +
'| H1 | H1 |
' +
'| X1 | X2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsAfter, 0, 0, 0
);
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'| X1 | X2 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsAfter, 1, 1, 0
);
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'| X1 | X2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsAfter, 2, 0, 0
);
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| X1 | X2 |
' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsBefore, 0, 0, 0
);
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| X1 | X2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsBefore, 1, 1, 0
);
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| X1 | X2 |
' +
'| F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H1 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 | X2 |
',
TableOperations.pasteRowsBefore, 2, 0, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (before) into table where num of cols in copied rows is less than number of cols in the table being pasted into',
generateTestTable(
[
'| X1 | ? |
',
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
'| X1 |
',
TableOperations.pasteRowsBefore, 0, 0, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (after) into table where num of cols in copied rows is less than number of cols in the table being pasted into',
generateTestTable(
[
'| A2 | B2 |
',
'| X1 | ? |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
'| X1 |
',
TableOperations.pasteRowsAfter, 0, 0, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (before) into table where num of cols in copied rows is greater than number of cols in the table being pasted into',
generateTestTable(
[
'| X1 | X2 | X3 | X4 |
',
'| A2 | B2 | ? | ? |
',
'| A3 | B3 | ? | ? |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
'| X1 | X2 | X3 | X4 |
',
TableOperations.pasteRowsBefore, 0, 0, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (after) into table where num of cols in copied rows is greater than number of cols in the table being pasted into',
generateTestTable(
[
'| A2 | B2 | ? | ? |
',
'| A3 | B3 | ? | ? |
',
'| X1 | X2 | X3 | X4 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [] }
),
'| X1 | X2 | X3 | X4 |
',
TableOperations.pasteRowsAfter, 0, 1, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (before) into table where there are locked columns - should wrap around locked columns (last locked column should remain as last column)',
generateTestTable(
[
'| A2 | B2 | ? | C2 |
',
'| ? | X1 | X2 | ? |
',
'| A3 | B3 | ? | C3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 3 ] }
),
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 2 ] }
),
'| X1 | X2 |
',
TableOperations.pasteRowsBefore, 0, 1, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (after) into table where there are locked columns - should wrap around locked columns (last locked column should remain as last column)',
generateTestTable(
[
'| A2 | B2 | ? | C2 |
',
'| A3 | B3 | ? | C3 |
',
'| ? | X1 | X2 | ? |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 3 ] }
),
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 2 ] }
),
'| X1 | X2 |
',
TableOperations.pasteRowsAfter, 0, 1, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (after) into table where all columns are locked - (first and last locked column should remain as first and last column)',
generateTestTable(
[
'| A2 | ? | ? | B2 |
',
'| ? | X1 | X2 | ? |
',
'| A3 | ? | ? | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 3 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0, 1 ] }
),
'| X1 | X2 |
',
TableOperations.pasteRowsAfter, 0, 0, 0
);
Assertions.checkPaste(
'TINY-6765: Test pasting rows (before) with less cols into table where there are locked columns',
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| X1 | X2 | ? |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 2 ] }
),
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 2 ] }
),
'| X1 | X2 |
',
TableOperations.pasteRowsBefore, 0, 1, 0
);
});