Files
cinny/src/app/plugins/utils.test.ts
T

40 lines
1.5 KiB
TypeScript
Raw Normal View History

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { getEmoticonSearchStr } from './utils';
import { PackImageReader } from './custom-emoji';
import { IEmoji } from './emoji';
test('getEmoticonSearchStr for a PackImageReader with a body returns shortcode + body', () => {
const reader = new PackImageReader('cat', 'mxc://server/cat', { body: 'kitten' });
assert.deepEqual(getEmoticonSearchStr(reader), [':cat:', 'kitten']);
});
test('getEmoticonSearchStr for a PackImageReader without a body returns just the shortcode string', () => {
const reader = new PackImageReader('cat', 'mxc://server/cat', {});
assert.equal(getEmoticonSearchStr(reader), ':cat:');
});
test('getEmoticonSearchStr ignores a non-string body on a PackImageReader', () => {
const reader = new PackImageReader('cat', 'mxc://server/cat', {
body: 123 as unknown as string,
});
assert.equal(getEmoticonSearchStr(reader), ':cat:');
});
test('getEmoticonSearchStr for an IEmoji concats shortcode, label and shortcodes', () => {
const emoji = {
shortcode: 'smile',
label: 'Smiling Face',
shortcodes: ['smile', 'happy'],
} as unknown as IEmoji;
assert.deepEqual(getEmoticonSearchStr(emoji), [':smile:', 'Smiling Face', 'smile', 'happy']);
});
test('getEmoticonSearchStr for an IEmoji without a shortcodes array returns shortcode + label', () => {
const emoji = {
shortcode: 'smile',
label: 'Smiling Face',
} as unknown as IEmoji;
assert.deepEqual(getEmoticonSearchStr(emoji), [':smile:', 'Smiling Face']);
});