mattermost-mobile/app/hooks/persistent_notification_props.test.ts
Joram Wilander 4187e9f81a
MM-59741 + others - Add tests for remaining app/hooks files (#8517)
* test: Add tests for useHandleSendMessage hook

* test: Add tests for header hooks

* test: Add tests for device hooks

* test: Add tests for useChannelSwitch hook

* test: Add tests for useTeamSwitch hook

* test: Add tests for useInputPropagation hook

* test: Add tests for useWhyDidYouUpdate hook

* test: Add tests for useFreeze hook

* test: Add tests for useAutocompleteDefaultAnimatedValues hook

* test: Add tests for usePersistentNotificationProps hook

* test: Add tests for useFetchingThreadState hook

* test: Add tests for useBackNavigation hook

* test: Add tests for useShowMoreAnimatedStyle hook

* test: Add tests for useTeamsLoading hook

* test: Add tests for useNavButtonPressed hook

* test: Add tests for useDidUpdate hook

* test: Add tests for useAppBinding hook

* Fix type error and test
2025-01-28 08:51:50 -05:00

71 lines
2.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {renderHook} from '@testing-library/react-hooks';
import {General} from '@constants';
import {PostPriorityType} from '@constants/post';
import {usePersistentNotificationProps} from './persistent_notification_props';
describe('usePersistentNotificationProps', () => {
const baseProps = {
value: '',
channelType: 'O' as ChannelType,
postPriority: {
priority: PostPriorityType.URGENT,
persistent_notifications: true,
},
};
it('should initialize with default values', () => {
const {result} = renderHook(() => usePersistentNotificationProps(baseProps));
expect(result.current.persistentNotificationsEnabled).toBe(true);
expect(result.current.noMentionsError).toBe(true);
expect(result.current.mentionsList).toEqual([]);
});
it('should detect mentions in message', () => {
const props = {
...baseProps,
value: 'Hello @user1 and @user2',
};
const {result} = renderHook(() => usePersistentNotificationProps(props));
expect(result.current.persistentNotificationsEnabled).toBe(true);
expect(result.current.noMentionsError).toBe(false);
expect(result.current.mentionsList).toEqual(['@user1', '@user2']);
});
it('should disable persistent notifications for DM channels', () => {
const props = {
...baseProps,
channelType: General.DM_CHANNEL as ChannelType,
value: 'Hello @user1',
};
const {result} = renderHook(() => usePersistentNotificationProps(props));
expect(result.current.persistentNotificationsEnabled).toBe(true);
expect(result.current.noMentionsError).toBe(false);
expect(result.current.mentionsList).toEqual([]);
});
it('should disable when priority is not urgent', () => {
const props = {
...baseProps,
postPriority: {
priority: PostPriorityType.IMPORTANT,
persistent_notifications: true,
},
};
const {result} = renderHook(() => usePersistentNotificationProps(props));
expect(result.current.persistentNotificationsEnabled).toBe(false);
expect(result.current.noMentionsError).toBe(false);
expect(result.current.mentionsList).toEqual([]);
});
});