Skip to content

[No QA] Reduce unsafe type assertions in SearchUIUtils tests - #95904

Merged
blimpich merged 6 commits into
Expensify:mainfrom
KJ21-ENG:sbf/job1-94739-searchuiutils-test
Jul 13, 2026
Merged

blimpich merged 6 commits into
Expensify:mainfrom
KJ21-ENG:sbf/job1-94739-searchuiutils-test

Conversation

@KJ21-ENG

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR addresses #94739 by removing the remaining @typescript-eslint/no-unsafe-type-assertion warnings from tests/unit/Search/SearchUIUtilsTest.ts. The cleanup keeps the existing SearchUIUtils test coverage intact while making fixture and result types explicit instead of forcing them with unsafe assertions.

What changed:

  • Added small test helpers for narrowing getSections and getSortedSections results through SearchUIUtils type guards.
  • Typed large fixtures, policy/search data, selected transaction maps, report actions, and transaction preview data at their declarations instead of asserting them later.
  • Replaced result-array casts with predicate-based filtering for transaction, report, task, card, category, merchant, tag, period, and withdrawal group test cases.
  • Updated mocked Report/Search action usage to jest.mocked and replaced compatible fixture assertions with satisfies or explicit annotations.

Why this approach is safe:

  • Only tests/unit/Search/SearchUIUtilsTest.ts changed; no production code, app behavior, copy, styles, or assets changed.
  • The new helpers assert that every returned item matches the expected type guard before returning the narrowed list.
  • Fixture access now throws on missing required transaction fixture indices instead of hiding undefined behind a cast.
  • The cleanup removes target-rule warnings without changing the expected SearchUIUtils assertions under test.

Reviewer focus:

  1. Check that each getSectionsByType/getSortedSectionsByType call uses the type guard that matches the scenario being asserted.
  2. Review typed fixture declarations where assertions were replaced to confirm the fixture shape still matches the original test intent.
  3. Confirm the jest.mocked updates preserve the same mocked function behavior for createTransactionThreadReport and setOptimisticDataForTransactionThreadPreview.
  4. Check the shared transactionPreviewData defaults against the per-test overrides in optimistic transaction thread preview tests.

Safety checks:

  • Target @typescript-eslint/no-unsafe-type-assertion warnings in tests/unit/Search/SearchUIUtilsTest.ts go from 136 to 0.
  • Overall @typescript-eslint/no-unsafe-type-assertion warnings go from 5300 to 5164.
  • Verification scope is targeted lint, eslint report generation, and formatting for tests/unit/Search/SearchUIUtilsTest.ts.
  • No QA: test-only cleanup.

Fixed Issues

$ #94739
PROPOSAL:
Use checked TypeScript patterns in the SearchUIUtils unit tests: type fixtures at declaration time, narrow mixed SearchUIUtils results with existing type guards, and rely on jest.mocked/satisfies where those preserve intent without bypassing type checking.

Count change

Current baseline source:

  • config/eslint/eslint.seatbelt.tsv
  • Target files: tests/unit/Search/SearchUIUtilsTest.ts
  • Target Rule: @typescript-eslint/no-unsafe-type-assertion

Before:

  • Target before warnings: 136
  • Before warnings: 5300

After:

  • Target after warnings: 0
  • After warnings: 5164

Net reduction:

  • Target warning reduction: 136
  • Net warning reduction: 136

TSV evidence:

  • OSBotify note: TSV row deletions were restored before commit because OSBotify tightens the baseline.

Exact verification commands:

  • npm run lint -- --no-cache --show-warnings tests/unit/Search/SearchUIUtilsTest.ts
  • npm run eslint-report
  • npm run fmt -- tests/unit/Search/SearchUIUtilsTest.ts

Tests

  1. Run:

      npm run lint -- --no-cache --show-warnings tests/unit/Search/SearchUIUtilsTest.ts
    

    Verify the command succeeds and produces the expected evidence.

  2. Run:

      npm run eslint-report
    

    Verify the command succeeds and produces the expected evidence.

  3. Run:

      npm run fmt -- tests/unit/Search/SearchUIUtilsTest.ts
    

    Verify the command succeeds and produces the expected evidence.

  4. Verify the target count decreased from 136 to 0, and total warnings decreased from 5300 to 5164.

Offline tests

Not applicable: this cleanup changes only a TypeScript test file and has no network-dependent runtime behavior.

QA Steps

[No QA]

Not applicable: this is a test-only cleanup with no staging UI or production workflow change.

PR Author Checklist

For checklist items that are not applicable to this cleanup, checked means the item was considered and determined not applicable.

  • 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 tests section — Not applicable to this test-only cleanup.
    • I added steps for Staging and/or Production testing in the QA steps section — Not applicable to this test-only cleanup.
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct) — Not applicable to this test-only cleanup.
    • 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) — Not applicable to this test-only cleanup.
    • 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). — Not applicable to this test-only cleanup.
  • I included screenshots or videos for tests on all platforms — Not applicable to this test-only cleanup.
  • I ran the tests on all platforms & verified they passed on: — Not applicable to this test-only cleanup.
    • Android: Native — Not applicable to this test-only cleanup.
    • Android: mWeb Chrome — Not applicable to this test-only cleanup.
    • iOS: Native — Not applicable to this test-only cleanup.
    • iOS: mWeb Safari — Not applicable to this test-only cleanup.
    • MacOS: Chrome / Safari — Not applicable to this test-only cleanup.
  • 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) — Not applicable to this test-only cleanup.
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory — Not applicable to this test-only cleanup.
    • 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. — Not applicable to this test-only cleanup.
    • 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) — Not applicable to this test-only cleanup.
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers — Not applicable to this test-only cleanup.
  • I followed the guidelines as stated in the Review Guidelines — Not applicable to this test-only cleanup.
  • 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) — Not applicable to this test-only cleanup.
  • If a new CSS style is added I verified that: — Not applicable to this test-only cleanup.
    • A similar style doesn't already exist — Not applicable to this test-only cleanup.
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)) — Not applicable to this test-only cleanup.
  • If new assets were added or existing ones were modified, I verified that: — Not applicable to this test-only cleanup.
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg) — Not applicable to this test-only cleanup.
    • The assets load correctly across all supported platforms. — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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) — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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: — Not applicable to this test-only cleanup.
    • I verified that all the inputs inside a form are aligned with each other. — Not applicable to this test-only cleanup.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes. — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.

Screenshots/Videos

Not applicable: no UI or visual behavior changed.

@KJ21-ENG
KJ21-ENG force-pushed the sbf/job1-94739-searchuiutils-test branch from 53f2732 to b602e07 Compare July 12, 2026 18:47
KJ21-ENG added 2 commits July 13, 2026 17:43
Target rule: @typescript-eslint/no-unsafe-type-assertion
Target files: tests/unit/Search/SearchUIUtilsTest.ts
Verification: completed
Generated TSV restored: yes
@KJ21-ENG
KJ21-ENG force-pushed the sbf/job1-94739-searchuiutils-test branch from b602e07 to 30bfd90 Compare July 13, 2026 12:15
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review July 13, 2026 12:21
@KJ21-ENG
KJ21-ENG requested a review from a team as a code owner July 13, 2026 12:21
@melvin-bot
melvin-bot Bot requested review from blimpich and removed request for a team July 13, 2026 12:21
@melvin-bot

melvin-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

@blimpich 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]

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@blimpich The large diff is intentional: SearchUIUtilsTest.ts is a broad, fixture-heavy test file, and the 136 warnings were spread across many fixture declarations and result-narrowing call sites. Removing them required rewriting the surrounding fixtures with typed helpers, type guards, and typed mocks rather than deleting isolated lines. Existing test scenarios are preserved; no production code changed. Target warnings: 136 → 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30bfd90d92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/unit/Search/SearchUIUtilsTest.ts Outdated
@@ -716,7 +731,8 @@ const searchResultsGroupByCategory: OnyxTypes.SearchResults = {
},
};

const reportActionListItems = [
const reportActionListItems = createMock<ReportActionListItemType[]>([
// @ts-expect-error -- these fixtures intentionally include the minimal report-action fields consumed by the search helpers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove unused ts-expect-error directives

In this createMock<ReportActionListItemType[]> call the fixtures are accepted as partial mocks, so omitting unused report-action fields does not produce an error on the following object literal. That makes this directive (and the same directives before the later report-action fixtures) report TS2578 as an unused @ts-expect-error, which blocks typecheck/CI before the tests can run; delete the suppressions or move to a construct that actually needs one.

Useful? React with 👍 / 👎.

@blimpich
blimpich merged commit 4b5fd32 into Expensify:main Jul 13, 2026
28 of 29 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.4.34-0 🚀

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.34-14 🚀

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.34-14 🚀

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

Bundle Size Analysis (Sentry):

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.

3 participants