Skip to content

Test: Component: Global Unified Search Categorization - #529

Open
Deb-Auth wants to merge 1 commit into
SwiftChainn:mainfrom
Deb-Auth:test-comp-global-search
Open

Test: Component: Global Unified Search Categorization#529
Deb-Auth wants to merge 1 commit into
SwiftChainn:mainfrom
Deb-Auth:test-comp-global-search

Conversation

@Deb-Auth

Copy link
Copy Markdown

closes #499

Summary

Adds automated tests verifying that global search results group correctly into Deliveries, Drivers and Transactions, together with the unified search implementation those tests exercise.

The existing components/ui/CommandPalette.tsx only groups into "Quick actions" and "Deliveries" and has no notion of drivers or transactions, so there was no categorisation to verify. This PR adds a unified search across all three categories following the project's Component -> Hook -> Service layering, and tests every layer. The command palette is deliberately left untouched to avoid colliding with the design work currently landing on it.

What was added

services/globalSearchService.ts — the transport for the unified search endpoint.

  • Exports SearchCategory, a canonical SEARCH_CATEGORIES order and SEARCH_CATEGORY_LABELS.
  • Accepts either a bare array or a { results: [...] } envelope from the API.
  • Normalises every record and drops malformed ones (missing id, unrecognised category) rather than rendering a broken row. Falls back to the id when a record has no title, and derives an in-app href per category when the API does not supply one.
  • Short-circuits an empty or whitespace-only query without a network call, and forwards an AbortSignal.

hooks/useGlobalSearch.ts — runs the search and groups the results.

  • Grouping is derived from the fetched results, in the canonical Deliveries/Drivers/Transactions order, with empty categories omitted entirely.
  • The result snapshot is tagged with the query that produced it, so every derived value (loading, results, grouping, empty) follows from whether that tag still matches the query on screen. Results from a superseded query can therefore never be shown, and a slow response cannot overwrite a newer one.
  • In-flight requests are aborted as soon as the query moves on.
  • isEmpty is only true once a search has actually run, so an untouched search box never reads as "no results".

components/search/GlobalSearch.tsx — the search input plus grouped results, with a heading per non-empty category, loading, error and empty states, an accessible live count and a clear action.

Test coverage

hooks/__tests__/useGlobalSearch.test.ts (13 tests)

  • Categorisation: a mixed result set groups into all three categories in canonical order with the right labels and members; categories with no results are omitted.
  • States: idle start with no service call; loading while in flight; empty only after a search has run; whitespace-only queries never reach the service.
  • Errors: a service failure surfaces its message and drops stale results; a non-Error rejection falls back to a generic message; a later successful query clears the error.
  • Race conditions: the previous request is aborted when the query changes, and a stale response resolving after a newer query is ignored.
  • Reset: emptying the query and calling clear() both restore the idle state.

components/search/__tests__/GlobalSearch.test.tsx (14 tests)

  • Categorisation: the three headings render in canonical order; each result lands under its own category region with the right member count; subtitles render; a category with no matches gets no heading; a follow-up query re-categorises and drops the previous groups.
  • Selection: the selected result is reported to the caller, and the component does not throw without an onSelect handler.
  • States: loading, empty (quoting the query), error, clear, and no service call for whitespace-only input.

services/__tests__/globalSearchService.test.ts (11 tests)

Canonical category order, request shape with a trimmed query, empty-query short-circuit, normalisation of wrapped and bare-array responses, explicit href preservation, title fallback, malformed-record rejection, missing and non-array results, error propagation and abort-signal forwarding.

Mocking of external dependencies

@/lib/api (the shared axios instance) is mocked in the service tests, and globalSearchService itself is mocked in the hook and component tests. No real HTTP, wallet or WebSocket call is made anywhere in the suite. The race-condition tests drive the timing explicitly with deferred promises rather than timers, so they are deterministic rather than timing-dependent.

Verification

  • npx jest services/__tests__/globalSearchService.test.ts hooks/__tests__/useGlobalSearch.test.ts components/search/__tests__/GlobalSearch.test.tsx — 38 tests pass.
  • pnpm test — the full suite goes from 921 to 959 tests with no change to the set of pre-existing failures.
  • npx eslint on every changed file — no errors.
  • pnpm run type-check — no new errors.

Note for the maintainer

CI on main is currently red before any of this, and these changes do not fix or worsen it:

  1. components/mobile/MobileFooter.tsx has lost every quote character in the file (line 1 reads ​`use client and line 3 import React from react). This is a hard parse error that fails pnpm run lint, pnpm run type-check and pnpm run build on main today.
  2. 21 test suites already fail on main, largely around the wallet/Freighter mocks (useWallet, useTheme, WalletConnect, MultiSigApprovals and related).

Both look like they need a maintainer decision rather than a drive-by fix from a test PR, so I have deliberately left them untouched to keep this diff scoped to the issue.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Deb-Auth Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

[Test] Component: Global Unified Search Categorization

1 participant