Add tests for search results components
Created by: attfarhan
This PR adds tests (not comprehensive) for components related to search results (SearchResults
, SearchResultsList
, FileMatch
, CodeExcerpt
).
It includes some small refactors and changes to make the components testable:
- Add
data-testid
attributes - Move
eventLogger
andisSourcegraphDotCom
toLayoutProps
so that we pass both of these as props into components that need them. These both required access to thewindow
global object, which we don't have when testing. - Add
searchRequest
toLayoutProps
so thesearch
request is passed in toSearchResults
as a prop so that we can mock/spy the function. - Be explicit in only requiring the
services
field when extendingExtensionsControllerProps
inSearchResultProps
.
There are more tests I want to add that require more refactoring, so this is just the first few that were easy to add.
Total coverage progress:
-
shared/src/components/CodeExcerpt.tsx
66.10% -> + 27.11% -> 93.22% -
web/src/search/results
0% -> +73.26% -> 73.26%