2022-01-19 19:19:08 +00:00
|
|
|
// Copyright 2020-2022 Signal Messenger, LLC
|
2020-11-03 01:19:52 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-01-19 19:19:08 +00:00
|
|
|
import { assert } from 'chai';
|
2020-11-03 01:19:52 +00:00
|
|
|
import { getTextWithMentions } from '../../util/getTextWithMentions';
|
|
|
|
|
|
|
|
describe('getTextWithMentions', () => {
|
|
|
|
describe('given mention replacements', () => {
|
|
|
|
it('replaces them', () => {
|
|
|
|
const bodyRanges = [
|
|
|
|
{
|
|
|
|
length: 1,
|
|
|
|
mentionUuid: 'abcdef',
|
|
|
|
replacementText: 'fred',
|
2022-11-10 04:59:36 +00:00
|
|
|
conversationID: 'x',
|
2020-11-03 01:19:52 +00:00
|
|
|
start: 4,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const text = "Hey \uFFFC, I'm here";
|
2022-01-19 19:19:08 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getTextWithMentions(bodyRanges, text),
|
2020-11-03 01:19:52 +00:00
|
|
|
"Hey @fred, I'm here"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sorts them to go from back to front', () => {
|
|
|
|
const bodyRanges = [
|
|
|
|
{
|
|
|
|
length: 1,
|
|
|
|
mentionUuid: 'blarg',
|
|
|
|
replacementText: 'jerry',
|
2022-11-10 04:59:36 +00:00
|
|
|
conversationID: 'x',
|
2020-11-03 01:19:52 +00:00
|
|
|
start: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
length: 1,
|
|
|
|
mentionUuid: 'abcdef',
|
|
|
|
replacementText: 'fred',
|
2022-11-10 04:59:36 +00:00
|
|
|
conversationID: 'x',
|
2020-11-03 01:19:52 +00:00
|
|
|
start: 7,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const text = "\uFFFC says \uFFFC, I'm here";
|
2022-01-19 19:19:08 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getTextWithMentions(bodyRanges, text),
|
2020-11-03 01:19:52 +00:00
|
|
|
"@jerry says @fred, I'm here"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|