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

55 lines
1.6 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 {withTiming} from 'react-native-reanimated';
import {useShowMoreAnimatedStyle} from './show_more';
jest.mock('react-native-reanimated', () => ({
useAnimatedStyle: (callback: () => any) => callback(),
withTiming: jest.fn((value) => value),
}));
describe('useShowMoreAnimatedStyle', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('returns maxHeight when height is undefined', () => {
const maxHeight = 100;
const {result} = renderHook(() =>
useShowMoreAnimatedStyle(undefined, maxHeight, false),
);
expect(result.current).toEqual({
maxHeight,
});
});
it('animates to maxHeight when not open', () => {
const height = 200;
const maxHeight = 100;
const {result} = renderHook(() =>
useShowMoreAnimatedStyle(height, maxHeight, false),
);
expect(result.current).toEqual({
maxHeight,
});
expect(withTiming).toHaveBeenCalledWith(maxHeight, {duration: 300});
});
it('animates to full height when open', () => {
const height = 200;
const maxHeight = 100;
const {result} = renderHook(() =>
useShowMoreAnimatedStyle(height, maxHeight, true),
);
expect(result.current).toEqual({
maxHeight: height,
});
expect(withTiming).toHaveBeenCalledWith(height, {duration: 300});
});
});