-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2565 from microsoft/u/juliaroldi/export-formatSeg…
…ment Export formatTextSegmentBeforeSelectionMarker
- Loading branch information
Showing
11 changed files
with
818 additions
and
1,874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
...erjs-content-model-api/test/publicApi/utils/formatTextSegmentBeforeSelectionMarkerTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import { formatTextSegmentBeforeSelectionMarker } from '../../../lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker'; | ||
import { | ||
ContentModelDocument, | ||
ContentModelParagraph, | ||
ContentModelSegmentFormat, | ||
ContentModelText, | ||
FormatContentModelContext, | ||
} from 'roosterjs-content-model-types'; | ||
|
||
describe('formatTextSegmentBeforeSelectionMarker', () => { | ||
function runTest( | ||
input: ContentModelDocument, | ||
callback: ( | ||
model: ContentModelDocument, | ||
previousSegment: ContentModelText, | ||
paragraph: ContentModelParagraph, | ||
markerFormat: ContentModelSegmentFormat, | ||
context: FormatContentModelContext | ||
) => boolean, | ||
expectedModel: ContentModelDocument, | ||
expectedResult: boolean | ||
) { | ||
const formatWithContentModelSpy = jasmine | ||
.createSpy('formatWithContentModel') | ||
.and.callFake((callback, options) => { | ||
const result = callback(input, { | ||
newEntities: [], | ||
deletedEntities: [], | ||
newImages: [], | ||
canUndoByBackspace: true, | ||
}); | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
formatTextSegmentBeforeSelectionMarker( | ||
{ | ||
focus: () => {}, | ||
formatContentModel: formatWithContentModelSpy, | ||
} as any, | ||
callback | ||
); | ||
|
||
expect(formatWithContentModelSpy).toHaveBeenCalled(); | ||
expect(input).toEqual(expectedModel); | ||
} | ||
|
||
it('no selection marker', () => { | ||
const input: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'Text', | ||
text: 'test', | ||
format: {}, | ||
}, | ||
], | ||
format: {}, | ||
}, | ||
], | ||
}; | ||
runTest(input, () => true, input, false); | ||
}); | ||
|
||
it('no previous segment', () => { | ||
const input: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'SelectionMarker', | ||
isSelected: true, | ||
format: {}, | ||
}, | ||
], | ||
format: {}, | ||
}, | ||
], | ||
}; | ||
runTest(input, () => true, input, false); | ||
}); | ||
|
||
it('previous segment is not text', () => { | ||
const input: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'Image', | ||
src: 'test', | ||
format: {}, | ||
dataset: {}, | ||
}, | ||
{ | ||
segmentType: 'SelectionMarker', | ||
isSelected: true, | ||
format: {}, | ||
}, | ||
], | ||
format: {}, | ||
}, | ||
], | ||
}; | ||
runTest(input, () => true, input, false); | ||
}); | ||
|
||
it('format segment', () => { | ||
const input: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'Text', | ||
text: 'first', | ||
format: {}, | ||
}, | ||
{ | ||
segmentType: 'Text', | ||
text: 'second', | ||
format: {}, | ||
}, | ||
{ | ||
segmentType: 'SelectionMarker', | ||
isSelected: true, | ||
format: {}, | ||
}, | ||
], | ||
format: {}, | ||
}, | ||
], | ||
}; | ||
const expectedModel: ContentModelDocument = { | ||
blockGroupType: 'Document', | ||
blocks: [ | ||
{ | ||
blockType: 'Paragraph', | ||
segments: [ | ||
{ | ||
segmentType: 'Text', | ||
text: 'first', | ||
format: {}, | ||
}, | ||
{ | ||
segmentType: 'Text', | ||
text: 'second', | ||
format: { | ||
textColor: 'red', | ||
}, | ||
}, | ||
{ | ||
segmentType: 'SelectionMarker', | ||
isSelected: true, | ||
format: {}, | ||
}, | ||
], | ||
format: {}, | ||
}, | ||
], | ||
}; | ||
runTest( | ||
input, | ||
(_model, previousSegment) => { | ||
previousSegment.format = { textColor: 'red' }; | ||
return true; | ||
}, | ||
expectedModel, | ||
true | ||
); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/roosterjs-content-model-plugins/lib/autoFormat/link/unlink.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/roosterjs-content-model-plugins/lib/markdown/utils/setFormat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.