mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Add Playlists to the Other search tab
Domains and Playlists are Collections, so the Other tab searches both with the existing /api/collections/search (by kind) instead of a Domain-only endpoint. The search and the estimate share search_collections_query. The search now loads each Collection's Downloads up front instead of once per Collection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d0b9355beb
commit
65e3325e51
12 changed files with 160 additions and 167 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import {act, render, screen} from '../test-utils';
|
||||
import {OtherSearchView} from './Search';
|
||||
import {searchChannels, searchDomains, 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,7 +9,7 @@ import {searchChannels, searchDomains, searchRepos} from '../api';
|
|||
jest.mock('../api', () => ({
|
||||
...jest.requireActual('../api'),
|
||||
searchChannels: jest.fn(),
|
||||
searchDomains: jest.fn(),
|
||||
searchCollections: jest.fn(),
|
||||
searchRepos: jest.fn(),
|
||||
}));
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ beforeEach(() => {
|
|||
searchChannels.mockReset();
|
||||
searchRepos.mockReset();
|
||||
searchRepos.mockResolvedValue({repos: [], total: 0});
|
||||
searchDomains.mockReset();
|
||||
searchDomains.mockResolvedValue({domains: []});
|
||||
searchCollections.mockReset();
|
||||
searchCollections.mockResolvedValue({collections: []});
|
||||
});
|
||||
|
||||
test('pending: shows a loader, not "No Channels"', () => {
|
||||
|
|
@ -121,39 +121,54 @@ describe('Repos', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Domains', () => {
|
||||
test('empty: shows "No Domains"', async () => {
|
||||
// Domains and Playlists are Collections searched by kind.
|
||||
describe.each([
|
||||
['domain', 'Domains', 'example.com', '/archives?domain=example.com'],
|
||||
['playlist', 'Playlists', 'Road Trip', '/playlists/3'],
|
||||
])('%s Collections', (kind, title, name, href) => {
|
||||
const collectionsOf = (wanted, collections) => (k) => Promise.resolve({collections: k === wanted ? collections : []});
|
||||
|
||||
test(`empty: shows "No ${title}"`, async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
render(<OtherSearchView loading={false}/>, {query: {searchParams: new URLSearchParams('q=nothing')}});
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText(`No ${title}`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('nothing to search by: shows none without fetching', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('No Domains')).toBeInTheDocument();
|
||||
expect(screen.getByText(`No ${title}`)).toBeInTheDocument();
|
||||
expect(searchCollections).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('failed: shows an error only in the Domains section', async () => {
|
||||
test(`failed: shows an error only in the ${title} section`, async () => {
|
||||
searchChannels.mockResolvedValue({channels: [{id: 1, name: 'Cooking'}]});
|
||||
searchDomains.mockRejectedValue(new Error('boom'));
|
||||
searchCollections.mockImplementation(k => k === kind ? Promise.reject(new Error('boom')) : Promise.resolve({collections: []}));
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {
|
||||
});
|
||||
try {
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
render(<OtherSearchView loading={false}/>, {query: {searchParams: new URLSearchParams('q=x')}});
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('Cooking')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Could not fetch the domains/)).toBeInTheDocument();
|
||||
expect(screen.getByText(new RegExp(`Could not fetch the ${title.toLowerCase()}`))).toBeInTheDocument();
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('loaded: lists domains by the search, linked to their archives', async () => {
|
||||
test('loaded: lists them by the search and tags, linked', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
searchDomains.mockResolvedValue({domains: [{id: 3, domain: 'example.com', tag_name: null}]});
|
||||
const searchParams = new URLSearchParams('q=example&tag=News');
|
||||
searchCollections.mockImplementation(collectionsOf(kind, [{id: 3, name, kind, tag_name: null}]));
|
||||
const searchParams = new URLSearchParams('q=road&tag=News');
|
||||
render(<OtherSearchView loading={false}/>, {query: {searchParams}});
|
||||
await act(async () => {
|
||||
});
|
||||
expect(searchDomains).toHaveBeenCalledWith(['News'], 'example');
|
||||
expect(screen.getByText('example.com').closest('a')).toHaveAttribute('href', '/archives?domain=example.com');
|
||||
expect(searchCollections).toHaveBeenCalledWith(kind, ['News'], 'road');
|
||||
expect(screen.getByText(name).closest('a')).toHaveAttribute('href', href);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue