Fix tests
This commit is contained in:
parent
cc1b478e3f
commit
d738e7d5bf
4 changed files with 41 additions and 37 deletions
|
@ -561,21 +561,26 @@ class StatusActionBar extends ImmutablePureComponent<IStatusActionBar, IStatusAc
|
|||
const replyCount = status.replies_count;
|
||||
const reblogCount = status.reblogs_count;
|
||||
const favouriteCount = status.favourites_count;
|
||||
|
||||
const emojiReactCount = reduceEmoji(
|
||||
(status.getIn(['pleroma', 'emoji_reactions']) || ImmutableList()) as ImmutableList<any>,
|
||||
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<IStatusActionBar, IStatusAc
|
|||
reblogIcon = require('@tabler/icons/icons/lock.svg');
|
||||
}
|
||||
|
||||
const reblogMenu = [
|
||||
{
|
||||
text: intl.formatMessage(status.reblogged ? messages.cancel_reblog_private : messages.reblog),
|
||||
action: this.handleReblogClick,
|
||||
icon: require('@tabler/icons/icons/repeat.svg'),
|
||||
},
|
||||
{
|
||||
text: intl.formatMessage(messages.quotePost),
|
||||
action: this.handleQuoteClick,
|
||||
icon: require('@tabler/icons/icons/quote.svg'),
|
||||
},
|
||||
];
|
||||
const reblogMenu = [{
|
||||
text: intl.formatMessage(status.reblogged ? messages.cancel_reblog_private : messages.reblog),
|
||||
action: this.handleReblogClick,
|
||||
icon: require('@tabler/icons/icons/repeat.svg'),
|
||||
}, {
|
||||
text: intl.formatMessage(messages.quotePost),
|
||||
action: this.handleQuoteClick,
|
||||
icon: require('@tabler/icons/icons/quote.svg'),
|
||||
}];
|
||||
|
||||
const reblogButton = (
|
||||
<StatusActionButton
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
// import { fromJS } from 'immutable';
|
||||
//
|
||||
// import {
|
||||
// getDomain,
|
||||
// } from '../accounts';
|
||||
//
|
||||
// describe('getDomain', () => {
|
||||
// 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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -80,21 +80,23 @@ export const reduceEmoji = (emojiReacts: ImmutableList<EmojiReact>, 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<EmojiReact>, 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,
|
||||
|
|
Loading…
Reference in a new issue