Skip to content

test : added unit tests for hooks/useSiteSearch hook - #10

Open
tmdeveloper007 wants to merge 2 commits into
mainfrom
#8425
Open

tmdeveloper007 wants to merge 2 commits into
mainfrom
#8425

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Owner

Summary of What Has Been Done

Created hooks/useSiteSearch.test.ts with comprehensive unit tests covering:

  • Returns empty initial state (query='', results=[], hasQuery=false)
  • setQuery updates query immediately
  • hasQuery is true when query has non-whitespace content
  • hasQuery is false for whitespace-only query
  • clear resets query, results, and hasQuery to initial state
  • Results reflect the debounced query via searchDomains
  • Returns empty results for non-matching query
  • isSearching is false initially and when query matches debounced value
  • Custom domains passed via the domains parameter are used for searching
  • Multiple setQuery calls update state each time

Mocked useDebounce from @/hooks/useDebounce to return the value immediately (bypassing the 120ms delay) and mocked searchDomains from @/lib/search/fuzzySearch for controlled fixture data.

Changes Made

  • New file: hooks/useSiteSearch.test.ts

Impact it Made

Adds first unit test coverage for the useSiteSearch hook, ensuring the search state management and result filtering work correctly under rapid input scenarios.

Closes #8425.

Note: please assign this PR to the tmdeveloper007 account.

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