mattermost-mobile/app/hooks/autocomplete.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

48 lines
1.7 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 {useAutocompleteDefaultAnimatedValues} from './autocomplete';
describe('useAutocompleteDefaultAnimatedValues', () => {
it('should initialize with provided values', () => {
const position = 100;
const availableSpace = 200;
const {result} = renderHook(() =>
useAutocompleteDefaultAnimatedValues(position, availableSpace),
);
const [animatedPosition, animatedAvailableSpace] = result.current;
expect(animatedPosition.value).toBe(position);
expect(animatedAvailableSpace.value).toBe(availableSpace);
});
it('should update values when props change', () => {
const initialPosition = 100;
const initialSpace = 200;
const {result, rerender} = renderHook(
({position, space}) => useAutocompleteDefaultAnimatedValues(position, space),
{
initialProps: {position: initialPosition, space: initialSpace},
},
);
// Check initial values
const [animatedPosition, animatedAvailableSpace] = result.current;
expect(animatedPosition.value).toBe(initialPosition);
expect(animatedAvailableSpace.value).toBe(initialSpace);
// Update props
const newPosition = 150;
const newSpace = 250;
rerender({position: newPosition, space: newSpace});
// Check updated values
const [updatedPosition, updatedSpace] = result.current;
expect(updatedPosition.value).toBe(newPosition);
expect(updatedSpace.value).toBe(newSpace);
});
});