From 874582ac053f0010a4d2eb3346932ec0dfbe2e65 Mon Sep 17 00:00:00 2001 From: lightbulbman Date: Thu, 15 Oct 2026 21:52:46 +0100 Subject: [PATCH] fix: restore the Search with AI option on the Community Cloud tab --- .../ManageMenu/CommunityCloud/CloudSearch.tsx | 6 ++-- .../CommunityCloud/WithCloudSearchContext.tsx | 2 +- .../code-snippets-community-featured.spec.ts | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/js/components/ManageMenu/CommunityCloud/CloudSearch.tsx b/src/js/components/ManageMenu/CommunityCloud/CloudSearch.tsx index 4da2f3aa1..a39faf545 100644 --- a/src/js/components/ManageMenu/CommunityCloud/CloudSearch.tsx +++ b/src/js/components/ManageMenu/CommunityCloud/CloudSearch.tsx @@ -10,7 +10,7 @@ import { LoadingStatusNotices } from '../../common/LoadingStatusNotices' import { SnippetViewToggle } from '../../common/SnippetViewToggle' import { CloudSnippetAuthor, CloudSnippetCard } from '../../common/cloud/CloudSnippetCard' import { CloudSnippetsTable } from './CloudSnippetsTable' -import { useCloudSearch } from './WithCloudSearchContext' +import { parseSearchMethod, useCloudSearch } from './WithCloudSearchContext' import { SearchFilters } from './SearchFilters' import type { CloudSearchResults } from './WithCloudSearchContext' import type { TableNavProps } from '../../common/ListTable/TableNavigation' @@ -37,10 +37,10 @@ const SearchBox = () => { diff --git a/src/js/components/ManageMenu/CommunityCloud/WithCloudSearchContext.tsx b/src/js/components/ManageMenu/CommunityCloud/WithCloudSearchContext.tsx index 58d72aa8e..809b48748 100644 --- a/src/js/components/ManageMenu/CommunityCloud/WithCloudSearchContext.tsx +++ b/src/js/components/ManageMenu/CommunityCloud/WithCloudSearchContext.tsx @@ -91,7 +91,7 @@ const updateSearchQueryParams = (params: CloudSearchParams) => { [SEARCH_PARAM_VARS.type]: params.type || undefined, [SEARCH_PARAM_VARS.query]: params.query || undefined, [SEARCH_PARAM_VARS.status]: params.status || undefined, - [SEARCH_PARAM_VARS.method]: 'codevault' === params.method ? 'codevault' : undefined, + [SEARCH_PARAM_VARS.method]: 'term' === params.method ? undefined : params.method, [SEARCH_PARAM_VARS.category]: params.category || undefined }) } diff --git a/tests/e2e/code-snippets-community-featured.spec.ts b/tests/e2e/code-snippets-community-featured.spec.ts index e44ece556..2f91c07ed 100644 --- a/tests/e2e/code-snippets-community-featured.spec.ts +++ b/tests/e2e/code-snippets-community-featured.spec.ts @@ -31,6 +31,10 @@ const isFeaturedRequest = (url: URL): boolean => url.pathname.includes('/cloud/snippets/featured') || true === url.searchParams.get('rest_route')?.includes('/cloud/snippets/featured') +const isSearchRequest = (url: URL): boolean => + url.pathname.endsWith('/cloud/snippets') || + true === url.searchParams.get('rest_route')?.endsWith('/cloud/snippets') + const isSnippetDownloadRequest = (url: URL): boolean => url.pathname.includes('/cloud/snippets/501/download') || true === url.searchParams.get('rest_route')?.includes('/cloud/snippets/501/download') @@ -139,6 +143,35 @@ test.describe('Community Cloud Featured Snippets', () => { await expect(page.locator('.cloud-snippets-heading', { hasText: 'Featured Snippets' })).not.toBeVisible() }) + test('Searches with AI and keeps the method after a reload', async ({ page }) => { + const searchMethods: (string | null)[] = [] + + await page.route(isFeaturedRequest, route => route.fulfill({ + contentType: 'application/json', + body: JSON.stringify(makeFeaturedResponse()) + })) + await page.route(isSearchRequest, route => { + searchMethods.push(new URL(route.request().url()).searchParams.get('searchMethod')) + return route.fulfill({ + contentType: 'application/json', + body: JSON.stringify(makeFeaturedResponse()) + }) + }) + await openCommunityCloud(page) + + const searchMethod = page.getByLabel('Search method') + await searchMethod.selectOption({ label: 'Search with AI' }) + await page.locator('#cloud-search-query').fill('disable comments') + await page.locator('.cloud-search-form').getByRole('button', { name: /Search Cloud Library/i }).click() + + await expect.poll(() => searchMethods).toEqual(['ai']) + await expect(page).toHaveURL(/[?&]by=ai(?:&|$)/) + + await page.reload() + await expect(searchMethod).toHaveValue('ai') + await expect.poll(() => searchMethods).toEqual(['ai', 'ai']) + }) + test('Announces loading and error states while featured snippets resolve', async ({ page }) => { let releaseRequest: VoidFunction = () => undefined const requestPending = new Promise(resolve => {