|
| 1 | +import {fireEvent, render, screen} from '@testing-library/react-native'; |
| 2 | +import React from 'react'; |
| 3 | +import {AttachmentContext} from '@components/AttachmentContext'; |
| 4 | +import VideoRenderer from '@components/HTMLEngineProvider/HTMLRenderers/VideoRenderer'; |
| 5 | +import type PressableProps from '@components/Pressable/GenericPressable/types'; |
| 6 | +import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; |
| 7 | +import Navigation from '@libs/Navigation/Navigation'; |
| 8 | +import CONST from '@src/CONST'; |
| 9 | + |
| 10 | +jest.mock('@libs/Navigation/Navigation', () => ({ |
| 11 | + navigate: jest.fn(), |
| 12 | +})); |
| 13 | + |
| 14 | +// Mock VideoPlayerPreview to simplify testing |
| 15 | +jest.mock('@components/VideoPlayerPreview', () => { |
| 16 | + return ({onShowModalPress, fileName}: {onShowModalPress: () => void; fileName: string}) => { |
| 17 | + // Get PressableWithoutFeedback inside the component to avoid Jest mock issues |
| 18 | + const {PressableWithoutFeedback} = require('@components/Pressable') as { |
| 19 | + PressableWithoutFeedback: React.ComponentType<PressableProps>; |
| 20 | + }; |
| 21 | + |
| 22 | + const handlePress = () => { |
| 23 | + onShowModalPress?.(); |
| 24 | + }; |
| 25 | + |
| 26 | + return ( |
| 27 | + <PressableWithoutFeedback |
| 28 | + testID="show-modal-button" |
| 29 | + onPress={handlePress} |
| 30 | + accessibilityRole="button" |
| 31 | + accessibilityLabel={fileName} |
| 32 | + /> |
| 33 | + ); |
| 34 | + }; |
| 35 | +}); |
| 36 | + |
| 37 | +const mockShowContextMenuValue = { |
| 38 | + anchor: null, |
| 39 | + report: undefined, |
| 40 | + reportNameValuePairs: undefined, |
| 41 | + action: undefined, |
| 42 | + transactionThreadReport: undefined, |
| 43 | + checkIfContextMenuActive: () => {}, |
| 44 | + isDisabled: true, |
| 45 | +}; |
| 46 | +const mockTNodeAttributes = { |
| 47 | + [CONST.ATTACHMENT_SOURCE_ATTRIBUTE]: 'video/test.mp4', |
| 48 | + [CONST.ATTACHMENT_THUMBNAIL_URL_ATTRIBUTE]: 'thumbnail/test.jpg', |
| 49 | + [CONST.ATTACHMENT_THUMBNAIL_WIDTH_ATTRIBUTE]: '640', |
| 50 | + [CONST.ATTACHMENT_THUMBNAIL_HEIGHT_ATTRIBUTE]: '480', |
| 51 | + [CONST.ATTACHMENT_DURATION_ATTRIBUTE]: '60', |
| 52 | +}; |
| 53 | + |
| 54 | +describe('VideoRenderer', () => { |
| 55 | + beforeEach(() => { |
| 56 | + jest.clearAllMocks(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should open the report attachment with isAuthTokenRequired=true', () => { |
| 60 | + // Given a VideoRenderer component with a valid attributes |
| 61 | + render( |
| 62 | + <ShowContextMenuContext.Provider value={mockShowContextMenuValue}> |
| 63 | + <AttachmentContext.Provider value={{type: CONST.ATTACHMENT_TYPE.SEARCH}}> |
| 64 | + {/* @ts-expect-error - Ignoring type errors for testing purposes */} |
| 65 | + <VideoRenderer tnode={{attributes: mockTNodeAttributes}} /> |
| 66 | + </AttachmentContext.Provider> |
| 67 | + </ShowContextMenuContext.Provider>, |
| 68 | + ); |
| 69 | + |
| 70 | + // When the user presses the show modal button |
| 71 | + fireEvent.press(screen.getByTestId('show-modal-button')); |
| 72 | + expect(Navigation.navigate).toHaveBeenCalled(); |
| 73 | + |
| 74 | + // Then it should navigate to the attachments route with isAuthTokenRequired=true |
| 75 | + const mockNavigate = jest.spyOn(Navigation, 'navigate'); |
| 76 | + const firstCall = mockNavigate.mock.calls.at(0); |
| 77 | + const navigateArgs = firstCall?.at(0); |
| 78 | + expect(navigateArgs).toContain('isAuthTokenRequired=true'); |
| 79 | + }); |
| 80 | +}); |
0 commit comments