import { describe, it } 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';
describe('PasteColumnOperationsTest', () => {
it('TBA: Test1', () =>
Assertions.checkPaste(
'TBA',
(
'
' +
'' +
'| H1 | X1 | H2 |
' +
'' +
'' +
'| A2 | X2 | B2 |
' +
'| A3 | X3 | B3 |
' +
'' +
'' +
'| F1 | X4 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsAfter, 0, 0, 0
)
);
it('TBA: Test2', () =>
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | H2 | X1 |
' +
'' +
'' +
'| A2 | B2 | X2 |
' +
'| A3 | B3 | X3 |
' +
'' +
'' +
'| F1 | F2 | X4 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsAfter, 1, 1, 1
)
);
it('TBA: Test3', () =>
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| X1 | H1 | H2 |
' +
'' +
'' +
'| X2 | A2 | B2 |
' +
'| X3 | A3 | B3 |
' +
'' +
'' +
'| X4 | F1 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsBefore, 0, 0, 0
)
);
it('TBA: Test4', () =>
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | X1 | H2 |
' +
'' +
'' +
'| A2 | X2 | B2 |
' +
'| A3 | X3 | B3 |
' +
'' +
'' +
'| F1 | X4 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsBefore, 1, 1, 1
)
);
it('TBA: Test5', () =>
// Colspan
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | X1 | H2 |
' +
'' +
'' +
'| A2 | X2 | Y2 | B2 |
' +
'| A3 | X3 | Y3 | B3 |
' +
'' +
'' +
'| F1 | X4 | Y4 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 | Y2 |
| X3 | Y3 |
| X4 | Y4 |
',
TableOperations.pasteColsAfter, 0, 0, 0
)
);
it('TBA: Test6', () =>
// Rowspan
Assertions.checkPaste(
'TBA',
(
'' +
'' +
'| H1 | X1 | H2 |
' +
'' +
'' +
'| A2 | X2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | X4 | F2 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 |
' +
'' +
'' +
'| A2 | B2 |
' +
'| A3 | B3 |
' +
'' +
'' +
'| F1 | F2 |
' +
'' +
'
'
),
'| X1 |
| X2 |
|
| X4 |
',
TableOperations.pasteColsBefore, 1, 0, 1
)
);
it('TBA: Test pasting cols (before) into table where num of rows in copied cols is less than number of rows in the table being pasted into', () =>
Assertions.checkPaste(
'Test pasting cols (before) into table where num of rows in copied cols is less than number of rows in the table being pasted into',
generateTestTable(
[
'| A2 | X1 | B2 |
',
'| A3 | ? | B3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 0 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0 ] }
),
'| X1 |
',
TableOperations.pasteColsBefore, 0, 0, 1
)
);
it('TBA: Test pasting cols (after) into table where num of rows in copied cols is less than number of rows in the table being pasted into', () =>
Assertions.checkPaste(
'Test pasting cols (after) into table where num of rows in copied cols is less than number of rows in the table being pasted into',
generateTestTable(
[
'| A2 | X1 | B2 |
',
'| A3 | ? | B3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 2 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
',
TableOperations.pasteColsAfter, 0, 0, 0
)
);
it('TBA: Test pasting cols (before) into table where num of rows in copied cols is greater than number of rows in the table being pasted into', () =>
Assertions.checkPaste(
'Test pasting cols (before) into table where num of rows in copied cols is greater than number of rows in the table being pasted into',
generateTestTable(
[
'| X1 | A2 | B2 |
',
'| X2 | A3 | B3 |
',
'| X3 | ? | ? |
',
'| X4 | ? | ? |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 2 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsBefore, 0, 0, 0
)
);
it('TBA: Test pasting cols (after) into table where num of rows in copied cols is greater than number of rows in the table being pasted into', () =>
Assertions.checkPaste(
'Test pasting cols (after) into table where num of rows in copied cols is greater than number of rows in the table being pasted into',
generateTestTable(
[
'| A2 | B2 | X1 |
',
'| A3 | B3 | X2 |
',
'| ? | ? | X3 |
',
'| ? | ? | X4 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 0 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0 ] }
),
'| X1 |
| X2 |
| X3 |
| X4 |
',
TableOperations.pasteColsAfter, 0, 0, 1
)
);
it('TINY-6765: Test that pasting cols (before) is a noop when the first column in the table is locked and selected', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (before) is a noop when the first column in the table is locked and selected',
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsBefore, 0, 0, 0
)
);
it('TINY-6765: Test that pasting cols (after) is not a noop when the first column in the table is locked and selected', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (after) is not a noop when the first column in the table is locked and selected',
generateTestTable(
[
'| A2 | X1 | B2 |
',
'| A3 | X2 | B3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 0 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 0 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsAfter, 0, 0, 0
)
);
it('TINY-6765: Test that pasting cols (before) is not a noop when the last column in the table is locked and selected', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (before) is not a noop when the last column in the table is locked and selected',
generateTestTable(
[
'| A2 | X1 | B2 |
',
'| A3 | X2 | B3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 2 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsBefore, 0, 0, 1
)
);
it('TINY-6765: Test that pasting cols (after) is a noop when the last column in the table is locked and selected', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (after) is a noop when the last column in the table is locked and selected',
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 1 ] }
),
generateTestTable(
[
'| A2 | B2 |
',
'| A3 | B3 |
'
],
[], [],
{ numCols: 2, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsAfter, 0, 0, 1
)
);
it('TINY-6765: Test that pasting cols (before) is not a noop when the selected locked column is not the first or last column', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (before) is not a noop when the selected locked column is not the first or last column',
generateTestTable(
[
'| A2 | X1 | B2 | C2 |
',
'| A3 | X2 | B3 | C3 |
'
],
[], [],
{ numCols: 4, colgroup: false, lockedColumns: [ 2 ] }
),
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsBefore, 0, 0, 1
)
);
it('TINY-6765: Test that pasting cols (after) is not a noop when the selected locked column is not the first or last column', () =>
Assertions.checkPaste(
'TINY-6765: Test that pasting cols (after) is not a noop when the selected locked column is not the first or last column',
generateTestTable(
[
'| A2 | B2 | X1 | C2 |
',
'| A3 | B3 | X2 | C3 |
'
],
[], [],
{ numCols: 4, colgroup: false, lockedColumns: [ 1 ] }
),
generateTestTable(
[
'| A2 | B2 | C2 |
',
'| A3 | B3 | C3 |
'
],
[], [],
{ numCols: 3, colgroup: false, lockedColumns: [ 1 ] }
),
'| X1 |
| X2 |
',
TableOperations.pasteColsAfter, 0, 0, 1
)
);
it('TINY-8040: Paste a column into the middle of a large colspan, after version', () =>
Assertions.checkPaste(
'Paste a column into the middle of a large colspan',
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | X | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 | ? | ? | A3 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 | A3 |
' +
'' +
'
'
),
(
'' +
'| X | ' +
'
' +
'
'
),
TableOperations.pasteColsAfter, 0, 0, 5
)
);
it('TINY-8040: Paste a column into the middle of a large colspan, before version', () =>
Assertions.checkPaste(
'Paste a column into the middle of a large colspan',
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | X | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 | ? | ? | A3 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 | A3 |
' +
'' +
'
'
),
(
'' +
'| X | ' +
'
' +
'
'
),
TableOperations.pasteColsBefore, 0, 0, 5
)
);
it('TINY-8040: Paste a column into the middle of a large colspan with no cell at the end', () =>
Assertions.checkPaste(
'Paste a column into the middle of a large colspan',
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | X | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 | ? | ? |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A1 | A2 |
' +
'' +
'
'
),
(
'' +
'| X | ' +
'
' +
'
'
),
TableOperations.pasteColsBefore, 0, 0, 5
)
);
it('TINY-8040: Paste a column into the middle of a large colspan with no cell at the start', () =>
Assertions.checkPaste(
'Paste a column into the middle of a large colspan',
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | X | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A2 | ? | ? | A3 |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A2 | A3 |
' +
'' +
'
'
),
(
'' +
'| X | ' +
'
' +
'
'
),
TableOperations.pasteColsBefore, 0, 0, 5
)
);
it('TINY-8040: Paste a column into the middle of a large colspan with no cell at the start or end', () =>
Assertions.checkPaste(
'Paste a column into the middle of a large colspan',
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | X | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A2 | ? | ? |
' +
'' +
'
'
),
(
'' +
'' +
'| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H0 |
' +
'' +
'' +
'| A2 |
' +
'' +
'
'
),
(
'' +
'| X | ' +
'
' +
'
'
),
TableOperations.pasteColsBefore, 0, 0, 5
)
);
/*
TINY-6910
TODO: Need a way to test multi-cell selections - will require something like Asserstions.pasteMultiple or Assertions.checkPaste should be changed to take an array
TODO: Test colgroup tables with locked column not around selection
*/
});