-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix: make company card CSV import help links reliably tappable on Android #99727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+192
−8
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4055da6
Fix: make company card CSV import help links reliably tappable on And…
MelvinBot a834a9b
Fix: format ImportFromFileStep to satisfy oxfmt (line length)
MelvinBot 1209fac
Fix: add sentryLabel to PressableWithoutFeedback links to satisfy ESLint
MelvinBot 865a6ba
Address review: preserve locale spacing and add href to help guide link
MelvinBot c2a16e2
Address review: use stable segment key and justify word-level index key
MelvinBot 6a6ed3c
Address review: render help-text segments explicitly and add inline-l…
MelvinBot 3ccd53a
Extract renderPlainCopy into a WrappingText component
MelvinBot 7596d45
Fix WrappingText.tsx Oxfmt import order and knip unused export, add d…
MelvinBot 1f8e1e8
Add file description header above WrappingTextProps
MelvinBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import Text from '@components/Text'; | ||
|
|
||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| // Renders plain paragraph copy as per-word <Text> nodes so it flows and wraps naturally inside a flexWrap | ||
| // row alongside tappable link nodes. Used by the company-card CSV import help text (see JSDoc below). | ||
|
|
||
| type WrappingTextProps = { | ||
| /** Plain copy to render, split into per-word nodes so it wraps naturally inside a flexWrap row. */ | ||
| text: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders plain copy as a sequence of per-word <Text> nodes so it flows and wraps naturally inside a | ||
| * flexWrap row alongside tappable link nodes. | ||
| * | ||
| * The company-card CSV import help text mixes plain copy with tappable links (a client-side template | ||
| * download and an external help guide). On Android, a link nested inline inside a <Text> becomes a | ||
| * ClickableSpan whose touch area is limited to the glyph bounds, which makes it unreliable to tap (e.g. | ||
| * at the minimum device font size). The links are therefore rendered as their own PressableWithoutFeedback | ||
| * nodes inside a flexWrap row, and this component renders the plain copy between them as per-word <Text> | ||
| * nodes so the paragraph still flows and wraps naturally across the row. | ||
| */ | ||
| function WrappingText({text}: WrappingTextProps) { | ||
| const styles = useThemeStyles(); | ||
|
|
||
| // Keep each word (with its own leading/trailing whitespace) as a separate node so the paragraph wraps in the flexWrap row. | ||
| // Preserving the run's own spacing means locales that don't use spaces around the links (e.g. Japanese, Chinese) aren't | ||
| // given extra spaces the translation never intended. | ||
| return (text.match(/\s*\S+\s*/g) ?? []).map((word, wordIndex) => ( | ||
| <Text | ||
| // The word list is derived synchronously from a fixed translation and is never reordered, inserted into, or | ||
| // filtered, so a word's index is a stable identity. wordIndex is only needed to disambiguate repeated words | ||
| // within a run (the word text alone can't); the array position is what makes it unique. | ||
| // eslint-disable-next-line react/no-array-index-key -- index is a stable identity for this static, never-reordered word list | ||
| key={`${text}-${word}-${wordIndex}`} | ||
| style={styles.textSupporting} | ||
| > | ||
| {word} | ||
| </Text> | ||
| )); | ||
| } | ||
|
|
||
| WrappingText.displayName = 'WrappingText'; | ||
|
|
||
| export default WrappingText; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import {act, fireEvent, render, screen} from '@testing-library/react-native'; | ||
|
|
||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
| import OnyxListItemProvider from '@components/OnyxListItemProvider'; | ||
|
|
||
| import * as Link from '@libs/actions/Link'; | ||
| import localFileDownload from '@libs/localFileDownload'; | ||
|
|
||
| import ImportFromFileStep from '@pages/workspace/companyCards/addNew/ImportFromFileStep'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| const POLICY_ID = 'import-from-file-step-test-policy'; | ||
|
|
||
| // The inline template download is a client-side file write, and the help guide opens an external link. | ||
| // Stub both so the test asserts the presses are wired up without touching the filesystem or the browser. | ||
| jest.mock('@libs/localFileDownload'); | ||
|
|
||
| jest.mock('@react-navigation/native', () => { | ||
| // jest.requireActual returns `any` for the untyped React Navigation module | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const actualNav = jest.requireActual('@react-navigation/native'); | ||
|
|
||
| // Spreading the untyped requireActual result is intentional for this navigation mock | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return { | ||
| ...actualNav, | ||
| useNavigation: () => ({ | ||
| navigate: jest.fn(), | ||
| goBack: jest.fn(), | ||
| addListener: () => jest.fn(), | ||
| isFocused: () => true, | ||
| }), | ||
| useIsFocused: () => true, | ||
| useFocusEffect: jest.fn(), | ||
| usePreventRemove: jest.fn(), | ||
| useRoute: () => ({key: 'test-route', name: 'Workspace_Company_Cards_Add_New', params: {policyID: POLICY_ID}}), | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('@libs/Navigation/Navigation', () => ({ | ||
| navigate: jest.fn(), | ||
| goBack: jest.fn(), | ||
| getActiveRoute: jest.fn(() => ''), | ||
| getActiveRouteWithoutParams: jest.fn(() => ''), | ||
| getTopmostReportId: jest.fn(() => undefined), | ||
| isNavigationReady: jest.fn(() => Promise.resolve()), | ||
| setNavigationActionToMicrotaskQueue: jest.fn(), | ||
| removeScreenFromNavigationState: jest.fn(), | ||
| dismissModal: jest.fn(), | ||
| })); | ||
|
|
||
| function renderImportFromFileStep() { | ||
| return render( | ||
| <ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}> | ||
| <ImportFromFileStep /> | ||
| </ComposeProviders>, | ||
| ); | ||
| } | ||
|
|
||
| describe('ImportFromFileStep inline help links', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await act(async () => { | ||
| await Onyx.clear(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
| }); | ||
| renderImportFromFileStep(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders the template link as a Pressable button that triggers the client-side CSV download', () => { | ||
| const templateLink = screen.getByTestId('ImportFromFileStep-TemplateLink'); | ||
|
|
||
| // A Pressable-backed link (not a bare inline <Text>/ClickableSpan) so it gets a real native touch target on Android. | ||
| expect(templateLink).toHaveProp('role', CONST.ROLE.BUTTON); | ||
|
|
||
| fireEvent.press(templateLink); | ||
| expect(localFileDownload).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('renders the help guide link as a Pressable that keeps its href and opens the help guide', () => { | ||
| const openLinkSpy = jest.spyOn(Link, 'openLink').mockImplementation(() => {}); | ||
| const helpGuideLink = screen.getByTestId('ImportFromFileStep-HelpGuideLink'); | ||
|
|
||
| // Retains href so web renders a real <a> (native link behavior), while still routing through onPress on every platform. | ||
| expect(helpGuideLink).toHaveProp('role', CONST.ROLE.LINK); | ||
| expect(helpGuideLink).toHaveProp('href', CONST.COMPANY_CARDS_CREATE_FILE_FEED_HELP_URL); | ||
|
|
||
| fireEvent.press(helpGuideLink); | ||
| expect(openLinkSpy).toHaveBeenCalledWith(CONST.COMPANY_CARDS_CREATE_FILE_FEED_HELP_URL, expect.any(String)); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: @MelvinBot the JSDoc documents the component, but the new file still has no header before
WrappingTextProps. Please add a short file description above the type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved ✅