From badefc579d314bcf91a749132428b5ae14a25b16 Mon Sep 17 00:00:00 2001 From: Bryan Valverde U Date: Thu, 5 Oct 2023 10:12:16 -0600 Subject: [PATCH] Fix Excel Border issue when pasting (#2121) * init * itChromeOnly --- .../Excel/processPastedContentFromExcel.ts | 15 + .../plugins/ContentModelPastePluginTest.ts | 6 +- .../paste/e2e/cmPasteFromExcelOnlineTest.ts | 1159 ++++++++++++++++- .../plugins/paste/e2e/cmPasteFromExcelTest.ts | 1123 +++++++++++++++- .../editor/plugins/paste/e2e/testUtils.ts | 17 +- .../test/publicApi/utils/pasteTest.ts | 4 +- 6 files changed, 2308 insertions(+), 16 deletions(-) diff --git a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel.ts b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel.ts index 95b14f01f3f..3619e20e849 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel.ts @@ -1,6 +1,7 @@ import addParser from '../utils/addParser'; import { isNodeOfType } from 'roosterjs-content-model-dom'; import { moveChildNodes } from 'roosterjs-editor-dom'; +import { setProcessor } from '../utils/setProcessor'; import type ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentModelBeforePasteEvent'; import type { TrustedHTMLHandler } from 'roosterjs-editor-types'; @@ -60,6 +61,20 @@ export function processPastedContentFromExcel( format.borderTop = DEFAULT_BORDER_STYLE; } }); + + setProcessor(event.domToModelOption, 'child', (group, element, context) => { + const segmentFormat = { ...context.segmentFormat }; + if (group.blockGroupType === 'TableCell' && group.format.textColor) { + context.segmentFormat.textColor = group.format.textColor; + } + + context.defaultElementProcessors.child(group, element, context); + + if (group.blockGroupType === 'TableCell' && group.format.textColor) { + context.segmentFormat = segmentFormat; + delete group.format.textColor; + } + }); } /** diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelPastePluginTest.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelPastePluginTest.ts index 93c4849ef4e..33f91e4bd92 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelPastePluginTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/ContentModelPastePluginTest.ts @@ -108,7 +108,7 @@ describe('Content Model Paste Plugin Test', () => { trustedHTMLHandler ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 3); - expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0); + expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1); expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1); }); @@ -141,7 +141,7 @@ describe('Content Model Paste Plugin Test', () => { trustedHTMLHandler ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); - expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0); + expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1); expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1); }); @@ -157,7 +157,7 @@ describe('Content Model Paste Plugin Test', () => { trustedHTMLHandler ); expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); - expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0); + expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1); expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1); }); diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelOnlineTest.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelOnlineTest.ts index 657f14506eb..786f8263b4a 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelOnlineTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelOnlineTest.ts @@ -1,8 +1,9 @@ import * as processPastedContentFromExcel from '../../../../../lib/editor/plugins/PastePlugin/Excel/processPastedContentFromExcel'; import paste from '../../../../../lib/publicApi/utils/paste'; import { ClipboardData } from 'roosterjs-editor-types'; +import { expectEqual, initEditor } from './testUtils'; import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor'; -import { initEditor } from './testUtils'; +import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper'; import { tableProcessor } from 'roosterjs-content-model-dom'; const ID = 'CM_Paste_From_ExcelOnline_E2E'; @@ -43,4 +44,1160 @@ describe(ID, () => { expect(processPastedContentFromExcel.processPastedContentFromExcel).toHaveBeenCalled(); }); + + itChromeOnly('E2E Table with table cells with text color', () => { + const CD = ({ + types: ['text/plain', 'text/html'], + text: + 'No.\tID\tWork Item Type\r\n1\tlink\tBug\r\n2\tlink\tBug\r\n3\tlink\tBug\r\n4\tlink\tBug\r\n5\tlink\tBug\r\n6\tlink\tBug\r\n7\tlink\tBug', + image: null, + files: [] as any, + rawHtml: + "\r\n\r\n
No.IDWork Item Type
1linkBug
2linkBug
3linkBug
4linkBug
5linkBug
6linkBug
7linkBug
\r\n\r\n", + customValues: {}, + pasteNativeEvent: true, + snapshotBeforePaste: '

', + }); + + paste(editor, CD); + + const model = editor.createContentModel({ + processorOverride: { + table: tableProcessor, + }, + }); + + expectEqual(model, { + blockGroupType: 'Document', + blocks: [ + { + widths: jasmine.anything() as any, + rows: [ + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'No.', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '48pt', + height: '28.5pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'ID', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '52pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Work Item Type', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'normal', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'normal', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '57pt', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '1', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '2', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '3', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '4', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '5', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '6', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '7', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + ], + blockType: 'Table', + format: { + width: '157pt' as any, + useBorderBox: true, + borderCollapse: true, + } as any, + dataset: {}, + }, + { + segments: [ + { + isSelected: true, + segmentType: 'SelectionMarker', + format: {}, + }, + { + segmentType: 'Br', + format: {}, + }, + ], + blockType: 'Paragraph', + format: {}, + }, + ], + format: {}, + }); + }); }); diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelTest.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelTest.ts index c5db86d346e..60b905711df 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/cmPasteFromExcelTest.ts @@ -2,8 +2,9 @@ import * as processPastedContentFromExcel from '../../../../../lib/editor/plugin import paste from '../../../../../lib/publicApi/utils/paste'; import { Browser } from 'roosterjs-editor-dom'; import { ClipboardData } from 'roosterjs-editor-types'; +import { expectEqual, initEditor } from './testUtils'; import { IContentModelEditor } from '../../../../../lib/publicTypes/IContentModelEditor'; -import { initEditor } from './testUtils'; +import { itChromeOnly } from 'roosterjs-editor-dom/test/DomTestHelper'; import { tableProcessor } from 'roosterjs-content-model-dom'; const ID = 'CM_Paste_From_Excel_E2E'; @@ -91,4 +92,1124 @@ describe(ID, () => { }); expect(processPastedContentFromExcel.processPastedContentFromExcel).not.toHaveBeenCalled(); }); + + itChromeOnly('Copy Table with text color in cell', () => { + const CD = ({ + types: ['image/png', 'text/plain', 'text/html'], + text: + 'No.\tID\tWork Item Type\r\n1\tlink\tBug\r\n2\tlink\tBug\r\n3\tlink\tBug\r\n4\tlink\tBug\r\n5\tlink\tBug\r\n6\tlink\tBug\r\n7\tlink\tBug\r\n', + image: {}, + files: [], + rawHtml: + "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n
No.IDWork Item Type
1linkBug
2linkBug
3linkBug
4linkBug
5linkBug
6linkBug
7linkBug
\r\n\r\n\r\n\r\n\r\n", + customValues: {}, + pasteNativeEvent: true, + imageDataUri: '', + snapshotBeforePaste: '
', + }); + + paste(editor, CD); + + const model = editor.createContentModel({ + processorOverride: { + table: tableProcessor, + }, + }); + + expectEqual(model, { + blockGroupType: 'Document', + blocks: [ + { + widths: jasmine.anything() as any, + rows: [ + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'No.', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '52pt', + height: '28.5pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'ID', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '56pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Work Item Type', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '700', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'normal', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'normal', + borderTop: '0.5pt solid', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + width: '62pt', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '1', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '2', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '3', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '4', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '5', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '6', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + { + height: jasmine.anything() as any, + cells: [ + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: '7', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'black', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + borderLeft: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + height: '30pt', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'link', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(5, 99, 193)', + underline: true, + }, + link: { + format: { + underline: true, + href: 'http://www.microsoft.com/', + }, + dataset: {}, + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + { + spanAbove: false, + spanLeft: false, + isHeader: false, + blockGroupType: 'TableCell', + blocks: [ + { + segments: [ + { + text: 'Bug', + segmentType: 'Text', + format: { + fontFamily: 'Calibri, sans-serif', + fontSize: '11pt', + fontWeight: '400', + textColor: 'rgb(219, 219, 219)', + }, + }, + ], + blockType: 'Paragraph', + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + }, + }, + ], + format: { + textAlign: 'center', + whiteSpace: 'nowrap', + borderRight: '0.5pt solid', + borderBottom: '0.5pt solid', + backgroundColor: 'white', + paddingTop: '1px', + paddingRight: '1px', + paddingLeft: '1px', + verticalAlign: 'middle', + }, + dataset: {}, + }, + ], + format: {}, + }, + ], + blockType: 'Table', + format: { + width: jasmine.anything(), + useBorderBox: true, + borderCollapse: true, + } as any, + dataset: {}, + }, + { + segments: [ + { + isSelected: true, + segmentType: 'SelectionMarker', + format: {}, + }, + { + segmentType: 'Br', + format: {}, + }, + ], + blockType: 'Paragraph', + format: {}, + }, + ], + format: {}, + }); + }); }); diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/testUtils.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/testUtils.ts index 8d235f46915..34d1eedcc6b 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/testUtils.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/plugins/paste/e2e/testUtils.ts @@ -22,14 +22,13 @@ export function initEditor(id: string) { } export function expectEqual(model1: ContentModelDocument, model2: ContentModelDocument) { - expect( - /// Remove Cached elements and undefined properties - JSON.parse( - JSON.stringify( - cloneModel(model1, { - includeCachedElement: false, - }) - ) + /// Remove Cached elements and undefined properties + const newModel = JSON.parse( + JSON.stringify( + cloneModel(model1, { + includeCachedElement: false, + }) ) - ).toEqual(model2); + ); + expect(newModel).toEqual(model2); } diff --git a/packages-content-model/roosterjs-content-model-editor/test/publicApi/utils/pasteTest.ts b/packages-content-model/roosterjs-content-model-editor/test/publicApi/utils/pasteTest.ts index 376e8818f9c..57d85576d7a 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/publicApi/utils/pasteTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/publicApi/utils/pasteTest.ts @@ -220,7 +220,7 @@ describe('paste with content model & paste plugin', () => { pasteF.default(editor!, clipboardData); - expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0); + expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(1); expect(addParserF.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); expect(ExcelF.processPastedContentFromExcel).toHaveBeenCalledTimes(1); }); @@ -231,7 +231,7 @@ describe('paste with content model & paste plugin', () => { pasteF.default(editor!, clipboardData); - expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0); + expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(1); expect(addParserF.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1); expect(ExcelF.processPastedContentFromExcel).toHaveBeenCalledTimes(1); });