diff --git a/app/src/api.js b/app/src/api.js index 142f7ec3..8b2a421b 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -2118,8 +2118,8 @@ export async function searchEstimateOthers(tagNames, searchStr) { } } -export async function searchChannels(tagNames) { - const body = {tag_names: tagNames}; +export async function searchChannels(tagNames, searchStr) { + const body = {tag_names: tagNames, search_str: searchStr}; const response = await apiPost(`${API_URI}/videos/channels/search`, body); if (response.ok) { const content = await response.json(); @@ -2129,6 +2129,16 @@ export async function searchChannels(tagNames) { } } +// Collections of `kind` whose name matches `searchStr` and/or which have any of the tags. +export async function searchCollections(kind, tagNames, searchStr) { + const body = {kind, tag_names: tagNames, search_str: searchStr}; + const response = await apiPost(`${COLLECTIONS_API}/search`, body); + if (response.ok) { + const content = await response.json(); + return {collections: content.collections}; + } +} + export async function getOutdatedZims() { const response = await apiGet(`${API_URI}/zim/outdated`); if (response.status === 200) { diff --git a/app/src/components/OtherSearchView.test.js b/app/src/components/OtherSearchView.test.js index e2526ec3..c4de3dc9 100644 --- a/app/src/components/OtherSearchView.test.js +++ b/app/src/components/OtherSearchView.test.js @@ -1,7 +1,7 @@ import React from 'react'; import {act, render, screen} from '../test-utils'; import {OtherSearchView} from './Search'; -import {searchChannels, searchRepos} from '../api'; +import {searchChannels, searchCollections, searchRepos} from '../api'; // What the search page's Other tab shows for each state of useSearchChannels. "No Channels" // must only appear once the server has confirmed there are none. @@ -9,6 +9,7 @@ import {searchChannels, searchRepos} from '../api'; jest.mock('../api', () => ({ ...jest.requireActual('../api'), searchChannels: jest.fn(), + searchCollections: jest.fn(), searchRepos: jest.fn(), })); @@ -18,6 +19,8 @@ beforeEach(() => { searchChannels.mockReset(); searchRepos.mockReset(); searchRepos.mockResolvedValue({repos: [], total: 0}); + searchCollections.mockReset(); + searchCollections.mockResolvedValue({collections: []}); }); test('pending: shows a loader, not "No Channels"', () => { @@ -117,3 +120,55 @@ describe('Repos', () => { expect(screen.getByText(/files