From fc151bda05735b1c7f4b25bb26a9216e4a3aee6c Mon Sep 17 00:00:00 2001 From: Tasso Date: Wed, 14 Aug 2024 16:35:36 -0300 Subject: [PATCH] Add failing emoji test --- packages/message-parser/tests/emoji.test.ts | 164 ++++++++++---------- yarn.lock | 18 +++ 2 files changed, 102 insertions(+), 80 deletions(-) diff --git a/packages/message-parser/tests/emoji.test.ts b/packages/message-parser/tests/emoji.test.ts index 3d64e59a2c3cb..af3ea581f26c1 100644 --- a/packages/message-parser/tests/emoji.test.ts +++ b/packages/message-parser/tests/emoji.test.ts @@ -1,90 +1,94 @@ import { parse } from '../src'; import { emoji, bigEmoji, paragraph, plain, emojiUnicode } from '../src/utils'; -test.each([ - [':smile: asd', [paragraph([emoji('smile'), plain(' asd')])]], - ['text:inner:outer', [paragraph([plain('text:inner:outer')])]], - ['10:20:30', [paragraph([plain('10:20:30')])]], - ['10:20:30:', [paragraph([plain('10:20:30:')])]], - ['":smile:"', [paragraph([plain('":smile:"')])]], - ['":smile: "', [paragraph([plain('":smile: "')])]], - ['" :smile: "', [paragraph([plain('" '), emoji('smile'), plain(' "')])]], - [ - `:smile: +describe('short-code emojis', () => { + test.each([ + [':smile: asd', [paragraph([emoji('smile'), plain(' asd')])]], + ['text:inner:outer', [paragraph([plain('text:inner:outer')])]], + ['10:20:30', [paragraph([plain('10:20:30')])]], + ['10:20:30:', [paragraph([plain('10:20:30:')])]], + ['":smile:"', [paragraph([plain('":smile:"')])]], + ['":smile: "', [paragraph([plain('":smile: "')])]], + ['" :smile: "', [paragraph([plain('" '), emoji('smile'), plain(' "')])]], + [ + `:smile: :smile: `, - [bigEmoji([emoji('smile'), emoji('smile')])], - ], - [ - 'asdas :smile: asd', - [paragraph([plain('asdas '), emoji('smile'), plain(' asd')])], - ], - [ - 'normal emojis :smile: :smile: :smile:', + [bigEmoji([emoji('smile'), emoji('smile')])], + ], + [ + 'asdas :smile: asd', + [paragraph([plain('asdas '), emoji('smile'), plain(' asd')])], + ], + [ + 'normal emojis :smile: :smile: :smile:', + [ + paragraph([ + plain('normal emojis '), + emoji('smile'), + plain(' '), + emoji('smile'), + plain(' '), + emoji('smile'), + ]), + ], + ], + [ + ':smile::smile::smile:', + [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], + ], [ - paragraph([ - plain('normal emojis '), - emoji('smile'), - plain(' '), - emoji('smile'), - plain(' '), - emoji('smile'), - ]), + ' :smile::smile::smile: ', + [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], ], - ], - [ - ':smile::smile::smile:', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - ' :smile::smile::smile: ', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - '\n :smile::smile::smile: \n', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [ - ':smile: :smile: :smile:', - [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], - ], - [':smile::smile:', [bigEmoji([emoji('smile'), emoji('smile')])]], - [':smile:', [bigEmoji([emoji('smile')])]], - ['Hi :+1:', [paragraph([plain('Hi '), emoji('+1')])]], - ['Hi :+1_tone4:', [paragraph([plain('Hi '), emoji('+1_tone4')])]], -])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); + [ + '\n :smile::smile::smile: \n', + [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], + ], + [ + ':smile: :smile: :smile:', + [bigEmoji([emoji('smile'), emoji('smile'), emoji('smile')])], + ], + [':smile::smile:', [bigEmoji([emoji('smile'), emoji('smile')])]], + [':smile:', [bigEmoji([emoji('smile')])]], + ['Hi :+1:', [paragraph([plain('Hi '), emoji('+1')])]], + ['Hi :+1_tone4:', [paragraph([plain('Hi '), emoji('+1_tone4')])]], + [':+1:?', [paragraph([emoji('+1'), plain('?')])]], + ])('parses %p', (input, output) => { + expect(parse(input)).toMatchObject(output); + }); }); -// Tests for unicode emojis -test.each([ - ['๐Ÿ˜€', [bigEmoji([emojiUnicode('๐Ÿ˜€')])]], - ['๐Ÿ˜ƒ', [bigEmoji([emojiUnicode('๐Ÿ˜ƒ')])]], - ['๐Ÿฅต', [bigEmoji([emojiUnicode('๐Ÿฅต')])]], - ['๐Ÿงฟ', [bigEmoji([emojiUnicode('๐Ÿงฟ')])]], - ['๐Ÿถ', [bigEmoji([emojiUnicode('๐Ÿถ')])]], - ['๐Ÿ', [bigEmoji([emojiUnicode('๐Ÿ')])]], - ['โšฝ', [bigEmoji([emojiUnicode('โšฝ')])]], - ['โšฝ๏ธ', [bigEmoji([emojiUnicode('โšฝ๏ธ')])]], - ['๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ', [bigEmoji([emojiUnicode('๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ')])]], - ['๐Ÿš—', [bigEmoji([emojiUnicode('๐Ÿš—')])]], - ['โŒš๏ธ', [bigEmoji([emojiUnicode('โŒš๏ธ')])]], - ['โค๏ธ', [bigEmoji([emojiUnicode('โค๏ธ')])]], - ['๐Ÿณ๏ธ', [bigEmoji([emojiUnicode('๐Ÿณ๏ธ')])]], - ['๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])]], - ['๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])]], - [ - '๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', - [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])], - ], - ['๐Ÿ‘†๐Ÿฝ', [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ')])]], - ['๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ', [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ')])]], - [ - '๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ', - [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ')])], - ], - ['๐Ÿ‘†๐Ÿบ', [bigEmoji([emojiUnicode('๐Ÿ‘†'), emojiUnicode('๐Ÿบ')])]], - ['Hi ๐Ÿ‘', [paragraph([plain('Hi '), emojiUnicode('๐Ÿ‘')])]], -])('parses %p', (input, output) => { - expect(parse(input)).toMatchObject(output); +describe('unicode emojis', () => { + test.each([ + ['๐Ÿ˜€', [bigEmoji([emojiUnicode('๐Ÿ˜€')])]], + ['๐Ÿ˜ƒ', [bigEmoji([emojiUnicode('๐Ÿ˜ƒ')])]], + ['๐Ÿฅต', [bigEmoji([emojiUnicode('๐Ÿฅต')])]], + ['๐Ÿงฟ', [bigEmoji([emojiUnicode('๐Ÿงฟ')])]], + ['๐Ÿถ', [bigEmoji([emojiUnicode('๐Ÿถ')])]], + ['๐Ÿ', [bigEmoji([emojiUnicode('๐Ÿ')])]], + ['โšฝ', [bigEmoji([emojiUnicode('โšฝ')])]], + ['โšฝ๏ธ', [bigEmoji([emojiUnicode('โšฝ๏ธ')])]], + ['๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ', [bigEmoji([emojiUnicode('๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ')])]], + ['๐Ÿš—', [bigEmoji([emojiUnicode('๐Ÿš—')])]], + ['โŒš๏ธ', [bigEmoji([emojiUnicode('โŒš๏ธ')])]], + ['โค๏ธ', [bigEmoji([emojiUnicode('โค๏ธ')])]], + ['๐Ÿณ๏ธ', [bigEmoji([emojiUnicode('๐Ÿณ๏ธ')])]], + ['๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])]], + ['๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])]], + [ + '๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป๐Ÿง‘๐Ÿพโ€๐Ÿ’ป', + [bigEmoji([emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป'), emojiUnicode('๐Ÿง‘๐Ÿพโ€๐Ÿ’ป')])], + ], + ['๐Ÿ‘†๐Ÿฝ', [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ')])]], + ['๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ', [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ')])]], + [ + '๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ๐Ÿ‘†๐Ÿฝ', + [bigEmoji([emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ'), emojiUnicode('๐Ÿ‘†๐Ÿฝ')])], + ], + ['๐Ÿ‘†๐Ÿบ', [bigEmoji([emojiUnicode('๐Ÿ‘†'), emojiUnicode('๐Ÿบ')])]], + ['Hi ๐Ÿ‘', [paragraph([plain('Hi '), emojiUnicode('๐Ÿ‘')])]], + ])('parses %p', (input, output) => { + expect(parse(input)).toMatchObject(output); + }); }); diff --git a/yarn.lock b/yarn.lock index 65ebae84019b7..6aa5998a1f690 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8992,6 +8992,7 @@ __metadata: "@storybook/react": ~6.5.16 "@storybook/testing-library": ~0.0.13 "@testing-library/react": ~16.0.0 + "@types/dompurify": ^3.0.5 "@types/jest": ~29.5.12 "@types/katex": ~0.16.5 "@types/react": ~17.0.69 @@ -9000,6 +9001,7 @@ __metadata: "@typescript-eslint/parser": ~5.60.1 babel-loader: ^8.3.0 date-fns: ^3.3.1 + dompurify: ^3.1.6 eslint: ~8.45.0 eslint-plugin-anti-trojan-source: ~1.1.1 eslint-plugin-react: ~7.32.2 @@ -13382,6 +13384,15 @@ __metadata: languageName: node linkType: hard +"@types/dompurify@npm:^3.0.5": + version: 3.0.5 + resolution: "@types/dompurify@npm:3.0.5" + dependencies: + "@types/trusted-types": "*" + checksum: ffc34eca6a4536e1c8c16a47cce2623c5a118a9785492e71230052d92933ff096d14326ff449031e8dfaac509413222372d8f2b28786a13159de6241df716185 + languageName: node + linkType: hard + "@types/ejson@npm:^2.2.1": version: 2.2.1 resolution: "@types/ejson@npm:2.2.1" @@ -21370,6 +21381,13 @@ __metadata: languageName: node linkType: hard +"dompurify@npm:^3.1.6": + version: 3.1.6 + resolution: "dompurify@npm:3.1.6" + checksum: cc4fc4ccd9261fbceb2a1627a985c70af231274a26ddd3f643fd0616a0a44099bd9e4480940ce3655612063be4a1fe9f5e9309967526f8c0a99f931602323866 + languageName: node + linkType: hard + "domutils@npm:^1.7.0": version: 1.7.0 resolution: "domutils@npm:1.7.0"