Fix giphy rendering issue. Closes #291.

This commit is contained in:
Jack Kingsman
2026-07-08 17:23:51 -07:00
parent 4385ea5703
commit f9b991b1a8
3 changed files with 108 additions and 8 deletions
@@ -10,6 +10,7 @@ import {
giphyUrlForId,
parseGif,
parseReaction,
splitReplyMention,
} from '../utils/meshcoreOpenPayloads';
describe('parseGif', () => {
@@ -79,3 +80,41 @@ describe('parseReaction', () => {
}
});
});
describe('splitReplyMention', () => {
it('splits a reply-prefixed gif into mention + body (issue #291)', () => {
// meshcore-open sends GIF replies as "@[senderName] g:<id>".
expect(splitReplyMention('@[Alice] g:abc123')).toEqual({
mention: '@[Alice]',
body: 'g:abc123',
});
});
it('the split body parses as a gif while the whole string does not', () => {
const whole = '@[Alice] g:abc123';
expect(parseGif(whole)).toBeNull(); // anchored regex rejects the prefix
const split = splitReplyMention(whole);
expect(split && parseGif(split.body)).toBe('abc123');
});
it('splits a reply-prefixed reaction', () => {
expect(splitReplyMention('@[Bob] r:1a2b:00')).toEqual({
mention: '@[Bob]',
body: 'r:1a2b:00',
});
});
it('trims surrounding whitespace and preserves names with spaces', () => {
expect(splitReplyMention(' @[Node One] g:xy ')).toEqual({
mention: '@[Node One]',
body: 'g:xy',
});
});
it('returns null without a leading reply mention', () => {
expect(splitReplyMention('g:abc123')).toBeNull();
expect(splitReplyMention('hello world')).toBeNull();
expect(splitReplyMention('@[Alice]')).toBeNull(); // mention only, no body
expect(splitReplyMention('text @[Alice] g:abc')).toBeNull(); // not a leading mention
});
});