Skip to content

refactor: cleanup duplicate create expense navigation logic#71820

Merged
neil-marcellini merged 68 commits into
Expensify:mainfrom
rohit9625:refactor/create-expense-navigation-logic
Jan 20, 2026
Merged

refactor: cleanup duplicate create expense navigation logic#71820
neil-marcellini merged 68 commits into
Expensify:mainfrom
rohit9625:refactor/create-expense-navigation-logic

Conversation

@rohit9625

@rohit9625 rohit9625 commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR extracts the duplicated logic from IOURequestStepDistance, IOURequestStepDistanceMap, IOURequestStepDistanceManual, IOURequestStepScan/index.tsx, IOURequestStepScan/index.native.tsx, and IOURequestStepAmount files and creates reusable functions in the actions/IOU/MoneyRequest.ts file.

  • The duplicate logic from IOURequestStepScan/index.tsx and IOURequestStepScan/index.native.tsx files is extracted into the handleMoneyRequestStepScanParticipants function.
  • Duplicate logic from IOURequestStepDistance, IOURequestStepDistanceMap, and IOURequestStepDistanceManual files is extracted into the handleMoneyRequestStepDistanceNavigation function.
  • The navigateToConfirmation function from all the mentioned files is moved into the IOUUtils.ts file.

Fixed Issues

$ #69179
PROPOSAL: $ #69179 (comment)

Tests

Since this PR made changes in the Create Expense navigation logic, we should test these flows:

  • Track Distance (Manual + Map)
  • Create Expense Scan
  • (1:1 Conversation) Split Expense -> Map

The above flows must be tested from:

  • Global Create Menu
  • Inside a Report/Workspace (Composer's + button)

Mainly, we would test if the user is correctly navigated to the Confirmation Page or the Participants Page, if the user doesn't have a workspace created.

I believe everyone is familiar with the steps of each of the expense flows as mentioned above. That's why I'm not including steps, as nothing unique is implemented in this PR that may change the flow behavior. However, if any of the flow behaves differently from the main, then it must be a regression.

Note: This doesn't apply if the PR is outdated or not synced with the main branch.

  • Verify that no errors appear in the JS console

Offline tests

  1. Open the Expensify App
  2. Force offline
  3. Test the create expense flows as mentioned in the Tests section

QA Steps

Same as tests
// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android_Native.mov
Android: mWeb Chrome
Android_Chrome.mov
iOS: Native
iOS_Native.mov
iOS: mWeb Safari
iOS_Safari.mov
MacOS: Chrome / Safari
Mac_Safari.1.mov

@rohit9625
rohit9625 force-pushed the refactor/create-expense-navigation-logic branch from 8cdebe9 to 7176b4f Compare October 3, 2025 15:51
@codecov

codecov Bot commented Oct 3, 2025

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/IOUUtils.ts 77.98% <100.00%> (+6.35%) ⬆️
src/libs/actions/IOU/MoneyRequest.ts 100.00% <100.00%> (ø)
...rc/pages/iou/request/step/IOURequestStepAmount.tsx 3.92% <ø> (+0.14%) ⬆️
.../pages/iou/request/step/IOURequestStepDistance.tsx 1.61% <0.00%> (+0.37%) ⬆️
.../iou/request/step/IOURequestStepDistanceManual.tsx 0.00% <0.00%> (ø)
...ges/iou/request/step/IOURequestStepDistanceMap.tsx 0.00% <0.00%> (ø)
...u/request/step/IOURequestStepScan/index.native.tsx 1.03% <0.00%> (+0.27%) ⬆️
...ages/iou/request/step/IOURequestStepScan/index.tsx 0.00% <0.00%> (ø)
... and 12 files with indirect coverage changes

@rohit9625
rohit9625 force-pushed the refactor/create-expense-navigation-logic branch from 75484a0 to cf97278 Compare October 9, 2025 11:43
@rohit9625
rohit9625 marked this pull request as ready for review October 9, 2025 12:58
@rohit9625
rohit9625 requested a review from a team as a code owner October 9, 2025 12:58
@melvin-bot
melvin-bot Bot requested review from hungvu193 and removed request for a team October 9, 2025 12:59
@melvin-bot

melvin-bot Bot commented Oct 9, 2025

Copy link
Copy Markdown

@hungvu193 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@hungvu193

Copy link
Copy Markdown
Contributor

Please complete the author check + fix the spell check first. I'll be looking at the failing tests.

@hungvu193

Copy link
Copy Markdown
Contributor
Screenshot 2025-10-09 at 21 29 37

From the error log, I assume you changed some function logic and that function had an existing unit test and you need to mock @react-native-community/geolocation into that existing test. I assume that you used getCurrentPosition inside that some existing function.

Can you please note the functions that you've changed that they had existing unit test?

@rohit9625

Copy link
Copy Markdown
Contributor Author

The tests started failing after this commit. The getCurrentPosition function is being used in files:

Since I migrated the complete navigateToConfirmationStep function in the linked commit and removed the getCurrentPosition usage from those files, I had to import this function in the IOU.ts file, and it's being used inside the function that I extracted from index.native.tsx and index.tsx files.

So, I didn't change the functionality of any existing function. I just created new ones, and one of them uses the getCurrentPosition function. Therefore, I don't know why suddenly all tests started failing.

I was expecting that removing the duplicate logic from those files would break some tests. But, the no. of failing tests are like something reusable function has changed.

@rohit9625

Copy link
Copy Markdown
Contributor Author

Please complete the author check + fix the spell check first. I'll be looking at the failing tests.

Sure, should I also prepare screen recordings for the checklist? If yes, then what exactly should be tested in the screencasts?

@hungvu193

Copy link
Copy Markdown
Contributor

Sure, should I also prepare screen recordings for the checklist? If yes, then what exactly should be tested in the screencasts?

Yes. Since you changed the IOU logic, make sure the IOU and other money request related flows work as expected.

Comment thread src/pages/iou/request/step/IOURequestStepScan/index.native.tsx Outdated
@hungvu193

hungvu193 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Alright, so you moved the function that used getCurrentPosition to actions/IOU.ts but you forgot to update IOUTest.ts

Let's do it. First of all you need to add mock function for getCurrentPosition. You can refer here:

jest.mock('@react-native-community/geolocation', () => ({
setRNConfiguration: jest.fn(),
getCurrentPosition: jest.fn(),
watchPosition: jest.fn(),
clearWatch: jest.fn(),
}));

After that, please write unit test for the functions that you've added inside actions/IOU.ts.

Here's the plan:

  1. Add mock function for getCurrentPosition inside IOUTest.
  2. Add unit tests for the newly added functions for IOUTest.

@rohit9625

Copy link
Copy Markdown
Contributor Author

Thank you so much @hungvu193 :)
I'll try to create mock and unit tests for the function. However, I never write tests for react-native but I'll try my best and will let you know if any problem arises.

@hungvu193

Copy link
Copy Markdown
Contributor

Sounds like a plan 😉

@rohit9625

Copy link
Copy Markdown
Contributor Author

That's great, in my testing the Android app also worked as expected 😀

@IuliiaHerets

Copy link
Copy Markdown

Regression is completed
No issues were found.

@hungvu193

Copy link
Copy Markdown
Contributor

Nice!

@rohit9625

Copy link
Copy Markdown
Contributor Author

Can we merge this PR now, @neil-marcellini?

@hungvu193

Copy link
Copy Markdown
Contributor

Yes. We're good to merge

@rohit9625

Copy link
Copy Markdown
Contributor Author

Hi @neil-marcellini, some conflicts arose again. I'm fixing the conflicts and will retest on my end after merging main. Please consider merging this PR after that. Thank you :)

@rohit9625

Copy link
Copy Markdown
Contributor Author

The iOS build task is failing on main. Should I wait or merge main right now?

@rohit9625

Copy link
Copy Markdown
Contributor Author

Sorry, it took more than expected :(

Test passes, but I cannot test this branch as it is permanently showing Offline after merging main.
Screenshot 2026-01-20 at 1 27 01 AM

The same behavior on the main as well. I hope we can merge now. If not, then LMK, I'll try merging main sometime and will retest as well.

@hungvu193

Copy link
Copy Markdown
Contributor

Little bump @neil-marcellini

@rohit9625

Copy link
Copy Markdown
Contributor Author

Everything works great now. I guess something was off in the backend last night.

@rohit9625

Copy link
Copy Markdown
Contributor Author

The lint check fails on main as well :(

@hungvu193

Copy link
Copy Markdown
Contributor

The lint check fails on main as well :(

Linting is on main, it's not related to this PR.

@neil-marcellini neil-marcellini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go! Sorry for the delay, I was out yesterday.

@neil-marcellini
neil-marcellini merged commit c1ada4f into Expensify:main Jan 20, 2026
28 of 29 checks passed
@melvin-bot

melvin-bot Bot commented Jan 20, 2026

Copy link
Copy Markdown

@neil-marcellini looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@melvin-bot melvin-bot Bot added the Emergency label Jan 20, 2026
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@hungvu193

Copy link
Copy Markdown
Contributor

@neil-marcellini looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

The failing test is on main

@neil-marcellini

Copy link
Copy Markdown
Contributor

Yeah, the failing ESLint check is on main.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.3.5-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 9.3.5-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants