Fix notification test types

This commit is contained in:
Alex Gleason 2022-07-06 12:24:45 -05:00
parent bdf00bb692
commit 590e85ac59
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 26 additions and 24 deletions

View File

@ -84,8 +84,6 @@ interface IStatus extends RouteComponentProps {
onMoveDown: (statusId: string, featured?: boolean) => void, onMoveDown: (statusId: string, featured?: boolean) => void,
getScrollPosition?: () => ScrollPosition | undefined, getScrollPosition?: () => ScrollPosition | undefined,
updateScrollBottom?: (bottom: number) => void, updateScrollBottom?: (bottom: number) => void,
cacheMediaWidth: () => void,
cachedMediaWidth: number,
group: ImmutableMap<string, any>, group: ImmutableMap<string, any>,
displayMedia: string, displayMedia: string,
allowedEmoji: ImmutableList<string>, allowedEmoji: ImmutableList<string>,

View File

@ -33,10 +33,12 @@ describe('<Notification />', () => {
describe('grouped notifications', () => { describe('grouped notifications', () => {
it('renders a grouped follow notification for more than 2', async() => { it('renders a grouped follow notification for more than 2', async() => {
const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); const { notification, state } = normalize({
const groupedNotification = { ...notification.toJS(), total_count: 5 }; ...require('soapbox/__fixtures__/notification-follow.json'),
total_count: 5,
});
render(<Notification notification={groupedNotification} />, undefined, state); render(<Notification notification={notification} />, undefined, state);
expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('notification')).toBeInTheDocument();
expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc');
@ -44,10 +46,12 @@ describe('<Notification />', () => {
}); });
it('renders a grouped follow notification for 1', async() => { it('renders a grouped follow notification for 1', async() => {
const { notification, state } = normalize(require('soapbox/__fixtures__/notification-follow.json')); const { notification, state } = normalize({
const groupedNotification = { ...notification.toJS(), total_count: 2 }; ...require('soapbox/__fixtures__/notification-follow.json'),
total_count: 2,
});
render(<Notification notification={groupedNotification} />, undefined, state); render(<Notification notification={notification} />, undefined, state);
expect(screen.getByTestId('notification')).toBeInTheDocument(); expect(screen.getByTestId('notification')).toBeInTheDocument();
expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc'); expect(screen.getByTestId('account')).toContainHTML('neko@rdrama.cc');

View File

@ -128,16 +128,14 @@ const buildMessage = (
interface INotificaton { interface INotificaton {
hidden?: boolean, hidden?: boolean,
notification: NotificationEntity, notification: NotificationEntity,
onMoveUp: (notificationId: string) => void, onMoveUp?: (notificationId: string) => void,
onMoveDown: (notificationId: string) => void, onMoveDown?: (notificationId: string) => void,
onMention: (account: Account) => void, onMention?: (account: Account) => void,
onFavourite: (status: Status) => void, onFavourite?: (status: Status) => void,
onReblog: (status: Status, e?: KeyboardEvent) => void, onReblog?: (status: Status, e?: KeyboardEvent) => void,
onToggleHidden: (status: Status) => void, onToggleHidden?: (status: Status) => void,
getScrollPosition?: () => ScrollPosition | undefined, getScrollPosition?: () => ScrollPosition | undefined,
updateScrollBottom?: (bottom: number) => void, updateScrollBottom?: (bottom: number) => void,
cacheMediaWidth: () => void,
cachedMediaWidth: number,
siteTitle?: string, siteTitle?: string,
} }
@ -180,35 +178,39 @@ const Notification: React.FC<INotificaton> = (props) => {
const handleMention = (e?: KeyboardEvent) => { const handleMention = (e?: KeyboardEvent) => {
e?.preventDefault(); e?.preventDefault();
if (account && typeof account === 'object') { if (props.onMention && account && typeof account === 'object') {
props.onMention(account); props.onMention(account);
} }
}; };
const handleHotkeyFavourite = (e?: KeyboardEvent) => { const handleHotkeyFavourite = (e?: KeyboardEvent) => {
if (status && typeof status === 'object') { if (props.onFavourite && status && typeof status === 'object') {
props.onFavourite(status); props.onFavourite(status);
} }
}; };
const handleHotkeyBoost = (e?: KeyboardEvent) => { const handleHotkeyBoost = (e?: KeyboardEvent) => {
if (status && typeof status === 'object') { if (props.onReblog && status && typeof status === 'object') {
props.onReblog(status, e); props.onReblog(status, e);
} }
}; };
const handleHotkeyToggleHidden = (e?: KeyboardEvent) => { const handleHotkeyToggleHidden = (e?: KeyboardEvent) => {
if (status && typeof status === 'object') { if (props.onToggleHidden && status && typeof status === 'object') {
props.onToggleHidden(status); props.onToggleHidden(status);
} }
}; };
const handleMoveUp = () => { const handleMoveUp = () => {
onMoveUp(notification.id); if (onMoveUp) {
onMoveUp(notification.id);
}
}; };
const handleMoveDown = () => { const handleMoveDown = () => {
onMoveDown(notification.id); if (onMoveDown) {
onMoveDown(notification.id);
}
}; };
const renderIcon = (): React.ReactNode => { const renderIcon = (): React.ReactNode => {
@ -268,8 +270,6 @@ const Notification: React.FC<INotificaton> = (props) => {
contextType='notifications' contextType='notifications'
getScrollPosition={props.getScrollPosition} getScrollPosition={props.getScrollPosition}
updateScrollBottom={props.updateScrollBottom} updateScrollBottom={props.updateScrollBottom}
cachedMediaWidth={props.cachedMediaWidth}
cacheMediaWidth={props.cacheMediaWidth}
/> />
) : null; ) : null;
default: default: