diff --git a/app/soapbox/components/status_action_bar.tsx b/app/soapbox/components/status_action_bar.tsx index 0b9bc9f9c..d2d3855bb 100644 --- a/app/soapbox/components/status_action_bar.tsx +++ b/app/soapbox/components/status_action_bar.tsx @@ -561,21 +561,26 @@ class StatusActionBar extends ImmutablePureComponent, favouriteCount, status.favourited, allowedEmoji, ).reduce((acc, cur) => acc + cur.get('count'), 0); - const meEmojiReact = getReactForStatus(status, allowedEmoji); - const meEmojiTitle = intl.formatMessage({ + + const meEmojiReact = getReactForStatus(status, allowedEmoji) as keyof typeof reactMessages | undefined; + + const reactMessages = { '👍': messages.reactionLike, '❤️': messages.reactionHeart, '😆': messages.reactionLaughing, '😮': messages.reactionOpenMouth, '😢': messages.reactionCry, '😩': messages.reactionWeary, - }[meEmojiReact] || messages.favourite); + }; + + const meEmojiTitle = intl.formatMessage(meEmojiReact ? reactMessages[meEmojiReact] : messages.favourite); const menu = this._makeMenu(publicStatus); let reblogIcon = require('@tabler/icons/icons/repeat.svg'); @@ -587,18 +592,15 @@ class StatusActionBar extends ImmutablePureComponent { -// const account = fromJS({ -// acct: 'alice', -// url: 'https://party.com/users/alice', -// }); -// it('returns the domain', () => { -// expect(getDomain(account)).toEqual('party.com'); -// }); -// }); +import { AccountRecord } from 'soapbox/normalizers'; + +import { + getDomain, +} from '../accounts'; + +describe('getDomain', () => { + const account = AccountRecord({ + acct: 'alice', + url: 'https://party.com/users/alice', + }); + it('returns the domain', () => { + expect(getDomain(account)).toEqual('party.com'); + }); +}); diff --git a/app/soapbox/utils/__tests__/emoji_reacts-test.js b/app/soapbox/utils/__tests__/emoji_reacts-test.js index c4b05960c..d67744fef 100644 --- a/app/soapbox/utils/__tests__/emoji_reacts-test.js +++ b/app/soapbox/utils/__tests__/emoji_reacts-test.js @@ -11,14 +11,14 @@ import { simulateUnEmojiReact, } from '../emoji_reacts'; -const ALLOWED_EMOJI = [ +const ALLOWED_EMOJI = fromJS([ '👍', '❤', '😂', '😯', '😢', '😡', -]; +]); describe('filterEmoji', () => { describe('with a mix of allowed and disallowed emoji', () => { @@ -168,7 +168,7 @@ describe('getReactForStatus', () => { }); it('returns undefined when a status has no reacts (or favourites)', () => { - const status = fromJS([]); + const status = fromJS({}); expect(getReactForStatus(status)).toEqual(undefined); }); diff --git a/app/soapbox/utils/emoji_reacts.ts b/app/soapbox/utils/emoji_reacts.ts index 3b3fc05d9..9662c8458 100644 --- a/app/soapbox/utils/emoji_reacts.ts +++ b/app/soapbox/utils/emoji_reacts.ts @@ -80,21 +80,23 @@ export const reduceEmoji = (emojiReacts: ImmutableList, favouritesCo emojiReacts, favouritesCount, favourited, ))), allowedEmoji)); -export const getReactForStatus = (status: any, allowedEmoji=ALLOWED_EMOJI): string => { - return String(reduceEmoji( +export const getReactForStatus = (status: any, allowedEmoji=ALLOWED_EMOJI): string | undefined => { + const result = reduceEmoji( status.getIn(['pleroma', 'emoji_reactions'], ImmutableList()), status.get('favourites_count', 0), status.get('favourited'), allowedEmoji, ).filter(e => e.get('me') === true) - .getIn([0, 'name'], '')); + .getIn([0, 'name']); + + return typeof result === 'string' ? result : undefined; }; export const simulateEmojiReact = (emojiReacts: ImmutableList, emoji: string) => { const idx = emojiReacts.findIndex(e => e.get('name') === emoji); const emojiReact = emojiReacts.get(idx); - if (emojiReact) { + if (idx > -1 && emojiReact) { return emojiReacts.set(idx, emojiReact.merge({ count: emojiReact.get('count') + 1, me: true,