From 1684cdf19d043e6fa9c22a82310ff7d060e22f22 Mon Sep 17 00:00:00 2001 From: Nyoman Jyotisa Date: Tue, 20 Oct 2026 21:16:11 +0800 Subject: [PATCH 1/2] fix: expose empty receipt upload as an accessible button --- src/components/ReceiptEmptyState.tsx | 5 +++-- tests/ui/components/ReceiptEmptyStateTest.tsx | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/ReceiptEmptyState.tsx b/src/components/ReceiptEmptyState.tsx index 67c8b42cee9f..9b029afc192b 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] : [ @@ -116,7 +117,7 @@ function ReceiptEmptyState({ {({openPicker}) => ( { if (isDisplayedInWideRHP) { diff --git a/tests/ui/components/ReceiptEmptyStateTest.tsx b/tests/ui/components/ReceiptEmptyStateTest.tsx index 83c492d5c570..63b01c97ce2f 100644 --- a/tests/ui/components/ReceiptEmptyStateTest.tsx +++ b/tests/ui/components/ReceiptEmptyStateTest.tsx @@ -43,6 +43,7 @@ describe('ReceiptEmptyState', () => { describe('wide RHP attachment picker flow', () => { 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 +75,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 +100,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'); }); }); }); From f5a6996d4e4495e45abea4a6e901a324a38fb66d Mon Sep 17 00:00:00 2001 From: Nyoman Jyotisa Date: Wed, 21 Oct 2026 19:49:18 +0800 Subject: [PATCH 2/2] fix: keep receipt alternatives outside upload button --- src/components/ReceiptEmptyState.tsx | 128 +++++++++--------- tests/ui/components/ReceiptEmptyStateTest.tsx | 27 ++-- 2 files changed, 85 insertions(+), 70 deletions(-) diff --git a/src/components/ReceiptEmptyState.tsx b/src/components/ReceiptEmptyState.tsx index 9b029afc192b..9a29e6063096 100644 --- a/src/components/ReceiptEmptyState.tsx +++ b/src/components/ReceiptEmptyState.tsx @@ -116,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 63b01c97ce2f..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,6 +37,22 @@ 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(