Skip to content

Commit 88e5db7

Browse files
authored
Merge pull request #57640 from linhvovan29546/fix/57275-unable-to-download-video-from-download-icon
Fix: unable to download video from download icon
2 parents 0b60925 + d0e9633 commit 88e5db7

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function VideoRenderer({tnode, key}: VideoRendererProps) {
4444
if (!sourceURL || !type) {
4545
return;
4646
}
47-
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, type, sourceURL, accountID);
47+
const isAuthTokenRequired = !!htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE];
48+
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, type, sourceURL, accountID, isAuthTokenRequired);
4849
Navigation.navigate(route);
4950
}}
5051
/>

tests/unit/VideoRendererTest.tsx

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)