Allow copy/paste of formatting and mentions

This commit is contained in:
Scott Nonnenberg 2023-05-09 17:40:19 -07:00 committed by GitHub
parent 320ac044a8
commit b4caf67bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 1003 additions and 446 deletions

View file

@ -101,6 +101,64 @@ describe('getTextAndRangesFromOps', () => {
});
});
describe('given formatting', () => {
it('handles trimming at the end of the message', () => {
const ops = [
{
insert: 'Text with trailing ',
attributes: { bold: true },
},
{
insert: 'whitespace ',
attributes: { bold: true, italic: true },
},
];
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
assert.equal(text, 'Text with trailing whitespace');
assert.equal(bodyRanges.length, 2);
assert.deepEqual(bodyRanges, [
{
start: 0,
length: 29,
style: BodyRange.Style.BOLD,
},
{
start: 19,
length: 10,
style: BodyRange.Style.ITALIC,
},
]);
});
it('handles trimming at beginning of the message', () => {
const ops = [
{
insert: ' Text with leading ',
attributes: { bold: true },
},
{
insert: 'whitespace!!',
attributes: { bold: true, italic: true },
},
];
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
assert.equal(text, 'Text with leading whitespace!!');
assert.equal(bodyRanges.length, 2);
assert.deepEqual(bodyRanges, [
{
start: 0,
length: 30,
style: BodyRange.Style.BOLD,
},
{
start: 18,
length: 12,
style: BodyRange.Style.ITALIC,
},
]);
});
});
describe('given text, emoji, and mentions', () => {
it('returns the trimmed text with placeholders and mentions', () => {
const ops = [