diff --git a/src/components/ReceiptEmptyState.tsx b/src/components/ReceiptEmptyState.tsx
index 67c8b42cee9f..9a29e6063096 100644
--- a/src/components/ReceiptEmptyState.tsx
+++ b/src/components/ReceiptEmptyState.tsx
@@ -91,7 +91,8 @@ function ReceiptEmptyState({
const {validateFiles, PDFValidationComponent} = useFilesValidation(setReceiptFile);
- const Wrapper = onPress ? PressableWithoutFeedback : View;
+ const isInteractive = !!onPress || isDisplayedInWideRHP;
+ const Wrapper = isInteractive ? PressableWithoutFeedback : View;
const containerStyle = isCompact
? [styles.alignItemsCenter, styles.justifyContentCenter, styles.receiptEmptyStateCompact, styles.moneyRequestAttachReceipt, style]
: [
@@ -115,72 +116,76 @@ function ReceiptEmptyState({
return (
{({openPicker}) => (
- {
- if (isDisplayedInWideRHP) {
- openPicker({
- onPicked: validateFiles,
- });
- return;
- }
- onPress?.();
- }}
- disabled={disabled}
- disabledStyle={styles.cursorDefault}
- hoverStyle={onPress && isCompact ? styles.hoveredComponentBG : undefined}
- onHoverIn={onPress && isCompact ? () => setIsHovered(true) : undefined}
- onHoverOut={onPress && isCompact ? () => setIsHovered(false) : undefined}
- style={containerStyle}
- >
- {PDFValidationComponent}
- {isCompact ? (
-
-
-
- {translate('dropzone.addReceipt')}
-
-
- ) : (
-
-
-
-
- {!isThumbnail && (
-
-
-
+
+ {
+ if (isDisplayedInWideRHP) {
+ openPicker({
+ onPicked: validateFiles,
+ });
+ return;
+ }
+ onPress?.();
+ }}
+ disabled={disabled}
+ disabledStyle={styles.cursorDefault}
+ hoverStyle={onPress && isCompact ? styles.hoveredComponentBG : undefined}
+ onHoverIn={onPress && isCompact ? () => setIsHovered(true) : undefined}
+ onHoverOut={onPress && isCompact ? () => setIsHovered(false) : undefined}
+ style={[styles.flex1, styles.w100, styles.alignItemsCenter, styles.justifyContentCenter]}
+ >
+ {PDFValidationComponent}
+ {isCompact ? (
+
+
+
+ {translate('dropzone.addReceipt')}
+
+
+ ) : (
+
+
+
+
+ {!isThumbnail && (
+
+
+
+ )}
+
+ {!isThumbnail && isDisplayedInWideRHP && (
+ <>
+ {translate('receipt.addAReceipt.phrase1')}
+ {translate('receipt.addAReceipt.phrase2')}
+ >
)}
- {!isThumbnail && isDisplayedInWideRHP && (
- <>
- {translate('receipt.addAReceipt.phrase1')}
- {translate('receipt.addAReceipt.phrase2')}
- >
- )}
-
- )}
+ )}
+
{isDisplayedInWideRHP && !disabled && }
-
+
)}
);
diff --git a/tests/ui/components/ReceiptEmptyStateTest.tsx b/tests/ui/components/ReceiptEmptyStateTest.tsx
index 83c492d5c570..9199bfbffc7d 100644
--- a/tests/ui/components/ReceiptEmptyStateTest.tsx
+++ b/tests/ui/components/ReceiptEmptyStateTest.tsx
@@ -1,4 +1,4 @@
-import {fireEvent, render, screen} from '@testing-library/react-native';
+import {fireEvent, render, screen, within} from '@testing-library/react-native';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import ReceiptEmptyState from '@components/ReceiptEmptyState';
@@ -6,6 +6,7 @@ import ReceiptEmptyState from '@components/ReceiptEmptyState';
import type {FileObject} from '@src/types/utils/Attachment';
import React from 'react';
+import {View as MockView} from 'react-native';
import {translateLocal} from '../../utils/TestHelper';
@@ -24,13 +25,7 @@ jest.mock('@hooks/useFilesValidation', () => (onFilesValidated: (files: FileObje
}));
// ReceiptAlternativeMethods uses RenderHTML which requires TRenderEngineProvider (buildTTree). Mock to avoid the error.
-jest.mock(
- '@components/ReceiptAlternativeMethods',
- () =>
- function MockReceiptAlternativeMethods() {
- return null;
- },
-);
+jest.mock('@components/ReceiptAlternativeMethods', () => () => );
function Wrapper({children}: {children: React.ReactNode}) {
return {children};
@@ -42,7 +37,24 @@ describe('ReceiptEmptyState', () => {
});
describe('wide RHP attachment picker flow', () => {
+ it('keeps alternative receipt methods outside the upload button', () => {
+ // Given an editable wide receipt panel with alternative actions.
+ render(
+
+
+ ,
+ );
+
+ // When the upload button and alternative methods are inspected.
+ const uploadButton = screen.getByRole('button', {name: translateLocal('receipt.upload')});
+
+ // Then alternative links cannot become nested interactive button content.
+ expect(screen.getByTestId('receipt-alternative-methods')).toBeOnTheScreen();
+ expect(within(uploadButton).queryByTestId('receipt-alternative-methods')).toBeNull();
+ });
+
it('calls openPicker when pressed and isDisplayedInWideRHP is true', () => {
+ // Given a wide receipt panel with its own picker action.
render(
{
,
);
- const uploadButton = screen.getByLabelText(translateLocal('receipt.upload'));
+ const uploadButton = screen.getByRole('button', {name: translateLocal('receipt.upload')});
+ // When its upload control is activated.
fireEvent.press(uploadButton);
+ // Then the picker, not a missing caller callback, handles the action.
expect(mockOpenPicker).toHaveBeenCalledTimes(1);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Jest matcher for callback
expect(mockOpenPicker).toHaveBeenCalledWith({onPicked: expect.any(Function)});
});
it('does not call openPicker when isDisplayedInWideRHP is false and calls onPress instead', () => {
+ // Given an upload control with a caller-owned navigation action.
const onPress = jest.fn();
render(
@@ -71,9 +86,11 @@ describe('ReceiptEmptyState', () => {
,
);
- const uploadButton = screen.getByLabelText(translateLocal('receipt.upload'));
+ const uploadButton = screen.getByRole('button', {name: translateLocal('receipt.upload')});
+ // When that control is activated.
fireEvent.press(uploadButton);
+ // Then its callback runs instead of the wide-panel picker.
expect(mockOpenPicker).not.toHaveBeenCalled();
expect(onPress).toHaveBeenCalledTimes(1);
});
@@ -94,6 +111,7 @@ describe('ReceiptEmptyState', () => {
});
it('does not show "Add a receipt" text when isDisplayedInWideRHP is false', () => {
+ // Given a receipt placeholder without an upload action.
render(
{
,
);
+ // When its accessible output is inspected.
+ // Then it remains a static placeholder, not a misleading upload button.
expect(screen.queryByText(translateLocal('receipt.addAReceipt.phrase1'))).not.toBeOnTheScreen();
expect(screen.queryByText(translateLocal('receipt.addAReceipt.phrase2'))).not.toBeOnTheScreen();
+ expect(screen.getByLabelText(translateLocal('receipt.upload'))).not.toHaveProp('accessibilityRole', 'button');
});
});
});