* 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
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {renderHook, act} from '@testing-library/react-hooks';
|
|
import {DeviceEventEmitter} from 'react-native';
|
|
|
|
import {Events} from '@constants';
|
|
|
|
import useFreeze from './freeze';
|
|
|
|
describe('useFreeze hook', () => {
|
|
it('should initialize with default values', () => {
|
|
const {result} = renderHook(() => useFreeze());
|
|
|
|
expect(result.current.freeze).toBe(false);
|
|
expect(result.current.backgroundColor).toBe('#000');
|
|
});
|
|
|
|
it('should update freeze state when event is emitted', () => {
|
|
const {result} = renderHook(() => useFreeze());
|
|
|
|
act(() => {
|
|
DeviceEventEmitter.emit(Events.FREEZE_SCREEN, true);
|
|
});
|
|
|
|
expect(result.current.freeze).toBe(true);
|
|
expect(result.current.backgroundColor).toBe('#000');
|
|
});
|
|
|
|
it('should update backgroundColor when provided with event', () => {
|
|
const {result} = renderHook(() => useFreeze());
|
|
const testColor = '#fff';
|
|
|
|
act(() => {
|
|
DeviceEventEmitter.emit(Events.FREEZE_SCREEN, true, testColor);
|
|
});
|
|
|
|
expect(result.current.freeze).toBe(true);
|
|
expect(result.current.backgroundColor).toBe(testColor);
|
|
});
|
|
|
|
it('should cleanup event listener on unmount', () => {
|
|
const removeMock = jest.fn();
|
|
jest.spyOn(DeviceEventEmitter, 'addListener').mockReturnValue({
|
|
remove: removeMock,
|
|
} as any);
|
|
|
|
const {unmount} = renderHook(() => useFreeze());
|
|
|
|
unmount();
|
|
|
|
expect(removeMock).toHaveBeenCalled();
|
|
});
|
|
});
|