First batch of modules/activities tests (#4446)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
|
||||
import { useEmailThread } from '../useEmailThread';
|
||||
|
||||
const mockSetViewableEmailThreadId = jest.fn();
|
||||
const mockUseOpenEmailThreadRightDrawer = jest.fn();
|
||||
|
||||
jest.mock('recoil', () => ({
|
||||
useSetRecoilState: () => mockSetViewableEmailThreadId,
|
||||
}));
|
||||
|
||||
jest.mock(
|
||||
'@/activities/emails/right-drawer/hooks/useOpenEmailThreadRightDrawer',
|
||||
() => ({
|
||||
useOpenEmailThreadRightDrawer: () => mockUseOpenEmailThreadRightDrawer,
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock('@/activities/emails/state/viewableEmailThreadIdState', () => ({
|
||||
viewableEmailThreadIdState: () => 'mockViewableEmailThreadIdState',
|
||||
}));
|
||||
|
||||
describe('useEmailThread hook', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('openEmailThread function', () => {
|
||||
const { result } = renderHook(() => useEmailThread());
|
||||
|
||||
act(() => {
|
||||
result.current.openEmailThread('mockThreadId');
|
||||
});
|
||||
|
||||
expect(mockSetViewableEmailThreadId).toHaveBeenCalledWith('mockThreadId');
|
||||
expect(mockUseOpenEmailThreadRightDrawer).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,37 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useEmailThreadStates } from '@/activities/emails/hooks/internal/useEmailThreadStates';
|
||||
|
||||
const mockScopeId = 'mockScopeId';
|
||||
const mockGetEmailThreadsPageState = jest.fn();
|
||||
|
||||
jest.mock(
|
||||
'@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId',
|
||||
() => ({
|
||||
useAvailableScopeIdOrThrow: () => mockScopeId,
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock(
|
||||
'@/ui/utilities/state/component-state/utils/extractComponentState',
|
||||
() => ({
|
||||
extractComponentState: () => mockGetEmailThreadsPageState,
|
||||
}),
|
||||
);
|
||||
|
||||
describe('useEmailThreadStates hook', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('returns the correct scopeId and getEmailThreadsPageState', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useEmailThreadStates({ emailThreadScopeId: 'mockEmailThreadScopeId' }),
|
||||
);
|
||||
|
||||
expect(result.current.scopeId).toBe(mockScopeId);
|
||||
expect(result.current.getEmailThreadsPageState).toBe(
|
||||
mockGetEmailThreadsPageState,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,35 @@
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useOpenEmailThreadRightDrawer } from '@/activities/emails/right-drawer/hooks/useOpenEmailThreadRightDrawer';
|
||||
import { RightDrawerHotkeyScope } from '@/ui/layout/right-drawer/types/RightDrawerHotkeyScope';
|
||||
import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages';
|
||||
|
||||
const mockOpenRightDrawer = jest.fn();
|
||||
const mockSetHotkeyScope = jest.fn();
|
||||
|
||||
jest.mock('@/ui/layout/right-drawer/hooks/useRightDrawer', () => ({
|
||||
useRightDrawer: () => ({
|
||||
openRightDrawer: mockOpenRightDrawer,
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('@/ui/utilities/hotkey/hooks/useSetHotkeyScope', () => ({
|
||||
useSetHotkeyScope: () => mockSetHotkeyScope,
|
||||
}));
|
||||
|
||||
test('useOpenEmailThreadRightDrawer opens the email thread right drawer', () => {
|
||||
const { result } = renderHook(() => useOpenEmailThreadRightDrawer());
|
||||
|
||||
act(() => {
|
||||
result.current();
|
||||
});
|
||||
|
||||
expect(mockSetHotkeyScope).toHaveBeenCalledWith(
|
||||
RightDrawerHotkeyScope.RightDrawer,
|
||||
{ goto: false },
|
||||
);
|
||||
expect(mockOpenRightDrawer).toHaveBeenCalledWith(
|
||||
RightDrawerPages.ViewEmailThread,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user