From 6cd187eb369d6e21d99645839aa1a64a8be1487e Mon Sep 17 00:00:00 2001 From: ChaosExAnima Date: Mon, 29 Sep 2025 16:28:44 +0200 Subject: [PATCH] fix tests --- .../mastodon/features/emoji/normalize.test.ts | 23 ---- .../mastodon/features/emoji/render.test.ts | 101 ++---------------- 2 files changed, 6 insertions(+), 118 deletions(-) diff --git a/app/javascript/mastodon/features/emoji/normalize.test.ts b/app/javascript/mastodon/features/emoji/normalize.test.ts index 6bf493b38e0..b4c76699611 100644 --- a/app/javascript/mastodon/features/emoji/normalize.test.ts +++ b/app/javascript/mastodon/features/emoji/normalize.test.ts @@ -5,11 +5,8 @@ import { flattenEmojiData } from 'emojibase'; import unicodeRawEmojis from 'emojibase-data/en/data.json'; import { - unicodeHexToUrl, twemojiToUnicodeInfo, unicodeToTwemojiHex, - CODES_WITH_DARK_BORDER, - CODES_WITH_LIGHT_BORDER, emojiToUnicodeHex, } from './normalize'; @@ -57,26 +54,6 @@ describe('unicodeToTwemojiHex', () => { }); }); -describe('twemojiHasBorder', () => { - test.concurrent.for( - svgFileNames - .filter((file) => file.endsWith('_border')) - .map((file) => { - const hexCode = file.replace('_border', ''); - return [ - hexCode, - CODES_WITH_LIGHT_BORDER.includes(hexCode.toUpperCase()), - CODES_WITH_DARK_BORDER.includes(hexCode.toUpperCase()), - ] as const; - }), - )('twemojiHasBorder for %s', ([hexCode, isLight, isDark], { expect }) => { - const result = unicodeHexToUrl(hexCode, isDark); - expect(result).toHaveProperty('hexCode', hexCode); - expect(result).toHaveProperty('hasLightBorder', isLight); - expect(result).toHaveProperty('hasDarkBorder', isDark); - }); -}); - describe('twemojiToUnicodeInfo', () => { const unicodeCodeSet = new Set(unicodeEmojis.map((emoji) => emoji.hexcode)); diff --git a/app/javascript/mastodon/features/emoji/render.test.ts b/app/javascript/mastodon/features/emoji/render.test.ts index e9609e15dc5..108cf747504 100644 --- a/app/javascript/mastodon/features/emoji/render.test.ts +++ b/app/javascript/mastodon/features/emoji/render.test.ts @@ -1,10 +1,6 @@ import { customEmojiFactory, unicodeEmojiFactory } from '@/testing/factories'; -import { - EMOJI_MODE_NATIVE, - EMOJI_MODE_NATIVE_WITH_FLAGS, - EMOJI_MODE_TWEMOJI, -} from './constants'; +import { EMOJI_MODE_TWEMOJI } from './constants'; import * as db from './database'; import { emojifyElement, @@ -12,7 +8,7 @@ import { testCacheClear, tokenizeText, } from './render'; -import type { EmojiAppState, ExtraCustomEmojiMap } from './types'; +import type { EmojiAppState } from './types'; function mockDatabase() { return { @@ -40,18 +36,6 @@ const expectedSmileImage = '😊'; const expectedFlagImage = '🇪🇺'; -const expectedCustomEmojiImage = - ':custom:'; -const expectedRemoteCustomEmojiImage = - ':remote:'; - -const mockExtraCustom: ExtraCustomEmojiMap = { - remote: { - shortcode: 'remote', - static_url: 'remote.social/static', - url: 'remote.social/custom', - }, -}; function testAppState(state: Partial = {}) { return { @@ -86,64 +70,10 @@ describe('emojifyElement', () => { 'en', ); expect(searchCustomEmojisByShortcodes).toHaveBeenCalledExactlyOnceWith([ - 'custom', + ':custom:', ]); }); - test('emojifies custom emoji in native mode', async () => { - const { searchEmojisByHexcodes } = mockDatabase(); - const actual = await emojifyElement( - testElement(), - testAppState({ mode: EMOJI_MODE_NATIVE }), - ); - assert(actual); - expect(actual.innerHTML).toBe( - `

Hello 😊🇪🇺!

${expectedCustomEmojiImage}

`, - ); - expect(searchEmojisByHexcodes).not.toHaveBeenCalled(); - }); - - test('emojifies flag emoji in native-with-flags mode', async () => { - const { searchEmojisByHexcodes } = mockDatabase(); - const actual = await emojifyElement( - testElement(), - testAppState({ mode: EMOJI_MODE_NATIVE_WITH_FLAGS }), - ); - assert(actual); - expect(actual.innerHTML).toBe( - `

Hello 😊${expectedFlagImage}!

${expectedCustomEmojiImage}

`, - ); - expect(searchEmojisByHexcodes).toHaveBeenCalledOnce(); - }); - - test('emojifies everything in twemoji mode', async () => { - const { searchCustomEmojisByShortcodes, searchEmojisByHexcodes } = - mockDatabase(); - const actual = await emojifyElement(testElement(), testAppState()); - assert(actual); - expect(actual.innerHTML).toBe( - `

Hello ${expectedSmileImage}${expectedFlagImage}!

${expectedCustomEmojiImage}

`, - ); - expect(searchEmojisByHexcodes).toHaveBeenCalledOnce(); - expect(searchCustomEmojisByShortcodes).toHaveBeenCalledOnce(); - }); - - test('emojifies with provided custom emoji', async () => { - const { searchCustomEmojisByShortcodes, searchEmojisByHexcodes } = - mockDatabase(); - const actual = await emojifyElement( - testElement('

hi :remote:

'), - testAppState(), - mockExtraCustom, - ); - assert(actual); - expect(actual.innerHTML).toBe( - `

hi ${expectedRemoteCustomEmojiImage}

`, - ); - expect(searchEmojisByHexcodes).not.toHaveBeenCalled(); - expect(searchCustomEmojisByShortcodes).not.toHaveBeenCalled(); - }); - test('returns null when no emoji are found', async () => { mockDatabase(); const actual = await emojifyElement( @@ -165,28 +95,9 @@ describe('emojifyText', () => { const actual = await emojifyText('Hello 😊🇪🇺!', testAppState()); expect(actual).toBe(`Hello ${expectedSmileImage}${expectedFlagImage}!`); }); - - test('renders custom emojis', async () => { - mockDatabase(); - const actual = await emojifyText('Hello :custom:!', testAppState()); - expect(actual).toBe(`Hello ${expectedCustomEmojiImage}!`); - }); - - test('renders provided extra emojis', async () => { - const actual = await emojifyText( - 'remote emoji :remote:', - testAppState(), - mockExtraCustom, - ); - expect(actual).toBe(`remote emoji ${expectedRemoteCustomEmojiImage}`); - }); }); describe('tokenizeText', () => { - test('returns empty array for string with only whitespace', () => { - expect(tokenizeText(' \n')).toEqual([]); - }); - test('returns an array of text to be a single token', () => { expect(tokenizeText('Hello')).toEqual(['Hello']); }); @@ -212,7 +123,7 @@ describe('tokenizeText', () => { 'Hello ', { type: 'custom', - code: 'smile', + code: ':smile:', }, '!!', ]); @@ -223,7 +134,7 @@ describe('tokenizeText', () => { 'Hello ', { type: 'custom', - code: 'smile_123', + code: ':smile_123:', }, '!!', ]); @@ -239,7 +150,7 @@ describe('tokenizeText', () => { ' ', { type: 'custom', - code: 'smile', + code: ':smile:', }, '!!', ]);