Add localized emoji search
This commit is contained in:
parent
ce0fb22041
commit
e90553b3b3
17 changed files with 878 additions and 97 deletions
|
@ -5,7 +5,7 @@ import { assert } from 'chai';
|
|||
import sinon from 'sinon';
|
||||
|
||||
import { EmojiCompletion } from '../../../quill/emoji/completion';
|
||||
import type { EmojiData } from '../../../components/emoji/lib';
|
||||
import { createSearch } from '../../../components/emoji/lib';
|
||||
|
||||
describe('emojiCompletion', () => {
|
||||
let emojiCompletion: EmojiCompletion;
|
||||
|
@ -27,6 +27,10 @@ describe('emojiCompletion', () => {
|
|||
onPickEmoji: sinon.stub(),
|
||||
setEmojiPickerElement: sinon.stub(),
|
||||
skinTone: 0,
|
||||
search: createSearch([
|
||||
{ shortName: 'smile', tags: [], rank: 0 },
|
||||
{ shortName: 'smile_cat', tags: [], rank: 0 },
|
||||
]),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
@ -52,13 +56,12 @@ describe('emojiCompletion', () => {
|
|||
|
||||
describe('onTextChange', () => {
|
||||
let insertEmojiStub: sinon.SinonStub<
|
||||
[EmojiData, number, number, (boolean | undefined)?],
|
||||
[string, number, number, (boolean | undefined)?],
|
||||
void
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
emojiCompletion.results = [{ short_name: 'joy' } as any];
|
||||
emojiCompletion.results = ['joy'];
|
||||
emojiCompletion.index = 5;
|
||||
insertEmojiStub = sinon
|
||||
.stub(emojiCompletion, 'insertEmoji')
|
||||
|
@ -165,7 +168,7 @@ describe('emojiCompletion', () => {
|
|||
});
|
||||
|
||||
it('stores the results and renders', () => {
|
||||
assert.equal(emojiCompletion.results.length, 10);
|
||||
assert.equal(emojiCompletion.results.length, 2);
|
||||
assert.equal((emojiCompletion.render as sinon.SinonStub).called, true);
|
||||
});
|
||||
});
|
||||
|
@ -193,7 +196,7 @@ describe('emojiCompletion', () => {
|
|||
it('inserts the emoji at the current cursor position', () => {
|
||||
const [emoji, index, range] = insertEmojiStub.args[0];
|
||||
|
||||
assert.equal(emoji.short_name, 'smile');
|
||||
assert.equal(emoji, 'smile');
|
||||
assert.equal(index, 0);
|
||||
assert.equal(range, 7);
|
||||
});
|
||||
|
@ -222,7 +225,7 @@ describe('emojiCompletion', () => {
|
|||
it('inserts the emoji at the current cursor position', () => {
|
||||
const [emoji, index, range] = insertEmojiStub.args[0];
|
||||
|
||||
assert.equal(emoji.short_name, 'smile');
|
||||
assert.equal(emoji, 'smile');
|
||||
assert.equal(index, 7);
|
||||
assert.equal(range, 7);
|
||||
});
|
||||
|
@ -282,7 +285,7 @@ describe('emojiCompletion', () => {
|
|||
it('inserts the emoji at the current cursor position', () => {
|
||||
const [emoji, index, range] = insertEmojiStub.args[0];
|
||||
|
||||
assert.equal(emoji.short_name, 'smile');
|
||||
assert.equal(emoji, 'smile');
|
||||
assert.equal(index, 0);
|
||||
assert.equal(range, validEmoji.length);
|
||||
});
|
||||
|
@ -331,7 +334,7 @@ describe('emojiCompletion', () => {
|
|||
it('inserts the emoji at the current cursor position', () => {
|
||||
const [emoji, index, range] = insertEmojiStub.args[0];
|
||||
|
||||
assert.equal(emoji.short_name, 'smile');
|
||||
assert.equal(emoji, 'smile');
|
||||
assert.equal(index, 0);
|
||||
assert.equal(range, 6);
|
||||
});
|
||||
|
@ -345,17 +348,12 @@ describe('emojiCompletion', () => {
|
|||
|
||||
describe('completeEmoji', () => {
|
||||
let insertEmojiStub: sinon.SinonStub<
|
||||
[EmojiData, number, number, (boolean | undefined)?],
|
||||
[string, number, number, (boolean | undefined)?],
|
||||
void
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
emojiCompletion.results = [
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{ short_name: 'smile' } as any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{ short_name: 'smile_cat' } as any,
|
||||
];
|
||||
emojiCompletion.results = ['smile', 'smile_cat'];
|
||||
emojiCompletion.index = 1;
|
||||
insertEmojiStub = sinon.stub(emojiCompletion, 'insertEmoji');
|
||||
});
|
||||
|
@ -381,7 +379,7 @@ describe('emojiCompletion', () => {
|
|||
it('inserts the currently selected emoji at the current cursor position', () => {
|
||||
const [emoji, insertIndex, range] = insertEmojiStub.args[0];
|
||||
|
||||
assert.equal(emoji.short_name, 'smile_cat');
|
||||
assert.equal(emoji, 'smile_cat');
|
||||
assert.equal(insertIndex, 0);
|
||||
assert.equal(range, text.length);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue