* 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
69 lines
2.1 KiB
TypeScript
69 lines
2.1 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 {Platform} from 'react-native';
|
|
|
|
import {useInputPropagation} from './input';
|
|
|
|
describe('useInputPropagation', () => {
|
|
const originalPlatform = Platform.OS;
|
|
|
|
afterEach(() => {
|
|
Platform.OS = originalPlatform;
|
|
});
|
|
|
|
describe('on Android', () => {
|
|
beforeEach(() => {
|
|
Platform.OS = 'android';
|
|
});
|
|
|
|
it('should always process events', () => {
|
|
const {result} = renderHook(() => useInputPropagation());
|
|
const [waitToPropagate, shouldProcessEvent] = result.current;
|
|
|
|
act(() => {
|
|
waitToPropagate('test');
|
|
});
|
|
|
|
expect(shouldProcessEvent('test')).toBe(true);
|
|
expect(shouldProcessEvent('different')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('on iOS', () => {
|
|
beforeEach(() => {
|
|
Platform.OS = 'ios';
|
|
});
|
|
|
|
it('should process event when no value is waiting', () => {
|
|
const {result} = renderHook(() => useInputPropagation());
|
|
const [, shouldProcessEvent] = result.current;
|
|
|
|
expect(shouldProcessEvent('test')).toBe(true);
|
|
});
|
|
|
|
it('should not process event when waiting for specific value', () => {
|
|
const {result} = renderHook(() => useInputPropagation());
|
|
const [waitToPropagate, shouldProcessEvent] = result.current;
|
|
|
|
act(() => {
|
|
waitToPropagate('expected');
|
|
});
|
|
|
|
expect(shouldProcessEvent('different')).toBe(false);
|
|
});
|
|
|
|
it('should clear waiting value after matching', () => {
|
|
const {result} = renderHook(() => useInputPropagation());
|
|
const [waitToPropagate, shouldProcessEvent] = result.current;
|
|
|
|
act(() => {
|
|
waitToPropagate('test');
|
|
});
|
|
|
|
expect(shouldProcessEvent('test')).toBe(false);
|
|
expect(shouldProcessEvent('test')).toBe(true);
|
|
});
|
|
});
|
|
});
|