Skip to content

Test: Component: Driver Job Marketplace Advanced Search Filters - #528

Open
Deb-Auth wants to merge 1 commit into
SwiftChainn:mainfrom
Deb-Auth:test-comp-driver-marketplace
Open

Test: Component: Driver Job Marketplace Advanced Search Filters#528
Deb-Auth wants to merge 1 commit into
SwiftChainn:mainfrom
Deb-Auth:test-comp-driver-marketplace

Conversation

@Deb-Auth

Copy link
Copy Markdown

closes #496

Summary

Adds automated tests for the state management of the location and cargo type filters in the driver job marketplace, together with the filter controls themselves.

The marketplace at /driver/jobs had no advanced search filters at the time of writing, so there was no filter state to test. This PR adds them following the project's Component -> Hook -> Service layering, wires them into the existing job board page, and then tests the state management thoroughly.

What was added

services/driverJobService.ts — a CargoType union (general, fragile, perishable, hazardous, oversized, refrigerated), a CARGO_TYPES list for rendering, and an optional cargoType field on DeliveryJob. The field is optional so the change is backwards-compatible with jobs the backend has not yet backfilled.

hooks/useJobFilters.ts — owns the advanced-search state.

  • Three independent filters: keyword, location and cargo type. They combine with AND, and each unset filter is a no-op.
  • Location matches the region, pickup address or drop-off address, case-insensitively and ignoring surrounding whitespace. Cargo type is an exact match.
  • availableLocations and availableCargoTypes are derived from the current job pool, de-duplicated and sorted, so the dropdowns never offer a value that would return nothing.
  • Filtering happens client-side over the pool the board already holds, so changing a filter never triggers a refetch and the driver keeps their place in the list.

features/driver/components/JobFilters.tsx — the presentational control strip: keyword input, location select, cargo type select, a live match count and a Clear All action that appears only while a filter is active.

app/(dashboard)/driver/jobs/page.tsx — renders the filters above the grid, drives the grid from filteredJobs, and adds a distinct "No jobs match your filters" state so an empty filtered result is not confused with an empty marketplace.

Test coverage

hooks/__tests__/useJobFilters.test.ts (17 tests)

  • Happy path: initial state is unfiltered; filtering by location, by cargo type, by keyword, and by location and cargo type combined.
  • Derived data: available locations and cargo types are de-duplicated and sorted.
  • State management: each filter stays independent when another changes; clearing one filter back to its empty value becomes a no-op; resetFilters clears all three at once; active filters survive a refresh of the job pool.
  • Edge cases: whitespace-only keyword is not treated as an active filter; matching is case- and whitespace-insensitive; no matches yields an empty list with hasActiveFilters still true; jobs without a cargo type are excluded once a cargo type filter is set; an empty job pool does not throw.

features/driver/components/__tests__/JobFilters.test.tsx (14 tests)

  • Rendering: all three controls present and labelled; location options plus the "all locations" entry; a human-readable label for every cargo type; current filter values reflected as selected options; an empty location list degrades gracefully.
  • Interaction: selections and keystrokes are reported to the caller, including clearing a select back to the "all" option.
  • Active filter summary: hidden while idle, correct and correctly pluralised match count including zero, and Clear All reported.
  • An integration test wires the real useJobFilters to the real JobFilters and asserts that the visible job list narrows as filters are applied and is restored on reset.

Mocking of external dependencies

The filter layer is pure state over data already in memory, so it needs no transport mocks. driverJobService (axios) is untouched by these tests and is never reached from them, which keeps the suite deterministic.

Verification

  • npx jest hooks/__tests__/useJobFilters.test.ts features/driver/components/__tests__/JobFilters.test.tsx — 31 tests pass.
  • pnpm test — the full suite goes from 921 to 952 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: Driver Job Marketplace Advanced Search Filters

1 participant