From c703945350e79aa53c4c64e0f0f673f0a6fd95b2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 12:38:27 +0300 Subject: [PATCH] fix emoji processor not leaving string as-is if no emoji are found --- .../mini_html_converter.service.js | 1 + .../mini_post_html_processor.spec.js | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/services/mini_html_converter/mini_html_converter.service.js b/src/services/mini_html_converter/mini_html_converter.service.js index 00d20019..879ff544 100644 --- a/src/services/mini_html_converter/mini_html_converter.service.js +++ b/src/services/mini_html_converter/mini_html_converter.service.js @@ -118,6 +118,7 @@ export const processTextForEmoji = (text, emojis, processor) => { textBuffer += char } } + if (textBuffer) buffer.push(textBuffer) return buffer } diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js index 41818f57..c4e3f688 100644 --- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -57,7 +57,7 @@ describe('MiniHtmlConverter', () => { ] ]) }) - it('realistic case', () => { + it('realistic case 1', () => { const inputOutput = '

@benis @hj nice

' expect(convertHtml(inputOutput)).to.eql([ [ @@ -110,6 +110,24 @@ describe('MiniHtmlConverter', () => { ] ]) }) + it('realistic case 2', () => { + const inputOutput = 'Country improv: give me a city
Audience: Memphis
Improv troupe: come on, a better one
Audience: el paso' + expect(convertHtml(inputOutput)).to.eql([ + 'Country improv: give me a city', + [ + '
' + ], + 'Audience: Memphis', + [ + '
' + ], + 'Improv troupe: come on, a better one', + [ + '
' + ], + 'Audience: el paso' + ]) + }) }) describe('processTextForEmoji', () => { it('processes all emoji in text', () => { @@ -126,5 +144,14 @@ describe('MiniHtmlConverter', () => { { shortcode: 'lmao', src: 'LMAO' } ]) }) + it('leaves text as is', () => { + const inputOutput = 'Number one: that\'s terror' + const emojis = [] + const processor = ({ shortcode, src }) => ({ shortcode, src }) + expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([ + 'Number one: that\'s terror' + ]) + }) + }) }) })