forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copies & renames useSearch to useBaseSearch in kolibri-common package
prereq to learningequality#12517
- Loading branch information
1 parent
365ed24
commit 6a495f5
Showing
4 changed files
with
1,074 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
packages/kolibri-common/composables/__mocks__/useBaseSearch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* `useBaseSearch` composable function mock. | ||
* | ||
* If default values are sufficient for tests, | ||
* you only need call `jest.mock('<useBaseSearch file path>')` | ||
* at the top of a test file. | ||
* | ||
* If you need to override some default values from some tests, | ||
* you can import a helper function `useBaseSearch` that accepts | ||
* an object with values to be overriden and use it together | ||
* with `mockImplementation` as follows: | ||
* | ||
* ``` | ||
* // eslint-disable-next-line import/named | ||
* import useBaseSearch, { useBaseSearch } from '<useBaseSearch file path>'; | ||
* | ||
* jest.mock('<useBaseSearch file path>') | ||
* | ||
* it('test', () => { | ||
* useBaseSearch.mockImplementation( | ||
* () => useBaseSearch({ classes: [{ id: 'class-1' }] }) | ||
* ); | ||
* }) | ||
* ``` | ||
* | ||
* You can reset your mock implementation back to default values | ||
* for other tests by calling the following in `beforeEach`: | ||
* | ||
* ``` | ||
* useBaseSearch.mockImplementation(() => useBaseSearch()) | ||
* ``` | ||
*/ | ||
|
||
const MOCK_DEFAULTS = { | ||
searchTerms: { | ||
learning_activities: {}, | ||
categories: {}, | ||
learner_needs: {}, | ||
channels: {}, | ||
accessibility_labels: {}, | ||
languages: {}, | ||
grade_levels: {}, | ||
}, | ||
displayingSearchResults: false, | ||
searchLoading: false, | ||
moreLoading: false, | ||
results: [], | ||
more: null, | ||
labels: null, | ||
search: jest.fn(), | ||
searchMore: jest.fn(), | ||
removeFilterTag: jest.fn(), | ||
clearSearch: jest.fn(), | ||
currentRoute: jest.fn(() => { | ||
// return a $route-flavored object to avoid undefined errors | ||
return { | ||
params: {}, | ||
query: {}, | ||
path: '', | ||
fullPath: '', | ||
name: '', | ||
meta: {}, | ||
}; | ||
}), | ||
}; | ||
|
||
export function useBaseSearch(overrides = {}) { | ||
return { | ||
...MOCK_DEFAULTS, | ||
...overrides, | ||
}; | ||
} | ||
|
||
export default jest.fn(() => useBaseSearch()); | ||
|
||
export const injectSearch = jest.fn(() => ({ | ||
availableLearningActivities: [], | ||
availableLibraryCategories: [], | ||
availableResourcesNeeded: [], | ||
availableGradeLevels: [], | ||
availableAccessibilityOptions: [], | ||
availableLanguages: [], | ||
availableChannels: [], | ||
searchableLabels: [], | ||
activeSearchTerms: [], | ||
})); | ||
|
||
export const searchKeys = []; |
Oops, something went wrong.