import { Log, Pipeline, Step } from '@ephox/agar';
import { Assert, UnitTest } from '@ephox/bedrock-client';
import { Fun, Optional } from '@ephox/katamari';
import { SelectorFind, SugarDocument, SugarElement } from '@ephox/sugar';
import { cellOperations } from 'ephox/snooker/api/TableFill';
UnitTest.asynctest('modules.snooker.src.test.ts.browser.CopyAttributesTest.ts', (success, failure) => {
const operations = cellOperations(Fun.noop, SugarDocument.getDocument(), Optional.none());
const generateCell = (input: string, type: string) => {
const modifiedInput = '
';
const element = SugarElement.fromHtml(modifiedInput);
return SelectorFind.descendant(element, type).getOrDie('Error here');
};
const sMakeCellComparison = (id: string, desctripion: string, type: string, input: string, expectedOutput: string): Step =>
Log.step(id, desctripion, Step.sync(() => {
const newCell = operations.cell({
element: generateCell(input, type),
colspan: 0,
rowspan: 0
});
Assert.eq(
'Ensure output html matches expectations',
expectedOutput,
newCell.dom.outerHTML
);
}));
Pipeline.async({}, [
sMakeCellComparison('TINY-6485', 'nothing copied if nothing is added for td', 'td', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'nothing copied if nothing is added for th', 'th', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'copy scope if value is row for td', 'td', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'copy scope if value is row for th', 'th', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'copy scope if value is col', 'th', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'nothing copied if scope value is not a pre-approved value', 'th', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'do not copy random attributes for td.', 'td', ' | ', '
| '),
sMakeCellComparison('TINY-6485', 'do not copy random attributes for th.', 'th', ' | ', '
| ')
], success, failure);
});