-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathuseGoToDirectMessage.spec.ts
More file actions
49 lines (38 loc) · 1.93 KB
/
useGoToDirectMessage.spec.ts
File metadata and controls
49 lines (38 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { mockAppRoot } from '@rocket.chat/mock-providers';
import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
import { renderHook } from '@testing-library/react';
import { useGoToDirectMessage } from './useGoToDirectMessage';
it('should return undefined if username is not provided', () => {
const { result } = renderHook(() => useGoToDirectMessage({}), {
wrapper: mockAppRoot().build(),
});
expect(result.current).toBe(undefined);
});
it("should return undefined if the user doesn't have permission to create direct messages and doesn't have a subscription with target user", () => {
const { result } = renderHook(() => useGoToDirectMessage({ username: 'test' }), {
wrapper: mockAppRoot().build(),
});
expect(result.current).toBe(undefined);
});
it('should return undefined if the room is already open', () => {
const { result } = renderHook(() => useGoToDirectMessage({ username: 'test' }, 'test-room'), {
wrapper: mockAppRoot()
.withSubscription({ _id: 'test-room', name: 'test', t: 'd', rid: 'test-room' } as SubscriptionWithRoom)
.build(),
});
expect(result.current).toBe(undefined);
});
it('should return a function to navigate to the direct message room if the user has permission to create direct messages and no subscription with target user', () => {
const { result } = renderHook(() => useGoToDirectMessage({ username: 'test' }), {
wrapper: mockAppRoot().withPermission('create-d').build(),
});
expect(typeof result.current).toBe('function');
});
it("should return a function to navigate to the direct message room if the user has a subscription with target user and doesn't have permission to create direct messages", () => {
const { result } = renderHook(() => useGoToDirectMessage({ username: 'test' }), {
wrapper: mockAppRoot()
.withSubscription({ _id: 'test-room', name: 'test', t: 'd', rid: 'test-room' } as SubscriptionWithRoom)
.build(),
});
expect(typeof result.current).toBe('function');
});