From ad45091ce76664e2dc5a71e9df96dfe15c1eff59 Mon Sep 17 00:00:00 2001 From: Linh Date: Sat, 1 Mar 2025 12:13:49 +0700 Subject: [PATCH 1/4] fix: unable to download vieo from attachment view --- .../HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx index e3383dc52d617..4f37cdea52377 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx @@ -44,7 +44,8 @@ function VideoRenderer({tnode, key}: VideoRendererProps) { if (!sourceURL || !type) { return; } - const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, type, sourceURL, accountID); + const isAuthTokenRequired = !!htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]; + const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID, type, sourceURL, accountID, isAuthTokenRequired); Navigation.navigate(route); }} /> From e7e613448622df1fde583b8fb833f97f5fbe986d Mon Sep 17 00:00:00 2001 From: Linh Date: Sat, 1 Mar 2025 12:17:07 +0700 Subject: [PATCH 2/4] fix: write unit test for VideoRenderer --- tests/unit/VideoRendererTest.tsx | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/unit/VideoRendererTest.tsx diff --git a/tests/unit/VideoRendererTest.tsx b/tests/unit/VideoRendererTest.tsx new file mode 100644 index 0000000000000..1d4ddefaf6b35 --- /dev/null +++ b/tests/unit/VideoRendererTest.tsx @@ -0,0 +1,80 @@ +import {fireEvent, render, screen} from '@testing-library/react-native'; +import React from 'react'; +import {AttachmentContext} from '@components/AttachmentContext'; +import VideoRenderer from '@components/HTMLEngineProvider/HTMLRenderers/VideoRenderer'; +import type PressableProps from '@components/Pressable/GenericPressable/types'; +import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; +import Navigation from '@libs/Navigation/Navigation'; +import CONST from '@src/CONST'; + +jest.mock('@libs/Navigation/Navigation', () => ({ + navigate: jest.fn(), +})); + +// Mock VideoPlayerPreview to simplify testing +jest.mock('@components/VideoPlayerPreview', () => { + return ({onShowModalPress, fileName}: {onShowModalPress: () => void; fileName: string}) => { + // Get PressableWithoutFeedback inside the component to avoid Jest mock issues + const {PressableWithoutFeedback} = require('@components/Pressable') as { + PressableWithoutFeedback: React.ComponentType; + }; + + const handlePress = () => { + onShowModalPress?.(); + }; + + return ( + + ); + }; +}); + +const mockShowContextMenuValue = { + anchor: null, + report: undefined, + reportNameValuePairs: undefined, + action: undefined, + transactionThreadReport: undefined, + checkIfContextMenuActive: () => {}, + isDisabled: true, +}; +const mockTNodeAttributes = { + [CONST.ATTACHMENT_SOURCE_ATTRIBUTE]: 'video/test.mp4', + [CONST.ATTACHMENT_THUMBNAIL_URL_ATTRIBUTE]: 'thumbnail/test.jpg', + [CONST.ATTACHMENT_THUMBNAIL_WIDTH_ATTRIBUTE]: '640', + [CONST.ATTACHMENT_THUMBNAIL_HEIGHT_ATTRIBUTE]: '480', + [CONST.ATTACHMENT_DURATION_ATTRIBUTE]: '60', +}; + +describe('VideoRenderer', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('navigates to the correct route when show modal button is pressed with isAuthTokenRequired=true', () => { + // Given a VideoRenderer component with a valid attributes + render( + + + {/* @ts-expect-error - Ignoring type errors for testing purposes */} + + + + ); + + // When the user presses the show modal button + fireEvent.press(screen.getByTestId('show-modal-button')); + expect(Navigation.navigate).toHaveBeenCalled(); + + // Then it should navigate to the attachments route with isAuthTokenRequired=true + const mockNavigate = jest.spyOn(Navigation, 'navigate'); + const firstCall = mockNavigate.mock.calls.at(0); + const navigateArgs = firstCall?.at(0); + expect(navigateArgs).toContain('isAuthTokenRequired=true'); + }); +}); From 3ddeb37b509a9be1e2001610dd43418a899c008d Mon Sep 17 00:00:00 2001 From: Linh Date: Sat, 1 Mar 2025 12:42:18 +0700 Subject: [PATCH 3/4] fix: eslint fail --- tests/unit/VideoRendererTest.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/VideoRendererTest.tsx b/tests/unit/VideoRendererTest.tsx index 1d4ddefaf6b35..67e8f0280afc9 100644 --- a/tests/unit/VideoRendererTest.tsx +++ b/tests/unit/VideoRendererTest.tsx @@ -64,7 +64,7 @@ describe('VideoRenderer', () => { {/* @ts-expect-error - Ignoring type errors for testing purposes */} - + , ); // When the user presses the show modal button From d0e96332927da947f5ba1c48a2700b0adcafe588 Mon Sep 17 00:00:00 2001 From: Linh Date: Sat, 1 Mar 2025 21:44:39 +0700 Subject: [PATCH 4/4] fix: rename test for clarity --- tests/unit/VideoRendererTest.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/VideoRendererTest.tsx b/tests/unit/VideoRendererTest.tsx index 67e8f0280afc9..f480cdd4dbd1a 100644 --- a/tests/unit/VideoRendererTest.tsx +++ b/tests/unit/VideoRendererTest.tsx @@ -56,7 +56,7 @@ describe('VideoRenderer', () => { jest.clearAllMocks(); }); - it('navigates to the correct route when show modal button is pressed with isAuthTokenRequired=true', () => { + it('should open the report attachment with isAuthTokenRequired=true', () => { // Given a VideoRenderer component with a valid attributes render(