-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathrescheduled_draft.test.tsx
87 lines (73 loc) · 2.85 KB
/
rescheduled_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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {fireEvent} from '@testing-library/react-native';
import React from 'react';
import {Screens} from '@constants';
import {dismissBottomSheet, showModal} from '@screens/navigation';
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
import test_helper from '@test/test_helper';
import RescheduledDraft from './rescheduled_draft';
import type ScheduledPostModel from '@typings/database/models/servers/scheduled_post';
import type {AvailableScreens} from '@typings/screens/navigation';
jest.mock('@screens/navigation', () => ({
dismissBottomSheet: jest.fn(),
showModal: jest.fn(),
}));
// Mock CompassIcon as a function component
jest.mock('@components/compass_icon', () => {
const MockCompassIcon = () => null;
MockCompassIcon.getImageSourceSync = jest.fn(() => 'mockedImageSource');
return MockCompassIcon;
});
describe('RescheduledDraft', () => {
const baseProps = {
bottomSheetId: 'bottomSheet1' as AvailableScreens,
draft: {
id: 'draft1',
channelId: 'channel1',
message: 'Test message',
createAt: 1234567890,
scheduledAt: 1234567890,
processedAt: 1234567890,
errorCode: '',
toApi: true,
updateAt: 1234567890,
rootId: '',
metadata: {},
} as unknown as ScheduledPostModel,
};
it('renders correctly', () => {
const {getByTestId, getByText} = renderWithIntlAndTheme(
<RescheduledDraft {...baseProps}/>,
);
expect(getByTestId('rescheduled_draft')).toBeTruthy();
expect(getByText('Reschedule')).toBeTruthy();
});
it('calls dismissBottomSheet and showModal when pressed', async () => {
// Mock implementation to resolve immediately
(dismissBottomSheet as jest.Mock).mockResolvedValue(undefined);
const {getByTestId} = renderWithIntlAndTheme(
<RescheduledDraft {...baseProps}/>,
);
fireEvent.press(getByTestId('rescheduled_draft'));
await test_helper.wait(0);
expect(dismissBottomSheet).toHaveBeenCalledWith(baseProps.bottomSheetId);
expect(showModal).toHaveBeenCalledWith(
Screens.RESCHEDULE_DRAFT,
'Change Schedule',
expect.objectContaining({
closeButtonId: 'close-rescheduled-draft',
draft: baseProps.draft,
}),
expect.objectContaining({
topBar: expect.objectContaining({
leftButtons: expect.arrayContaining([
expect.objectContaining({
id: 'close-rescheduled-draft',
}),
]),
}),
}),
);
});
});