Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copies & renames useSearch to useBaseSearch in kolibri-common package (On develop this time) #12566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions packages/kolibri-common/composables/__mocks__/useBaseSearch.js
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 = [];
Loading