Skip to content

refactor: remove unsafe assertions from charts, addresses, and invoices - #104927

Draft
KJ21-ENG wants to merge 2 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261023-804bc132-run-1-284f64d4
Draft

KJ21-ENG wants to merge 2 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt-v2/batch-20261023-804bc132-run-1-284f64d4

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Remove unsafe type assertions from chart filters, address defaults, country localization, and invoice company-size forwarding. Preserve exact-merchant filters, inclusive date bounds, registered address-field retention and validation, localization fallbacks, and current and legacy company-size values.

Changed files:

  • src/components/AddressForm.tsx
  • src/components/CountrySelector.tsx
  • src/components/Search/SearchChartView.tsx
  • src/components/Search/chartGroupByConfig.ts
  • src/languages/IntlStore.ts
  • src/libs/CountryUtils.ts
  • src/libs/Localize/index.ts
  • src/libs/actions/IOU/PayMoneyRequest.ts
  • src/pages/AddressPage.tsx
  • src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx
  • src/types/onyx/IntroSelected.ts
  • tests/actions/IOUTest/PayMoneyRequestTest.ts
  • tests/ui/AddressPageTest.tsx
  • tests/ui/WorkspaceTravelAddressCountryTest.tsx
  • tests/unit/CountryUtils.test.ts
  • tests/unit/Search/chartGroupByConfigTest.ts

Fixed Issues

$ #94739
PROPOSAL: #94739 (comment)

Tests

Manual QA required. QA before review.

Use the candidate App against its supported test backend, signed in with a non-delegate account. Run each case on Android native, Android mWeb Chrome, iOS native, iOS mWeb Safari, macOS Chrome, and macOS Safari; use the repository's Mobile-Expensify setup for native builds. Create data through the normal App UI and check for unexpected JavaScript console errors throughout.

Personal address validation and retained fields

Setup: Open the signed-in App link /settings/profile/address. Using this form, save 123 Main St, Suite 4, New York, United States, state New York (NY), ZIP 10001.

  1. Reopen /settings/profile/address. Both street lines, New York city/state, United States and 10001 appear.
  2. Select Canada through the Country picker. Country becomes Canada and State / Province clears; registered city New York, ZIP 10001 and both street lines remain.
  3. Press Save. The form stays open and rejects the incomplete Canadian address; invalid state/postcode is reported.
  4. Enter Ontario in State / Province. Ontario appears without clearing registered city New York or the registered ZIP.
  5. Replace ZIP / Postcode with M5V 2T6. The edited postal code appears and city New York remains.
  6. Press Save at least one second after the rejected save. The valid Canadian address is accepted and the form closes.
  7. Reopen /settings/profile/address. Canada, Ontario, New York, M5V 2T6 and both original street lines appear.
  8. Select United States through the Country picker. Country becomes United States and state clears; city and street lines remain.
  9. Select New York as State. New York is selected.
  10. Replace ZIP with bad. The ZIP input contains bad.
  11. Press Save. ZIP validation prevents dismissal/submission.
  12. Replace ZIP with 10001. The valid ZIP appears.
  13. Press Save at least one second after the rejected save. The valid US address is accepted.
  14. Reopen /settings/profile/address. United States, New York state/city, 10001 and both street lines remain.

Country label follows the language

Setup: Retain the US address saved in the preceding case. Use Settings > Preferences > Language and the signed-in App link /settings/profile/address.

  1. Save English on the Language screen. The selected App language is English.
  2. Open /settings/profile/address. Country reads United States.
  3. Save Spanish on the Language screen. The selected App language is Spanish.
  4. Open /settings/profile/address. Country reads Estados Unidos de América and address labels are Spanish.
  5. Open the Country picker. The saved US selection is represented in the translated picker without a missing-key label or crash.
  6. Return without selecting another country. The translated US country and saved address are retained.
  7. Save English on the Language screen. The selected App language is English again.
  8. Open /settings/profile/address. Country reads United States again with the same saved address.

Chart setup: create ordinary cash expenses through Create expense > Manual with different amounts: merchant I on 2023-12-31, merchant I shop on 2024-01-06, and merchant I shop on 2024-01-07. Open Expenses/Search with a date range containing all three and a supported additional filter that includes them. Restore this original result before each Bar, Pie, or Line variation because drill-down removes the grouping and chart view.

Merchant bar selects the exact merchant

Setup: Restore the original Expenses/Search result described above before configuring this chart.

  1. Set Display > Group by to Merchant. I and I shop appear as distinct groups with their matching amounts.
  2. Set View to Bar. Both groups are represented in the bar chart.
  3. Press the I bar. A table opens containing only exact merchant I, excludes I shop, preserves other filters and matches the selected group amount.

Merchant pie selects the exact merchant

Setup: Restore the original Expenses/Search result described above before configuring this chart.

  1. Set Display > Group by to Merchant. I and I shop appear as distinct groups with their matching amounts.
  2. Set View to Pie. Both groups are represented in the pie chart.
  3. Press the I slice. A table opens containing only exact merchant I, excludes I shop, preserves other filters and matches the selected group amount.

Week line uses inclusive date bounds

Setup: Restore the original Expenses/Search result described above before configuring this chart.

  1. Set Display > Group by to Week. The Dec 31-Jan 6 week and Jan 7 following week appear separately.
  2. Set View to Line. Both weekly points appear in the Line chart.
  3. Press the Dec 31-Jan 6 point. A table includes the Dec 31 and Jan 6 expenses, excludes the Jan 7 control, retains other filters and leaves the grouped chart view.

Insights comparison keeps the current-period identity

Setup: Use an account with Insights and comparison access and ordinary expenses visible in Insights > Spend. Through Create expense > Manual, create expenses with different amounts on Jan 5 and Jan 6, 2024, plus an expense on Jan 3 in the preceding period. Open the headline Spend over time chart with a supported workspace/currency filter that includes them; use Day grouping for the two-day current range.

  1. Select the two-day current date range in the Spend dashboard. The headline chart shows the two current expense days and their distinct amounts.
  2. Select Compare > Previous period. The chart displays current and previous-period series with their period labels.
  3. Press a current-series point whose date and amount are identifiable. Spend opens a table for that current day, retains the dashboard filters, excludes the other current day and previous-period expense, and does not use the compared date or chart label as the filter.

Focused lint, formatting, and nine Jest suites (211 tests) passed. CI passed typecheck, lint, formatting, React Compiler checks, and the selected Jest suites.

The checked-in tests cover chart dispatch and comparison-series data, country/localization fallbacks, registered address values including the Travel consumer, and invoice company-size forwarding. To repeat the selected suites with the normal repository test command:

npm test -- --runInBand --runTestsByPath \
  tests/unit/Search/chartGroupByConfigTest.ts \
  tests/unit/buildChartSeriesTest.ts \
  tests/unit/buildInsightsChartCSVTest.ts \
  tests/unit/getInProgressBucketLabelTest.ts \
  tests/unit/CountryUtils.test.ts \
  tests/ui/AddressPageTest.tsx \
  tests/ui/WorkspaceTravelAddressCountryTest.tsx \
  tests/actions/IOUTest/PayMoneyRequestTest.ts \
  tests/unit/OnboardingFlowTest.ts
  • Verify that no errors appear in the JS console

Offline tests

N/A. Address writes, synchronization, recovery, chart fetching, and the existing localization cache behavior are unchanged, so this refactor introduces no distinct offline case.

QA Steps

Same as Tests, on staging only after the candidate is deployed there and equivalent account, data, and Insights comparison access are available.

  • 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 any copy / text that was added to the app 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • 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)
  • 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

Screenshots/Videos

No manual execution evidence or recordings were supplied; all selected cases and required platform lanes remain unverified by human execution. The required Insights current-point navigation check lacks a supported account/access method with comparison enabled and ordinary Spend data on the candidate test backend. Automated form tests use reduced navigation and mocked transport, and chart unit tests do not establish rendered gestures or navigation. Offline testing is N/A and is not claimed as performed.

Seatbelt-Operation: 0e9ad28d-53d1-4aa9-baac-7c8c97723582
@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/components/AddressForm.tsx 92.59% <100.00%> (+0.09%) ⬆️
src/components/CountrySelector.tsx 95.23% <100.00%> (+4.76%) ⬆️
src/components/Search/chartGroupByConfig.ts 100.00% <100.00%> (+65.21%) ⬆️
src/libs/CountryUtils.ts 91.66% <100.00%> (ø)
src/libs/Localize/index.ts 74.62% <100.00%> (+1.61%) ⬆️
src/libs/actions/IOU/PayMoneyRequest.ts 92.15% <ø> (+10.78%) ⬆️
src/pages/AddressPage.tsx 93.75% <ø> (+9.37%) ⬆️
...gs/Profile/PersonalDetails/PersonalAddressPage.tsx 94.11% <100.00%> (+27.45%) ⬆️
src/components/Search/SearchChartView.tsx 74.46% <50.00%> (ø)
... and 74 files with indirect coverage changes

Seatbelt-Operation: 9c3ccfa2-8f76-4f56-9b19-48906f453380
@KJ21-ENG KJ21-ENG changed the title Remove unsafe type assertions from charts, addresses, and invoice payments refactor: remove unsafe assertions from charts, addresses, and invoices Oct 24, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant