import { hasMessageText, stripEmptyTextCharacters } from '../message_text' const EMPTY = '\uFFFC' describe('stripEmptyTextCharacters', () => { it.each([ ['leaves ordinary text alone', 'Come on over after.', 'Come on over after.'], [ 'removes a trailing pair', `Yes. Come on over after.${EMPTY}${EMPTY}`, 'Yes. Come on over after.', ], ['removes one mid-string', `before${EMPTY}after`, 'beforeafter'], ['reduces an all-empty body to an empty string', EMPTY, ''], ['reduces a repeated all-empty body to an empty string', `${EMPTY}${EMPTY}${EMPTY}`, ''], ['leaves an empty string alone', '', ''], ])('%s', (_name, input, expected) => { expect(stripEmptyTextCharacters(input)).toBe(expected) }) it('does not disturb emoji or other multi-byte text', () => { expect(stripEmptyTextCharacters(`👋 hi${EMPTY}`)).toBe('👋 hi') }) }) describe('hasMessageText', () => { it.each([ ['ordinary text', 'hello', true], ['text alongside an empty character', `hello${EMPTY}`, true], ['only an empty character', EMPTY, false], ['several empty characters', `${EMPTY}${EMPTY}`, false], ['an empty character surrounded by whitespace', ` ${EMPTY} `, false], ['whitespace only', ' ', false], ['empty string', '', false], ['undefined', undefined, false], ['null', null, false], ])('%s -> %s', (_name, input, expected) => { expect(hasMessageText(input)).toBe(expected) }) it('is not fooled by trim alone, which does not treat the character as whitespace', () => { expect(EMPTY.trim()).toBe(EMPTY) expect(hasMessageText(EMPTY)).toBe(false) }) })