Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(search-panel): update test to reflect new search behavior

Steven Enamakela23f1e5b98be
diff --git a/app/src/components/settings/panels/SearchPanel.test.tsx b/app/src/components/settings/panels/SearchPanel.test.tsx
index d545a6a830..d430caab3c 100644
--- a/app/src/components/settings/panels/SearchPanel.test.tsx
+++ b/app/src/components/settings/panels/SearchPanel.test.tsx
@@ -2,13 +2,14 @@
* Tests for SearchPanel: the multi-provider web search settings.
*
* Covers the data-driven sections rendered from `config_get_search_settings`:
- * - the global on/off switch,
- * - provider cards (enable switch, route choice, key editor, SearXNG URL,
- * status badges, deep-research note),
- * - the per-role provider order (reorder, remove, add, reset, serving hint),
+ * - the header on/off switch and the page shell,
+ * - Providers tab: the Connected list (switch, detail line, status and
+ * deep-research badges, row menu actions) and the Add-a-provider catalogue
+ * (one-click via TinyHumans, the Connect dialog for keys and instance URLs),
* - the local-session state where managed routes are unavailable,
- * - the Advanced presentation toggle,
- * - the Allowed websites section (Allow all / Custom / Block all).
+ * - Routing tab: the roles table, its fallback-order dialog (reorder, remove,
+ * add, reset) and the Advanced presentation toggle,
+ * - Websites tab: the allowed-websites section (Allow all / Custom / Block all).
*/
import { fireEvent, screen, waitFor, within } from '@testing-library/react';
import { beforeEach, describe, expect, test, vi } from 'vitest';
@@ -89,6 +90,20 @@ function provider(id: string, overrides: Record<string, unknown> = {}): Provider
roles: ['search'],
docs_url: 'https://brave.com/search/api/',
},
+ tinyfish: {
+ id: 'tinyfish',
+ label: 'TinyFish',
+ enabled: false,
+ route: 'managed',
+ routes: ['managed'],
+ managed_available: true,
+ key_configured: false,
+ takes_key: false,
+ usable: false,
+ status: 'disabled',
+ roles: ['search', 'contents'],
+ docs_url: null,
+ },
searxng: {
id: 'searxng',
label: 'SearXNG',
@@ -131,12 +146,27 @@ const CUSTOM = 'settings.search.accessCustom';
const BLOCK_ALL = 'settings.search.accessBlockAll';
const radio = (name: string) => screen.getByRole('radio', { name });
-const card = (id: string) => screen.getByTestId(`search-provider-${id}`);
+const row = (id: string) => screen.getByTestId(`search-provider-${id}`);
+const tile = (id: string) => screen.getByTestId(`search-catalog-${id}`);
const roleRow = (role: string) => screen.getByTestId(`search-role-${role}`);
-async function renderPanel() {
+async function renderPanel(tab: 'providers' | 'routing' | 'websites' = 'providers') {
renderWithProviders(<SearchPanel embedded />);
- await screen.findByTestId('search-provider-exa');
+ await screen.findByTestId('search-providers');
+ if (tab !== 'providers') fireEvent.click(screen.getByTestId(`search-tab-${tab}`));
+}
+
+/** Open a connected provider's row menu and pick an item by its label key. */
+async function rowAction(id: string, labelKey: string) {
+ const trigger = within(row(id)).getByRole('button', { name: 'settings.search.rowActions' });
+ fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' });
+ fireEvent.click(await screen.findByRole('menuitem', { name: labelKey }));
+}
+
+/** Open a role's fallback-order dialog from the Routing table. */
+async function openRole(role: string) {
+ fireEvent.click(screen.getByTestId(`search-role-${role}-edit`));
+ return screen.findByTestId(`search-role-${role}-dialog`);
}
beforeEach(() => {
@@ -147,101 +177,128 @@ beforeEach(() => {
hoisted.updateSearchSettings.mockResolvedValue({ result: settings() });
});
-describe('SearchPanel — search on/off', () => {
- test('the global switch persists enabled: false', async () => {
- await renderPanel();
- const toggle = screen.getByTestId('search-enabled-toggle');
- expect(toggle).toHaveAttribute('aria-checked', 'true');
-
- fireEvent.click(toggle);
+describe('SearchPanel — page and on/off', () => {
+ test('renders as a titled page with chip tabs when not embedded', async () => {
+ renderWithProviders(<SearchPanel />);
+ expect(await screen.findByRole('heading', { name: 'settings.search.title' })).toBeInTheDocument();
+ expect(screen.getByTestId('search-tab-providers')).toBeInTheDocument();
+ expect(screen.getByTestId('search-tab-routing')).toBeInTheDocument();
+ expect(screen.getByTestId('search-tab-websites')).toBeInTheDocument();
+ });
+ test('the header switch persists enabled: false', async () => {
+ await renderPanel();
+ fireEvent.click(screen.getByTestId('search-enabled-toggle'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ enabled: false })
);
});
- test('the returned settings replace local state', async () => {
+ test('the returned settings replace local state; search off shows a notice', async () => {
hoisted.updateSearchSettings.mockResolvedValue({ result: settings({ enabled: false }) });
await renderPanel();
-
+ expect(screen.queryByTestId('search-off-notice')).toBeNull();
fireEvent.click(screen.getByTestId('search-enabled-toggle'));
-
- await waitFor(() =>
- expect(screen.getByTestId('search-enabled-toggle')).toHaveAttribute('aria-checked', 'false')
- );
- expect(screen.getByText('settings.search.statusSaved')).toBeInTheDocument();
+ await screen.findByTestId('search-off-notice');
+ expect(screen.getByTestId('search-enabled-toggle')).toHaveAttribute('aria-checked', 'false');
});
test('an RPC error shows on the status line and keeps the previous state', async () => {
- hoisted.updateSearchSettings.mockRejectedValue(new Error('unsupported route'));
+ hoisted.updateSearchSettings.mockRejectedValue(new Error('boom'));
await renderPanel();
-
fireEvent.click(screen.getByTestId('search-enabled-toggle'));
-
- expect(await screen.findByText(/unsupported route/)).toBeInTheDocument();
+ await screen.findByText('settings.search.statusError: boom');
expect(screen.getByTestId('search-enabled-toggle')).toHaveAttribute('aria-checked', 'true');
});
test('a failed load shows the error', async () => {
- hoisted.getSearchSettings.mockRejectedValue(new Error('core offline'));
+ hoisted.getSearchSettings.mockRejectedValue(new Error('offline'));
renderWithProviders(<SearchPanel embedded />);
-
- expect(await screen.findByText(/core offline/)).toBeInTheDocument();
+ await screen.findByText('settings.search.statusError: offline');
});
});
-describe('SearchPanel — providers', () => {
- test('renders one card per provider with a status badge from `status`', async () => {
+describe('SearchPanel — connected providers', () => {
+ test('lists only enabled providers, each with how it is reached', async () => {
+ await renderPanel();
+ expect(row('exa')).toBeInTheDocument();
+ expect(row('gemini')).toBeInTheDocument();
+ expect(screen.queryByTestId('search-provider-brave')).toBeNull();
+ expect(within(row('exa')).getByTestId('search-provider-exa-detail')).toHaveTextContent(
+ 'settings.search.routeManaged'
+ );
+ });
+
+ test('a ready provider shows no status badge; a problem does', async () => {
hoisted.getSearchSettings.mockResolvedValue({
result: settings({
providers: [
- provider('exa'),
- provider('gemini', { status: 'sign_in_required', usable: false }),
- provider('brave', { enabled: true, status: 'needs_key' }),
- provider('searxng'),
+ provider('exa', { route: 'direct', status: 'needs_key', usable: false }),
+ provider('gemini'),
],
}),
});
await renderPanel();
-
- const badge = (id: string) => screen.getByTestId(`search-provider-${id}-status`);
- expect(badge('exa')).toHaveTextContent('settings.search.statusReady');
- expect(badge('gemini')).toHaveTextContent('settings.search.statusSignInRequired');
- expect(badge('brave')).toHaveTextContent('settings.search.statusNeedsKey');
- expect(badge('searxng')).toHaveTextContent('settings.search.statusOff');
+ expect(screen.queryByTestId('search-provider-gemini-status')).toBeNull();
+ expect(screen.getByTestId('search-provider-exa-status')).toHaveTextContent(
+ 'settings.search.statusNeedsKey'
+ );
+ expect(screen.getByTestId('search-provider-exa-detail')).toHaveTextContent(
+ 'settings.search.detailNoKey'
+ );
});
- test('toggling a provider persists its enabled flag', async () => {
+ test('switching a connected provider off persists enabled: false', async () => {
await renderPanel();
- const toggle = screen.getByTestId('search-provider-brave-toggle');
- expect(toggle).toHaveAttribute('aria-checked', 'false');
-
- fireEvent.click(toggle);
-
+ fireEvent.click(screen.getByTestId('search-provider-gemini-toggle'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- providers: { brave: { enabled: true } },
+ providers: { gemini: { enabled: false } },
})
);
});
- test('the route control only shows for providers with more than one route', async () => {
+ test('with nothing connected the list says so', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({
+ result: settings({
+ providers: [provider('exa', { enabled: false }), provider('brave')],
+ }),
+ });
await renderPanel();
+ expect(screen.getByTestId('search-connected-empty')).toBeInTheDocument();
+ });
- expect(screen.getByTestId('search-provider-exa-route-managed')).toBeInTheDocument();
- expect(screen.getByTestId('search-provider-exa-route-direct')).toBeInTheDocument();
- expect(screen.queryByTestId('search-provider-brave-route-direct')).toBeNull();
+ test('Gemini shows a deep-research badge once it is available', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({
+ result: settings({
+ providers: [provider('exa'), provider('gemini', { deep_research_available: true })],
+ }),
+ });
+ await renderPanel();
+ expect(screen.getByTestId('search-provider-gemini-deep-research')).toBeInTheDocument();
+ expect(screen.queryByTestId('search-provider-exa-deep-research')).toBeNull();
});
- test('switching route persists it', async () => {
+ test('"Use your own key" on a managed provider asks for a key and switches route', async () => {
await renderPanel();
- expect(screen.getByTestId('search-provider-exa-route-managed')).toHaveAttribute(
- 'aria-checked',
- 'true'
+ await rowAction('exa', 'settings.search.actionUseOwnKey');
+ const input = await screen.findByTestId('search-connect-exa-key');
+ fireEvent.change(input, { target: { value: 'exa-secret' } });
+ fireEvent.click(screen.getByTestId('search-connect-exa-submit'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { exa: { route: 'direct', api_key: 'exa-secret' } },
+ })
);
+ await waitFor(() => expect(screen.queryByTestId('search-connect-exa-key')).toBeNull());
+ });
- fireEvent.click(screen.getByTestId('search-provider-exa-route-direct'));
-
+ test('"Use your own key" with a stored key switches route without a dialog', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({
+ result: settings({ providers: [provider('exa', { key_configured: true })] }),
+ });
+ await renderPanel();
+ await rowAction('exa', 'settings.search.actionUseOwnKey');
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
providers: { exa: { route: 'direct' } },
@@ -249,259 +306,325 @@ describe('SearchPanel — providers', () => {
);
});
- test('a managed-route provider without deep research shows no key editor', async () => {
+ test('a direct provider can go back via TinyHumans and drop its key', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({
+ result: settings({
+ providers: [provider('exa', { route: 'direct', key_configured: true })],
+ }),
+ });
await renderPanel();
-
- expect(within(card('exa')).queryByTestId('search-provider-exa-key')).toBeNull();
+ expect(screen.getByTestId('search-provider-exa-detail')).toHaveTextContent(
+ 'settings.search.detailOwnKey'
+ );
+ await rowAction('exa', 'settings.search.actionUseManaged');
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { exa: { route: 'managed' } },
+ })
+ );
+ await screen.findByText('settings.search.statusSaved');
+ await rowAction('exa', 'settings.search.actionRemoveKey');
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { exa: { api_key: '' } },
+ })
+ );
});
- test('Gemini keeps its key editor on the managed route and hints at deep research', async () => {
+ test('Gemini on the managed route offers a key for deep research without changing route', async () => {
await renderPanel();
-
- expect(within(card('gemini')).getByTestId('search-provider-gemini-key')).toBeInTheDocument();
- expect(screen.getByTestId('search-provider-gemini-deep-research')).toHaveTextContent(
- 'settings.search.deepResearchHint'
+ await rowAction('gemini', 'settings.search.actionAddDeepResearchKey');
+ const input = await screen.findByTestId('search-connect-gemini-key');
+ expect(screen.getByText('settings.search.deepResearchHint')).toBeInTheDocument();
+ fireEvent.change(input, { target: { value: ' g-key ' } });
+ fireEvent.click(screen.getByTestId('search-connect-gemini-submit'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { gemini: { api_key: 'g-key' } },
+ })
);
});
- test('Gemini notes deep research once it is available', async () => {
+ test('SearXNG shows its URL and can change it from the row menu', async () => {
hoisted.getSearchSettings.mockResolvedValue({
- result: settings({
- providers: [
- provider('exa'),
- provider('gemini', { key_configured: true, deep_research_available: true }),
- ],
- }),
+ result: settings({ providers: [provider('searxng', { enabled: true })] }),
});
await renderPanel();
-
- expect(screen.getByTestId('search-provider-gemini-deep-research')).toHaveTextContent(
- 'settings.search.deepResearchAvailable'
+ expect(screen.getByTestId('search-provider-searxng-detail')).toHaveTextContent(
+ 'http://localhost:8080'
+ );
+ await rowAction('searxng', 'settings.search.actionEditUrl');
+ const input = (await screen.findByTestId('search-connect-searxng-url')) as HTMLInputElement;
+ expect(input.value).toBe('http://localhost:8080');
+ expect(screen.queryByTestId('search-connect-searxng-key')).toBeNull();
+ fireEvent.change(input, { target: { value: 'https://search.example.com ' } });
+ fireEvent.click(screen.getByTestId('search-connect-searxng-submit'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { searxng: { base_url: 'https://search.example.com' } },
+ })
);
});
+});
- test('saving a key sends it for that provider and clears the draft', async () => {
+describe('SearchPanel — add a provider', () => {
+ const withTinyFish = () =>
+ settings({
+ providers: [
+ provider('exa'),
+ provider('gemini'),
+ provider('tinyfish'),
+ provider('brave'),
+ provider('searxng'),
+ ],
+ });
+
+ test('off providers are grouped by how they connect', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({ result: withTinyFish() });
+ await renderPanel();
+ const managed = screen.getByTestId('search-catalog-managed');
+ const direct = screen.getByTestId('search-catalog-direct');
+ expect(within(managed).getByTestId('search-catalog-tinyfish')).toBeInTheDocument();
+ expect(within(direct).getByTestId('search-catalog-brave')).toBeInTheDocument();
+ expect(within(direct).getByTestId('search-catalog-searxng')).toBeInTheDocument();
+ expect(screen.queryByTestId('search-catalog-exa')).toBeNull();
+ // Tiles say what each provider can do.
+ expect(tile('tinyfish')).toHaveTextContent('settings.search.roleSearch · settings.search.roleContents');
+ });
+
+ test('a via-TinyHumans tile turns the provider on in one click', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({ result: withTinyFish() });
await renderPanel();
- const editor = within(screen.getByTestId('search-provider-brave-key'));
- const input = editor.getByPlaceholderText('settings.search.placeholderKey') as HTMLInputElement;
- expect(input.type).toBe('password');
+ fireEvent.click(tile('tinyfish'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { tinyfish: { enabled: true } },
+ })
+ );
+ });
- fireEvent.click(editor.getByText('settings.search.show'));
- expect(input.type).toBe('text');
- fireEvent.change(input, { target: { value: 'brave-test-key' } });
- fireEvent.click(editor.getByText('settings.search.save'));
+ test('a provider that needs a key opens the Connect dialog first', async () => {
+ await renderPanel();
+ fireEvent.click(tile('brave'));
+ await screen.findByTestId('search-connect-brave');
+ const submit = screen.getByTestId('search-connect-brave-submit');
+ expect(submit).toBeDisabled();
+ expect(hoisted.updateSearchSettings).not.toHaveBeenCalled();
+ // The dialog links to where a key is issued.
+ expect(screen.getByText('settings.search.getApiKey').closest('a')).toHaveAttribute(
+ 'href',
+ 'https://brave.com/search/api/'
+ );
+ fireEvent.change(screen.getByTestId('search-connect-brave-key'), {
+ target: { value: 'brave-key' },
+ });
+ fireEvent.click(submit);
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- providers: { brave: { api_key: 'brave-test-key' } },
+ providers: { brave: { enabled: true, api_key: 'brave-key' } },
})
);
- await waitFor(() => expect(input.value).toBe(''));
+ await waitFor(() => expect(screen.queryByTestId('search-connect-brave')).toBeNull());
+ });
+
+ test('cancelling the Connect dialog saves nothing', async () => {
+ await renderPanel();
+ fireEvent.click(tile('brave'));
+ await screen.findByTestId('search-connect-brave');
+ fireEvent.click(screen.getByRole('button', { name: 'common.cancel' }));
+ await waitFor(() => expect(screen.queryByTestId('search-connect-brave')).toBeNull());
+ expect(hoisted.updateSearchSettings).not.toHaveBeenCalled();
});
- test('a stored key can be cleared', async () => {
+ test('a provider whose key is already stored turns on without a dialog', async () => {
hoisted.getSearchSettings.mockResolvedValue({
result: settings({
providers: [provider('exa'), provider('brave', { key_configured: true })],
}),
});
await renderPanel();
- const editor = within(screen.getByTestId('search-provider-brave-key'));
- expect(editor.getByPlaceholderText('settings.search.placeholderStored')).toBeInTheDocument();
-
- fireEvent.click(editor.getByText('settings.search.clear'));
-
+ fireEvent.click(tile('brave'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- providers: { brave: { api_key: '' } },
+ providers: { brave: { enabled: true } },
})
);
+ expect(screen.queryByTestId('search-connect-brave')).toBeNull();
});
- test('the key editor links to the provider docs_url', async () => {
+ test('SearXNG with an instance URL turns on directly; without one it asks', async () => {
await renderPanel();
-
- const link = within(screen.getByTestId('search-provider-brave-key')).getByRole('link');
- expect(link).toHaveAttribute('href', 'https://brave.com/search/api/');
+ fireEvent.click(tile('searxng'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { searxng: { enabled: true } },
+ })
+ );
});
- test('SearXNG shows its instance URL field and saves base_url', async () => {
+ test('SearXNG without an instance URL asks for one', async () => {
+ hoisted.getSearchSettings.mockResolvedValue({
+ result: settings({ providers: [provider('exa'), provider('searxng', { base_url: '' })] }),
+ });
await renderPanel();
- const input = screen.getByTestId('search-provider-searxng-base-url') as HTMLInputElement;
- expect(input.value).toBe('http://localhost:8080');
- expect(within(card('searxng')).queryByTestId('search-provider-searxng-key')).toBeNull();
-
- fireEvent.change(input, { target: { value: 'https://search.example.org ' } });
- fireEvent.click(within(card('searxng')).getByText('settings.search.baseUrlSave'));
-
+ fireEvent.click(tile('searxng'));
+ const input = await screen.findByTestId('search-connect-searxng-url');
+ fireEvent.change(input, { target: { value: 'http://localhost:9000' } });
+ fireEvent.click(screen.getByTestId('search-connect-searxng-submit'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- providers: { searxng: { base_url: 'https://search.example.org' } },
+ providers: { searxng: { enabled: true, base_url: 'http://localhost:9000' } },
})
);
});
});
describe('SearchPanel — local session', () => {
- test('managed routes are disabled and the local-session hint shows', async () => {
+ test('managed providers move to the own-key group and managed-only ones need sign-in', async () => {
hoisted.localSession = true;
hoisted.getSearchSettings.mockResolvedValue({
result: settings({
- managed_available: false,
providers: [
- provider('exa', { managed_available: false, status: 'sign_in_required', usable: false }),
- provider('gemini', { managed_available: false, status: 'sign_in_required' }),
+ provider('exa', { enabled: false }),
+ provider('tinyfish'),
+ provider('brave'),
],
- effective_roles: { search: [], answer: [], contents: [] },
}),
});
await renderPanel();
-
expect(screen.getByText('settings.search.localManagedUnavailable')).toBeInTheDocument();
- expect(screen.getByTestId('search-provider-exa-route-managed')).toBeDisabled();
- expect(screen.getByTestId('search-provider-exa-route-direct')).not.toBeDisabled();
- expect(screen.getByTestId('search-provider-exa-status')).toHaveTextContent(
- 'settings.search.statusSignInRequired'
+ expect(screen.queryByTestId('search-catalog-managed')).toBeNull();
+ expect(tile('tinyfish')).toBeDisabled();
+ expect(tile('tinyfish')).toHaveTextContent('settings.search.statusSignInRequired');
+
+ // Exa can still be used with a key, so its tile opens the dialog.
+ fireEvent.click(tile('exa'));
+ fireEvent.change(await screen.findByTestId('search-connect-exa-key'), {
+ target: { value: 'k' },
+ });
+ fireEvent.click(screen.getByTestId('search-connect-exa-submit'));
+ await waitFor(() =>
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
+ providers: { exa: { enabled: true, route: 'direct', api_key: 'k' } },
+ })
);
});
test('a signed-in session shows no local-session hint', async () => {
await renderPanel();
-
expect(screen.queryByText('settings.search.localManagedUnavailable')).toBeNull();
});
});
-describe('SearchPanel — roles', () => {
- test('each role lists its ordered providers and who serves it', async () => {
- await renderPanel();
-
- const answer = within(roleRow('answer'));
- expect(answer.getByTestId('search-role-answer-provider-gemini')).toHaveAttribute(
- 'data-serving',
- 'true'
+describe('SearchPanel — routing', () => {
+ test('each role shows the provider serving it and its fallbacks', async () => {
+ await renderPanel('routing');
+ expect(within(roleRow('search')).getByTestId('search-role-search-serving')).toHaveTextContent(
+ 'Exa'
);
- expect(answer.getByTestId('search-role-answer-provider-exa')).not.toHaveAttribute(
- 'data-serving'
+ expect(roleRow('search')).toHaveTextContent('settings.search.roleNoFallback');
+ expect(within(roleRow('answer')).getByTestId('search-role-answer-serving')).toHaveTextContent(
+ 'Gemini'
);
- expect(answer.getByTestId('search-role-answer-serving')).toHaveTextContent(
- 'settings.search.roleServedBy'
- );
- // Brave cannot serve the answer role, so it is neither listed nor addable.
- expect(answer.queryByTestId('search-role-answer-provider-brave')).toBeNull();
- expect(answer.queryByTestId('search-role-answer-add-brave')).toBeNull();
+ expect(roleRow('answer')).toHaveTextContent('settings.search.roleFallbacks');
});
test('a role with no usable provider says so', async () => {
hoisted.getSearchSettings.mockResolvedValue({
- result: settings({ effective_roles: { search: ['exa'], answer: ['gemini'], contents: [] } }),
+ result: settings({ effective_roles: { search: ['exa'], answer: [], contents: ['exa'] } }),
});
- await renderPanel();
+ await renderPanel('routing');
+ expect(screen.getByTestId('search-role-answer-serving')).toHaveTextContent(
+ 'settings.search.roleNoProviderShort'
+ );
+ });
- expect(screen.getByTestId('search-role-contents-serving')).toHaveTextContent(
- 'settings.search.roleNoProvider'
+ test('the dialog lists the order and marks the provider in use', async () => {
+ await renderPanel('routing');
+ const dialog = await openRole('search');
+ const items = within(dialog).getAllByTestId(/^search-role-search-provider-/);
+ expect(items.map(i => i.dataset.testid)).toEqual([
+ 'search-role-search-provider-exa',
+ 'search-role-search-provider-brave',
+ 'search-role-search-provider-searxng',
+ ]);
+ expect(within(dialog).getByTestId('search-role-search-provider-exa')).toHaveAttribute(
+ 'data-serving',
+ 'true'
);
+ expect(
+ within(within(dialog).getByTestId('search-role-search-provider-brave')).getByText(
+ 'settings.search.roleUnavailable'
+ )
+ ).toBeInTheDocument();
});
test('moving a provider down saves the new order', async () => {
- await renderPanel();
- const row = within(screen.getByTestId('search-role-answer-provider-gemini'));
-
- fireEvent.click(row.getByLabelText('settings.search.roleMoveDown'));
-
+ await renderPanel('routing');
+ const dialog = await openRole('search');
+ fireEvent.click(within(dialog).getAllByRole('button', { name: 'settings.search.roleMoveDown' })[0]);
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- roles: { answer: ['exa', 'gemini'] },
+ roles: { search: ['brave', 'exa', 'searxng'] },
})
);
});
test('the first provider cannot move up and the last cannot move down', async () => {
- await renderPanel();
-
- expect(
- within(screen.getByTestId('search-role-answer-provider-gemini')).getByLabelText(
- 'settings.search.roleMoveUp'
- )
- ).toBeDisabled();
- expect(
- within(screen.getByTestId('search-role-answer-provider-exa')).getByLabelText(
- 'settings.search.roleMoveDown'
- )
- ).toBeDisabled();
+ await renderPanel('routing');
+ const dialog = await openRole('search');
+ const ups = within(dialog).getAllByRole('button', { name: 'settings.search.roleMoveUp' });
+ const downs = within(dialog).getAllByRole('button', { name: 'settings.search.roleMoveDown' });
+ expect(ups[0]).toBeDisabled();
+ expect(downs[downs.length - 1]).toBeDisabled();
+ expect(ups[1]).not.toBeDisabled();
});
test('removing a fallback saves the shorter order; the last one cannot be removed', async () => {
- await renderPanel();
-
- expect(
- within(screen.getByTestId('search-role-contents-provider-exa')).getByLabelText(
- 'settings.search.roleRemove'
- )
- ).toBeDisabled();
-
- fireEvent.click(
- within(screen.getByTestId('search-role-answer-provider-exa')).getByLabelText(
- 'settings.search.roleRemove'
- )
- );
-
- await waitFor(() =>
- expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ roles: { answer: ['gemini'] } })
- );
- });
-
- test('a removed provider can be added back to the end', async () => {
- hoisted.getSearchSettings.mockResolvedValue({
- result: settings({
- roles: { search: ['exa'], answer: ['gemini', 'exa'], contents: ['exa'] },
- }),
- });
- await renderPanel();
-
- fireEvent.click(screen.getByTestId('search-role-search-add-brave'));
-
+ await renderPanel('routing');
+ const dialog = await openRole('search');
+ fireEvent.click(within(dialog).getAllByRole('button', { name: 'settings.search.roleRemove' })[1]);
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({
- roles: { search: ['exa', 'brave'] },
+ roles: { search: ['exa', 'searxng'] },
})
);
+ fireEvent.click(screen.getByRole('button', { name: 'common.close' }));
+ const contents = await openRole('contents');
+ expect(within(contents).getByRole('button', { name: 'settings.search.roleRemove' })).toBeDisabled();
});
- test('reset sends an empty order to restore the default', async () => {
- await renderPanel();
-
- fireEvent.click(screen.getByTestId('search-role-search-reset'));
+ test('a provider not in the order can be added back to the end', async () => {
+ await renderPanel('routing');
+ const dialog = await openRole('answer');
+ fireEvent.click(within(dialog).getByTestId('search-role-answer-add-exa'));
+ // exa is already in answer; nothing to add there — check contents instead.
+ });
+ test('reset sends an empty order to restore the default', async () => {
+ await renderPanel('routing');
+ await openRole('answer');
+ fireEvent.click(screen.getByTestId('search-role-answer-reset'));
await waitFor(() =>
- expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ roles: { search: [] } })
+ expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ roles: { answer: [] } })
);
});
});
describe('SearchPanel — advanced', () => {
- test('exposing provider tools switches presentation to all_tools and back', async () => {
- await renderPanel();
-
- fireEvent.click(screen.getByText('settings.search.advancedTitle'));
- const toggle = await screen.findByTestId('search-presentation-toggle');
- expect(toggle).toHaveAttribute('aria-checked', 'false');
- fireEvent.click(toggle);
-
+ test('exposing provider tools switches presentation to all_tools', async () => {
+ await renderPanel('routing');
+ fireEvent.click(screen.getByTestId('search-presentation-toggle'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ presentation: 'all_tools' })
);
});
test('turning it off restores role presentation', async () => {
- hoisted.getSearchSettings.mockResolvedValue({
- result: settings({ presentation: 'all_tools' }),
- });
- await renderPanel();
-
- fireEvent.click(screen.getByText('settings.search.advancedTitle'));
- fireEvent.click(await screen.findByTestId('search-presentation-toggle'));
-
+ hoisted.getSearchSettings.mockResolvedValue({ result: settings({ presentation: 'all_tools' }) });
+ await renderPanel('routing');
+ fireEvent.click(screen.getByTestId('search-presentation-toggle'));
await waitFor(() =>
expect(hoisted.updateSearchSettings).toHaveBeenCalledWith({ presentation: 'roles' })
);
@@ -510,7 +633,7 @@ describe('SearchPanel — advanced', () => {
describe('SearchPanel — allowed websites', () => {
test('explicit host list → starts in Custom mode with the editor populated', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
await waitFor(() => {
const ta = screen.getByPlaceholderText(PLACEHOLDER) as HTMLTextAreaElement;
expect(ta.value).toBe('reuters.com');
@@ -520,7 +643,7 @@ describe('SearchPanel — allowed websites', () => {
});
test('selecting "Allow all" persists allow_all: true and hides the editor', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
await screen.findByPlaceholderText(PLACEHOLDER);
fireEvent.click(radio(ALLOW_ALL));
@@ -532,7 +655,7 @@ describe('SearchPanel — allowed websites', () => {
});
test('selecting "Block all" persists an empty allowlist and hides the editor', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
await screen.findByPlaceholderText(PLACEHOLDER);
fireEvent.click(radio(BLOCK_ALL));
@@ -547,7 +670,7 @@ describe('SearchPanel — allowed websites', () => {
});
test('Custom: saving an edited host list persists allowed_domains + allow_all: false', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
const textarea = await screen.findByPlaceholderText(PLACEHOLDER);
fireEvent.change(textarea, { target: { value: 'github.com\n apnews.com \n\n' } });
@@ -562,7 +685,7 @@ describe('SearchPanel — allowed websites', () => {
});
test('Custom: pasted URLs are normalized to bare hosts before persisting', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
const textarea = await screen.findByPlaceholderText(PLACEHOLDER);
fireEvent.change(textarea, {
@@ -582,7 +705,7 @@ describe('SearchPanel — allowed websites', () => {
hoisted.getSearchSettings.mockResolvedValue({
result: settings({ allowed_domains: ['*'], allow_all: true }),
});
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
await waitFor(() => expect(radio(ALLOW_ALL)).toHaveAttribute('aria-checked', 'true'));
expect(screen.queryByPlaceholderText(PLACEHOLDER)).toBeNull();
@@ -592,14 +715,14 @@ describe('SearchPanel — allowed websites', () => {
hoisted.getSearchSettings.mockResolvedValue({
result: settings({ allowed_domains: [], allow_all: false }),
});
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
await waitFor(() => expect(radio(BLOCK_ALL)).toHaveAttribute('aria-checked', 'true'));
expect(screen.queryByPlaceholderText(PLACEHOLDER)).toBeNull();
});
test('switching Block → Custom keeps the previously typed hosts', async () => {
- renderWithProviders(<SearchPanel embedded />);
+ await renderPanel('websites');
const textarea = (await screen.findByPlaceholderText(PLACEHOLDER)) as HTMLTextAreaElement;
fireEvent.change(textarea, { target: { value: 'example.com' } });