From 590e85ac596d98c86eaff60066c0c7c2ccc262dc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 6 Jul 2022 12:24:45 -0500 Subject: [PATCH] Fix notification test types --- app/soapbox/components/status.tsx | 2 -- .../__tests__/notification.test.tsx | 16 ++++++---- .../notifications/components/notification.tsx | 32 +++++++++---------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/soapbox/components/status.tsx b/app/soapbox/components/status.tsx index 200b2de10..90d7e13df 100644 --- a/app/soapbox/components/status.tsx +++ b/app/soapbox/components/status.tsx @@ -84,8 +84,6 @@ interface IStatus extends RouteComponentProps { onMoveDown: (statusId: string, featured?: boolean) => void, getScrollPosition?: () => ScrollPosition | undefined, updateScrollBottom?: (bottom: number) => void, - cacheMediaWidth: () => void, - cachedMediaWidth: number, group: ImmutableMap, displayMedia: string, allowedEmoji: ImmutableList, diff --git a/app/soapbox/features/notifications/components/__tests__/notification.test.tsx b/app/soapbox/features/notifications/components/__tests__/notification.test.tsx index 14c43f50c..eacca0f99 100644 --- a/app/soapbox/features/notifications/components/__tests__/notification.test.tsx +++ b/app/soapbox/features/notifications/components/__tests__/notification.test.tsx @@ -33,10 +33,12 @@ describe('', () => { describe('grouped notifications', () => { it('renders a grouped follow notification for more than 2', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); - const groupedNotification = { ...notification.toJS(), total_count: 5 }; + const { notification, state } = normalize({ + ...require('soapbox/__fixtures__/notification-follow.json'), + total_count: 5, + }); - render(, undefined, state); + render(, undefined, state); expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); @@ -44,10 +46,12 @@ describe('', () => { }); it('renders a grouped follow notification for 1', async() => { - const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); - const groupedNotification = { ...notification.toJS(), total_count: 2 }; + const { notification, state } = normalize({ + ...require('soapbox/__fixtures__/notification-follow.json'), + total_count: 2, + }); - render(, undefined, state); + render(, undefined, state); expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); diff --git a/app/soapbox/features/notifications/components/notification.tsx b/app/soapbox/features/notifications/components/notification.tsx index dda887919..4b67e5645 100644 --- a/app/soapbox/features/notifications/components/notification.tsx +++ b/app/soapbox/features/notifications/components/notification.tsx @@ -128,16 +128,14 @@ const buildMessage = ( interface INotificaton { hidden?: boolean, notification: NotificationEntity, - onMoveUp: (notificationId: string) => void, - onMoveDown: (notificationId: string) => void, - onMention: (account: Account) => void, - onFavourite: (status: Status) => void, - onReblog: (status: Status, e?: KeyboardEvent) => void, - onToggleHidden: (status: Status) => void, + onMoveUp?: (notificationId: string) => void, + onMoveDown?: (notificationId: string) => void, + onMention?: (account: Account) => void, + onFavourite?: (status: Status) => void, + onReblog?: (status: Status, e?: KeyboardEvent) => void, + onToggleHidden?: (status: Status) => void, getScrollPosition?: () => ScrollPosition | undefined, updateScrollBottom?: (bottom: number) => void, - cacheMediaWidth: () => void, - cachedMediaWidth: number, siteTitle?: string, } @@ -180,35 +178,39 @@ const Notification: React.FC = (props) => { const handleMention = (e?: KeyboardEvent) => { e?.preventDefault(); - if (account && typeof account === 'object') { + if (props.onMention && account && typeof account === 'object') { props.onMention(account); } }; const handleHotkeyFavourite = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onFavourite && status && typeof status === 'object') { props.onFavourite(status); } }; const handleHotkeyBoost = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onReblog && status && typeof status === 'object') { props.onReblog(status, e); } }; const handleHotkeyToggleHidden = (e?: KeyboardEvent) => { - if (status && typeof status === 'object') { + if (props.onToggleHidden && status && typeof status === 'object') { props.onToggleHidden(status); } }; const handleMoveUp = () => { - onMoveUp(notification.id); + if (onMoveUp) { + onMoveUp(notification.id); + } }; const handleMoveDown = () => { - onMoveDown(notification.id); + if (onMoveDown) { + onMoveDown(notification.id); + } }; const renderIcon = (): React.ReactNode => { @@ -268,8 +270,6 @@ const Notification: React.FC = (props) => { contextType='notifications' getScrollPosition={props.getScrollPosition} updateScrollBottom={props.updateScrollBottom} - cachedMediaWidth={props.cachedMediaWidth} - cacheMediaWidth={props.cacheMediaWidth} /> ) : null; default: