import { Assert, describe, it } from '@ephox/bedrock-client'; import { Arr } from '@ephox/katamari'; import { Hierarchy, Html, Insert, Remove, SugarBody, SugarElement } from '@ephox/sugar'; import { copyCols } from 'ephox/snooker/api/CopyCols'; describe('CopyColumnsTest', () => { const check = ( label: string, inputHtml: string, expectedHtml: string, section: number, row: number, column: number ) => { const table = SugarElement.fromHtml(inputHtml); Insert.append(SugarBody.body(), table); const rowsOpt = copyCols(table, { selection: [ Hierarchy.follow(table, [ section, row, column, 0 ]).getOrDie(label + ': could not follow path') ] }); const copiedHtml = rowsOpt.map((rows) => Arr.map(rows, Html.getOuter).join('')).getOr(''); Assert.eq(label + ': Copied HTML should match', expectedHtml, copiedHtml); Remove.remove(table); }; const defaultTable = (hasColgroup: boolean = false, lockedColumns: number[] = []) => ` 0 ? `data-snooker-locked-cols="${lockedColumns.join(',')}"` : ''}>` + `${hasColgroup ? '' : ''}` + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
H1H2
A2B2
A3B3
F1F2
'; const colspanTable = (hasColgroup: boolean = false, lockedColumns: number[] = []) => ` 0 ? `data-snooker-locked-cols="${lockedColumns.join(',')}"` : ''}>` + `${hasColgroup ? '' : ''}` + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
H1H2H3
A2B2C2
A3C3
A4
F1F2F3
'; const rowspanTable = (hasColgroup: boolean = false, lockedColumns: number[] = []) => ` 0 ? `data-snooker-locked-cols="${lockedColumns.join(',')}"` : ''}>` + `${hasColgroup ? '' : ''}` + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
H1H2
A2B2
B3
F1F2
'; it('TBA: Test copying column from basic table', () => check( 'Test copying column from basic table', defaultTable(), ( 'H2' + 'B2' + 'B3' + 'F2' ), 0, 0, 1 )); it('TBA: Test copying column from rowspan table', () => check( 'Test copying column from rowspan table', rowspanTable(), ( 'H1' + 'A2' + '' + 'F1' ), 1, 0, 0 )); it('TBA: Test copying column from colspan table with selection in colspan cell', () => check( 'Test copying column from colspan table with selection in colspan cell', colspanTable(), ( 'H1H2' + 'A2B2' + 'A3' + 'A4' + 'F1F2' ), 1, 1, 0 )); it('TBA: Test copying column from colspan table with selection not in colspan cell', () => check( 'Test copying column from colspan table with selection not in colspan cell', colspanTable(), ( 'H1' + 'A2' + 'A3' + 'A4' + 'F1' ), 1, 0, 0 )); it('TINY-8040: Test copying column from colspan table with selection in colspan cell', () => check( 'Test copying column from colspan table with selection in colspan cell', colspanTable(), ( 'H2' + 'B2' + 'A3' + 'A4' + 'F2' ), 1, 0, 1 )); it('TBA: Test copying column from colgroup table', () => check( 'Test copying column from colgroup table', defaultTable(true), ( '' + 'H2' + 'B2' + 'B3' + 'F2' ), 2, 0, 1 )); it('TBA: Test copying column from colgroup table with locked column - selection not in locked column', () => check( 'Test copying column from colgroup table with locked column - selection not in locked column', defaultTable(true, [ 1 ]), ( '' + 'H1' + 'A2' + 'A3' + 'F1' ), 2, 0, 0 )); it('TBA: Test copying column from colgroup table with locked column - selection in locked column (0)', () => check( 'Test copying column from colgroup table with locked column - selection in locked column (0)', defaultTable(true, [ 0 ]), '', 2, 0, 0 )); it('TBA: Test copying column from colgroup table with locked column - selection in locked column (1)', () => check( 'Test copying column from colgroup table with locked column - selection in locked column (1)', defaultTable(true, [ 1 ]), '', 2, 0, 1 )); it('TBA: Test copying column from colgroup table with multiple locked columns', () => check( 'Test copying column from colgroup table with multiple locked columns', defaultTable(true, [ 0, 1 ]), '', 2, 1, 1 )); });