Skip to content

chore: add unit tests to filterSelectionState (plugin-hrm-form/src/states/resources/filterSelectionState/)#4059

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/add-unit-tests-filter-selection-state
Draft

chore: add unit tests to filterSelectionState (plugin-hrm-form/src/states/resources/filterSelectionState/)#4059
Copilot wants to merge 2 commits intomasterfrom
copilot/add-unit-tests-filter-selection-state

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Adds unit test coverage for the KHP and USCH filterSelectionState implementations, which drive reference data loading and search filter state management for their respective resource configurations.

New test files

  • src/___tests__/states/resources/filterSelectionState/khp.test.ts — 28 tests
  • src/___tests__/states/resources/filterSelectionState/usch.test.ts — 30 tests

Coverage per function

referenceLocationsInitialState — shape assertion for both implementations.

loadReferenceActionFunction — mocks getReferenceAttributeList (KHP) / getDistinctStringAttributes (USCH); asserts correct API call args, option deduplication, sort order, and info.name ?? value label fallback.

handleLoadReferenceLocationsAsyncActionFulfilled — per list type (Provinces/Regions/Cities for KHP; Country/Provinces/Cities for USCH), verifies referenceLocations update and cascading filterOptions recomputation. Key edge cases:

  • KHP: invalid province/region/city selections are cleared (uses validatedFilterSelections directly)
  • USCH Country: "United States" at index > 0 → moved to head and auto-selected; at index 0 → not auto-selected (containsDefaultOption requires index > 0); absent → no auto-selection
  • USCH Provinces/Cities: pre-existing selections are preserved even if absent from newly loaded options — because the implementation uses { ...defaultFilterSelection, ...validatedFilterSelections }, where absent keys do not override

handlerUpdateSearchFormAction — verifies cascading filter updates (province → region → city for KHP; country → province → city for USCH), invalidation of downstream selections when parent changes, and age-range filter mutual constraint logic (KHP).

Checklist

  • Corresponding issue has been opened
  • New tests added
  • Feature flags added
  • Strings are localized
  • Tested for chat contacts
  • Tested for call contacts

Other Related Issues

None

Verification steps

Run the new test suites:

cd plugin-hrm-form && node_modules/.bin/jest "filterSelectionState" --maxWorkers=1

Expected: 58 tests pass across 2 suites.

AFTER YOU MERGE

  1. Cut a release tag using the Github workflow. Wait for it to complete and notify in the #aselo-deploys Slack channel.
  2. Comment on the ticket with the release tag version AND any additional instructions required to configure an environment to test the changes.
  3. Only then move the ticket into the QA column in JIRA

You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P

Original prompt

This section details on the original issue you should resolve

<issue_title>chore: add unit tests to filterSelectionState (plugin-hrm-form/src/states/resources/filterSelectionState/)</issue_title>
<issue_description>### Context
plugin-hrm-form/src/states/resources/index.ts contains the Redux reducer for state management of "resources".

One of the actions handled by this reducer is loadReferenceLocationsAsyncAction.fulfilled. How this action is handled, is a parameterized function, handleLoadReferenceLocationsAsyncActionFulfilled, that depends on the implementation of the resources (different use cases have different resource shapes).
Each of this implementations expose a FilterSelectionState, as described in plugin-hrm-form/src/components/resources/mappingComponents/index.tsx
At the moment there are two of this implementations:

  • plugin-hrm-form/src/states/resources/filterSelectionState/khp/index.ts
  • plugin-hrm-form/src/states/resources/filterSelectionState/usch/index.ts

Each of this integrations expose three functions:

  • loadReferenceActionFunction: specifies "how to retrieve the references, which are lists of options used as search filters".
  • handleLoadReferenceLocationsAsyncActionFulfilled: specifies "how to update the state once the load reference action fulfills".
  • handlerUpdateSearchFormAction: specifies "how a state update is handled when interacting with the search forms".

Assignment

Write unit tests for both of this custom filterSelectionState implementations, taking into consideration it's differences. The tests must assert

  • Initial state is properly loaded onto resources reducer.
  • Mocking the API calls used for the actual implementation (returning mocked references), assert that loadReferenceActionFunction if fulfills, then the handleLoadReferenceLocationsAsyncActionFulfilled is called.
    • Assert that the state is properly handled, considering edge cases (e.g. usch implementation have two operating modes, one if the defaultCountryTarget is part of the references list and one if it's not).
  • Assert that handlerUpdateSearchFormAction performs the state updates accordingly.
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ations

Co-authored-by: gpaoloni <15805319+gpaoloni@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests to filterSelectionState chore: add unit tests to filterSelectionState (plugin-hrm-form/src/states/resources/filterSelectionState/) Mar 13, 2026
Copilot AI requested a review from gpaoloni March 13, 2026 21:35
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.

chore: add unit tests to filterSelectionState (plugin-hrm-form/src/states/resources/filterSelectionState/)

2 participants