-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathsend_draft.test.tsx
116 lines (106 loc) · 3.86 KB
/
send_draft.test.tsx
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {General, Screens} from '@constants';
import {DRAFT_TYPE_DRAFT, DRAFT_TYPE_SCHEDULED, type DraftType} from '@screens/global_drafts/constants';
import {dismissBottomSheet} from '@screens/navigation';
import {fireEvent, renderWithIntlAndTheme} from '@test/intl-test-helper';
import SendDraft from './send_draft';
jest.mock('@screens/navigation', () => ({
dismissBottomSheet: jest.fn(),
}));
jest.mock('@actions/local/draft', () => ({
removeDraft: jest.fn(),
}));
jest.mock('@actions/remote/scheduled_post', () => ({
deleteScheduledPost: jest.fn(),
}));
jest.mock('@context/server', () => ({
useServerUrl: jest.fn(() => 'https://server.com'),
}));
describe('Send Draft', () => {
it('should render the component', () => {
const props = {
channelId: 'channel_id',
channelName: 'channel_name',
rootId: '',
channelType: General.OPEN_CHANNEL,
bottomSheetId: Screens.DRAFT_SCHEDULED_POST_OPTIONS,
currentUserId: 'current_user_id',
maxMessageLength: 4000,
useChannelMentions: true,
userIsOutOfOffice: false,
customEmojis: [],
value: 'value',
files: [],
postPriority: '' as unknown as PostPriority,
persistentNotificationInterval: 0,
persistentNotificationMaxRecipients: 0,
draftReceiverUserName: undefined,
draftType: DRAFT_TYPE_DRAFT as DraftType,
};
const wrapper = renderWithIntlAndTheme(
<SendDraft
{...props}
/>,
);
const {getByText} = wrapper;
expect(getByText('Send draft')).toBeTruthy();
});
it('should call dismissBottomSheet after sending the draft', () => {
const props = {
channelId: 'channel_id',
channelName: 'channel_name',
rootId: '',
channelType: General.OPEN_CHANNEL,
bottomSheetId: Screens.DRAFT_SCHEDULED_POST_OPTIONS,
currentUserId: 'current_user_id',
maxMessageLength: 4000,
useChannelMentions: true,
userIsOutOfOffice: false,
customEmojis: [],
value: 'value',
files: [],
postPriority: '' as unknown as PostPriority,
persistentNotificationInterval: 0,
persistentNotificationMaxRecipients: 0,
draftReceiverUserName: undefined,
};
const wrapper = renderWithIntlAndTheme(
<SendDraft
{...props}
/>,
);
const {getByTestId} = wrapper;
fireEvent.press(getByTestId('send_draft_button'));
expect(dismissBottomSheet).toHaveBeenCalledTimes(1);
});
it('should render the component for scheduled post', () => {
const props = {
channelId: 'channel_id',
channelName: 'channel_name',
rootId: '',
channelType: General.OPEN_CHANNEL,
bottomSheetId: Screens.DRAFT_SCHEDULED_POST_OPTIONS,
currentUserId: 'current_user_id',
maxMessageLength: 4000,
useChannelMentions: true,
userIsOutOfOffice: false,
customEmojis: [],
value: 'value',
files: [],
postPriority: '' as unknown as PostPriority,
persistentNotificationInterval: 0,
persistentNotificationMaxRecipients: 0,
draftReceiverUserName: undefined,
draftType: DRAFT_TYPE_SCHEDULED as DraftType,
};
const wrapper = renderWithIntlAndTheme(
<SendDraft
{...props}
/>,
);
const {getByText} = wrapper;
expect(getByText('Send')).toBeTruthy();
});
});