import { UnitTest } from '@ephox/bedrock-client';
import * as Assertions from 'ephox/snooker/test/Assertions';
UnitTest.test('MergeOperationsTest', () => {
Assertions.checkMerge(
'SimpleCase - merging textnodes should move all content into the first cell separarted by BRs',
// Border = 1 would be here, but it is removed so that we can assert html
'
' +
'a d
| b | c |
' +
'| e | f |
' +
'| g | h | i |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'SimpleCase - merging textnodes should move all content into the first cell separarted by BRs',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'a d
| b | c |
' +
'| e | f |
' +
'' +
'' +
'| g | h | i |
' +
'| j | k | l |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'' +
'' +
'| g | h | i |
' +
'| j | k | l |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'SimpleCase - merging textnodes should move all content into the first cell separarted by BRs',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'' +
'' +
'g j
| h | i |
' +
'| k | l |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'' +
'' +
'| g | h | i |
' +
'| j | k | l |
' +
'
',
[
{ section: 1, row: 0, column: 0 },
{ section: 1, row: 1, column: 0 }
],
{ startRow: 2, startCol: 0, finishRow: 3, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6484 - merge cells where there is one or more row-scopes, resulting in a rowgroup scope.',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'' +
'' +
'A1 A2
| ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
'' +
'' +
'' +
'| A1 | ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| A2 | ' +
'B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6484 - merge cells where there is one or more col-scopes, resulting in a colgroup scope.',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'' +
'' +
'A1 B1
| ' +
'C1 | ' +
'
' +
'' +
'| A2 | ' +
'B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
'' +
'' +
'' +
'| A1 | ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| A2 | ' +
'B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 0, column: 1 }
],
{ startRow: 0, startCol: 0, finishRow: 0, finishCol: 1 }
);
Assertions.checkMerge(
'TINY-6484 - merge cells where there is one or more row-scopes and one or more col-scopes, resulting in the scope attribute being removed.',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'' +
'' +
'A1 A2
| ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
'' +
'' +
'' +
'| A1 | ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| A2 | ' +
'B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6484 - merge cells where there is one or more row-scopes and one or more col-scopes, resulting in the scope attribute being removed, reverse order.',
// Border = 1 would be here, but it is removed so that we can assert html
'' +
'' +
'' +
'A1 A2
| ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
'' +
'' +
'' +
'| A1 | ' +
'B1 | ' +
'C1 | ' +
'
' +
'' +
'| A2 | ' +
'B2 | ' +
'C2 | ' +
'
' +
'' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6765 - merging cells in different rows that are part of a locked column should be noop',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6765 - merging cells in different columns that are part of a locked column should be noop',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 0, column: 1 },
{ section: 0, row: 0, column: 2 }
],
{ startRow: 0, startCol: 0, finishRow: 0, finishCol: 2 }
);
Assertions.checkMerge(
'TINY-6765 - merging cells in different rows with a locked column in the table but not selected should not affect merging (0)',
'' +
'a d
| b | c |
' +
'| e | f |
' +
'| g | h | i |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 1, column: 0 }
],
{ startRow: 0, startCol: 0, finishRow: 1, finishCol: 0 }
);
Assertions.checkMerge(
'TINY-6765 - merging cells in different rows and columns with a locked column in the table but not selected should not affect merging (1)',
'' +
'a b d e g h
| c |
' +
'| f |
' +
'| i |
' +
'
',
'' +
'| a | b | c |
' +
'| d | e | f |
' +
'| g | h | i |
' +
'
',
[
{ section: 0, row: 0, column: 0 },
{ section: 0, row: 0, column: 1 },
{ section: 0, row: 1, column: 0 },
{ section: 0, row: 1, column: 1 },
{ section: 0, row: 2, column: 0 },
{ section: 0, row: 2, column: 1 }
],
{ startRow: 0, startCol: 0, finishRow: 2, finishCol: 1 }
);
});