-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathAttachment.test.js
More file actions
100 lines (84 loc) · 3.36 KB
/
Attachment.test.js
File metadata and controls
100 lines (84 loc) · 3.36 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
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
import React from 'react';
import { render, waitFor } from '@testing-library/react-native';
import { v4 as uuidv4 } from 'uuid';
import { MessageProvider } from '../../../contexts/messageContext/MessageContext';
import { MessagesProvider } from '../../../contexts/messagesContext/MessagesContext';
import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
import {
generateAudioAttachment,
generateFileAttachment,
generateImageAttachment,
generateVideoAttachment,
} from '../../../mock-builders/generator/attachment';
import { generateMessage } from '../../../mock-builders/generator/message';
import { ImageLoadingFailedIndicator } from '../../Attachment/ImageLoadingFailedIndicator';
import { ImageLoadingIndicator } from '../../Attachment/ImageLoadingIndicator';
import { ImageUploadingIndicator } from '../../Attachment/ImageUploadingIndicator';
import { Attachment } from '../Attachment';
import { FilePreview as FilePreviewDefault } from '../FilePreview';
jest.mock('../../../native.ts', () => ({
isVideoPlayerAvailable: jest.fn(() => false),
isSoundPackageAvailable: jest.fn(() => false),
}));
jest.mock('../../../hooks/useIsPendingAttachmentUploading', () => ({
useIsPendingAttachmentUploading: jest.fn(() => false),
}));
const getAttachmentComponent = (props) => {
const message = generateMessage();
return (
<ThemeProvider>
<MessagesProvider
value={{
FilePreview: FilePreviewDefault,
ImageLoadingFailedIndicator,
ImageLoadingIndicator,
ImageUploadingIndicator,
}}
>
<MessageProvider value={{ message }}>
<Attachment {...props} />
</MessageProvider>
</MessagesProvider>
</ThemeProvider>
);
};
describe('Attachment', () => {
it('should render File component for "audio" type attachment', async () => {
const attachment = generateAudioAttachment();
const { getByTestId } = render(getAttachmentComponent({ attachment }));
await waitFor(() => {
expect(getByTestId('file-attachment')).toBeTruthy();
});
});
it('should render File component for "video" type attachment', async () => {
const attachment = generateVideoAttachment();
const { getByTestId } = render(getAttachmentComponent({ attachment }));
await waitFor(() => {
expect(getByTestId('file-attachment')).toBeTruthy();
});
});
it('should render File component for "file" type attachment', async () => {
const attachment = generateFileAttachment();
const { getByTestId } = render(getAttachmentComponent({ attachment }));
await waitFor(() => {
expect(getByTestId('file-attachment')).toBeTruthy();
});
});
it('should render UrlPreview component if attachment has title_link or og_scrape_url', async () => {
const attachment = generateImageAttachment({
og_scrape_url: uuidv4(),
title_link: uuidv4(),
});
const { getByTestId } = render(getAttachmentComponent({ attachment }));
await waitFor(() => {
expect(getByTestId('card-attachment')).toBeTruthy();
});
});
it('should render Gallery component if image does not have title_link or og_scrape_url', async () => {
const attachment = generateImageAttachment();
const { getByTestId } = render(getAttachmentComponent({ attachment }));
await waitFor(() => {
expect(getByTestId('gallery-container')).toBeTruthy();
});
});
});