import { HeaderHeightContext } from '@react-navigation/elements' import { DefaultTheme, ThemeProvider } from '@react-navigation/native' import { render } from '@testing-library/react-native' import React from 'react' import { SafeAreaProvider } from 'react-native-safe-area-context' import type { ConversationResource } from '../../../types' import { AttachmentActionsScreen, AttachmentActionsScreenProps } from '../attachment_actions_screen' let mockConversation = { id: 1, disabled: false } as ConversationResource jest.mock('@react-navigation/native', () => ({ ...jest.requireActual('@react-navigation/native'), useNavigation: () => ({ goBack: jest.fn() }), })) jest.mock('../../../hooks/use_conversation', () => ({ useConversation: () => ({ data: mockConversation }), })) jest.mock('../hooks/useDeleteAttachment', () => ({ useDeleteAttachment: () => ({ handleDeleteAttachment: jest.fn() }), })) const safeAreaMetrics = { frame: { x: 0, y: 0, width: 390, height: 844 }, insets: { top: 0, right: 0, bottom: 0, left: 0 }, } const renderScreen = (params: Partial = {}) => { const route = { key: 'AttachmentActions', name: 'AttachmentActions', params: { attachmentId: 'a1', attachmentContentType: 'image/png', attachmentUrl: 'https://example.com/a1.png', conversation_id: 1, canDeleteNonAuthoredMessages: false, myMessage: true, ...params, }, } as AttachmentActionsScreenProps['route'] return render( ) } describe('AttachmentActionsScreen', () => { beforeEach(() => { mockConversation = { id: 1, disabled: false } as ConversationResource }) it('offers Delete on my own attachment', () => { const { getByText } = renderScreen() expect(getByText('Delete image')).toBeTruthy() }) it('hides Delete when the conversation is disabled', () => { mockConversation = { id: 1, disabled: true, disabledReason: 'locked' } as ConversationResource const { queryByText, getByText } = renderScreen({ canDeleteNonAuthoredMessages: true }) expect(queryByText('Delete image')).toBeNull() expect(getByText('Open in browser')).toBeTruthy() }) })