Support for sending formatting messages
This commit is contained in:
parent
42e13aedcd
commit
9bfbee464b
65 changed files with 1762 additions and 371 deletions
|
@ -5,9 +5,10 @@ import { assert } from 'chai';
|
|||
|
||||
import {
|
||||
getDeltaToRemoveStaleMentions,
|
||||
getTextAndMentionsFromOps,
|
||||
getTextAndRangesFromOps,
|
||||
getDeltaToRestartMention,
|
||||
} from '../../quill/util';
|
||||
import { BodyRange } from '../../types/BodyRange';
|
||||
|
||||
describe('getDeltaToRemoveStaleMentions', () => {
|
||||
const memberUuids = ['abcdef', 'ghijkl'];
|
||||
|
@ -83,20 +84,20 @@ describe('getDeltaToRemoveStaleMentions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getTextAndMentionsFromOps', () => {
|
||||
describe('getTextAndRangesFromOps', () => {
|
||||
describe('given only text', () => {
|
||||
it('returns only text trimmed', () => {
|
||||
const ops = [{ insert: ' The ' }, { insert: ' text \n' }];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, 'The text');
|
||||
assert.equal(resultMentions.length, 0);
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, 'The text');
|
||||
assert.equal(bodyRanges.length, 0);
|
||||
});
|
||||
|
||||
it('returns trimmed of trailing newlines', () => {
|
||||
const ops = [{ insert: ' The\ntext\n\n\n' }];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, 'The\ntext');
|
||||
assert.equal(resultMentions.length, 0);
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, 'The\ntext');
|
||||
assert.equal(bodyRanges.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -120,9 +121,9 @@ describe('getTextAndMentionsFromOps', () => {
|
|||
},
|
||||
},
|
||||
];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, '😂 wow, funny, \uFFFC');
|
||||
assert.deepEqual(resultMentions, [
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, '😂 wow, funny, \uFFFC');
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
length: 1,
|
||||
mentionUuid: 'abcdef',
|
||||
|
@ -145,9 +146,9 @@ describe('getTextAndMentionsFromOps', () => {
|
|||
},
|
||||
},
|
||||
];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, '\uFFFC');
|
||||
assert.deepEqual(resultMentions, [
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, '\uFFFC');
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
length: 1,
|
||||
mentionUuid: 'abcdef',
|
||||
|
@ -170,9 +171,9 @@ describe('getTextAndMentionsFromOps', () => {
|
|||
},
|
||||
{ insert: '\n test' },
|
||||
];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, 'test \n\uFFFC\n test');
|
||||
assert.deepEqual(resultMentions, [
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, 'test \n\uFFFC\n test');
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
length: 1,
|
||||
mentionUuid: 'abcdef',
|
||||
|
@ -182,6 +183,188 @@ describe('getTextAndMentionsFromOps', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('given formatting on text, with emoji and mentions', () => {
|
||||
it('handles overlapping and contiguous format sections properly', () => {
|
||||
const ops = [
|
||||
{
|
||||
insert: 'Hey, ',
|
||||
attributes: {
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: {
|
||||
mention: {
|
||||
uuid: 'a',
|
||||
title: '@alice',
|
||||
},
|
||||
},
|
||||
attributes: {
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ': this is ',
|
||||
attributes: {
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: 'bold',
|
||||
attributes: {
|
||||
bold: true,
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ' and',
|
||||
attributes: {
|
||||
bold: true,
|
||||
italic: true,
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ' italic',
|
||||
attributes: {
|
||||
italic: true,
|
||||
spoiler: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ' and strikethrough',
|
||||
attributes: {
|
||||
strike: true,
|
||||
},
|
||||
},
|
||||
{ insert: ' ' },
|
||||
{
|
||||
insert: 'and monospace',
|
||||
attributes: {
|
||||
monospace: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(
|
||||
text,
|
||||
'Hey, \uFFFC: this is bold and italic and strikethrough and monospace'
|
||||
);
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
start: 5,
|
||||
length: 1,
|
||||
mentionUuid: 'a',
|
||||
replacementText: '@alice',
|
||||
},
|
||||
{
|
||||
start: 16,
|
||||
length: 8,
|
||||
style: BodyRange.Style.BOLD,
|
||||
},
|
||||
{
|
||||
start: 20,
|
||||
length: 11,
|
||||
style: BodyRange.Style.ITALIC,
|
||||
},
|
||||
{
|
||||
start: 0,
|
||||
length: 31,
|
||||
style: BodyRange.Style.SPOILER,
|
||||
},
|
||||
{
|
||||
start: 31,
|
||||
length: 18,
|
||||
style: BodyRange.Style.STRIKETHROUGH,
|
||||
},
|
||||
{
|
||||
start: 50,
|
||||
length: 13,
|
||||
style: BodyRange.Style.MONOSPACE,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles lots of the same format', () => {
|
||||
const ops = [
|
||||
{
|
||||
insert: 'Every',
|
||||
attributes: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ' other ',
|
||||
},
|
||||
{
|
||||
insert: 'word',
|
||||
attributes: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
insert: ' is ',
|
||||
},
|
||||
{
|
||||
insert: 'bold!',
|
||||
attributes: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, 'Every other word is bold!');
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
start: 0,
|
||||
length: 5,
|
||||
style: BodyRange.Style.BOLD,
|
||||
},
|
||||
{
|
||||
start: 12,
|
||||
length: 4,
|
||||
style: BodyRange.Style.BOLD,
|
||||
},
|
||||
{
|
||||
start: 20,
|
||||
length: 5,
|
||||
style: BodyRange.Style.BOLD,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles formatting on mentions', () => {
|
||||
const ops = [
|
||||
{
|
||||
insert: {
|
||||
mention: {
|
||||
uuid: 'a',
|
||||
title: '@alice',
|
||||
},
|
||||
},
|
||||
attributes: {
|
||||
bold: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
|
||||
assert.equal(text, '\uFFFC');
|
||||
assert.deepEqual(bodyRanges, [
|
||||
{
|
||||
start: 0,
|
||||
length: 1,
|
||||
mentionUuid: 'a',
|
||||
replacementText: '@alice',
|
||||
},
|
||||
{
|
||||
start: 0,
|
||||
length: 1,
|
||||
style: BodyRange.Style.BOLD,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDeltaToRestartMention', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue