* 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
59 lines
1.6 KiB
TypeScript
59 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 {subject} from '@store/fetching_thread_store';
|
|
|
|
import {useFetchingThreadState} from './fetching_thread';
|
|
|
|
describe('useFetchingThreadState', () => {
|
|
const rootId = 'test-root-id';
|
|
|
|
afterEach(() => {
|
|
// Clear all subjects after each test
|
|
subject.next({});
|
|
});
|
|
|
|
it('should initialize with false', () => {
|
|
const {result} = renderHook(() => useFetchingThreadState(rootId));
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it('should update when subject emits new state', () => {
|
|
const {result} = renderHook(() => useFetchingThreadState(rootId));
|
|
|
|
act(() => {
|
|
subject.next({[rootId]: true});
|
|
});
|
|
expect(result.current).toBe(true);
|
|
|
|
act(() => {
|
|
subject.next({[rootId]: false});
|
|
});
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it('should not update for different rootId', () => {
|
|
const {result} = renderHook(() => useFetchingThreadState(rootId));
|
|
|
|
act(() => {
|
|
subject.next({'different-root-id': true});
|
|
});
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it('should handle empty subject updates', () => {
|
|
const {result} = renderHook(() => useFetchingThreadState(rootId));
|
|
|
|
act(() => {
|
|
subject.next({[rootId]: true});
|
|
});
|
|
expect(result.current).toBe(true);
|
|
|
|
act(() => {
|
|
subject.next({});
|
|
});
|
|
expect(result.current).toBe(false);
|
|
});
|
|
});
|