From 5424242b0f5279a8a30b01b6f61ef582de05ef60 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 28 Feb 2018 21:03:21 -0800 Subject: [PATCH] fix emoji insertion --- routes/_actions/emoji.js | 6 +++--- tests/spec/12-compose.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js index e004005f..89da8601 100644 --- a/routes/_actions/emoji.js +++ b/routes/_actions/emoji.js @@ -19,9 +19,9 @@ export async function updateCustomEmojiForInstance (instanceName) { export function insertEmoji (emoji) { let idx = store.get('composeSelectionStart') || 0 - let oldText = store.get('rawComposeText') - let pre = substring(oldText, 0, idx) - let post = substring(oldText, idx) + let oldText = store.get('rawComposeText') || '' + let pre = oldText ? substring(oldText, 0, idx) : '' + let post = oldText ? substring(oldText, idx) : '' let newText = `${pre}:${emoji.shortcode}: ${post}` store.set({ rawComposeText: newText diff --git a/tests/spec/12-compose.js b/tests/spec/12-compose.js index d8077da8..588bea2e 100644 --- a/tests/spec/12-compose.js +++ b/tests/spec/12-compose.js @@ -81,3 +81,13 @@ test('inserts custom emoji correctly', async t => { .click($('button img[title=":blobpeek:"]')) .expect(composeInput.value).eql(':blobnom: hello :blobpats: world foobar :blobpeek: ') }) + +test('inserts emoji without typing anything', async t => { + await t.useRole(foobarRole) + .click(emojiButton) + .click($('button img[title=":blobpats:"]')) + .expect(composeInput.value).eql(':blobpats: ') + .click(emojiButton) + .click($('button img[title=":blobpeek:"]')) + .expect(composeInput.value).eql(':blobpeek: :blobpats: ') +})