mirror of
https://github.com/iflytek/skillhub.git
synced 2026-09-10 22:41:02 +00:00
fix(search): preserve empty-query discovery results
This commit is contained in:
parent
3739c7879b
commit
df85ea0e18
3 changed files with 25 additions and 1 deletions
|
|
@ -41,7 +41,19 @@ test.describe('Search Input (Real API)', () => {
|
|||
|
||||
// TC_SEARCH_INPUT_003 P0 - empty search shows the default discovery list
|
||||
test('TC_SEARCH_INPUT_003: empty search shows the default discovery list', async ({ page }) => {
|
||||
const emptyQueryResponse = page.waitForResponse((response) => {
|
||||
if (!response.url().includes('/api/web/skills?')) {
|
||||
return false
|
||||
}
|
||||
|
||||
const url = new URL(response.url())
|
||||
return response.status() === 200
|
||||
&& url.searchParams.has('q')
|
||||
&& url.searchParams.get('q') === ''
|
||||
})
|
||||
|
||||
await page.goto(searchUrl(''))
|
||||
await emptyQueryResponse
|
||||
await expect(page).toHaveURL(/\/search/)
|
||||
await expect(getSearchCards(page).first()).toBeVisible({ timeout: 10_000 })
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,6 +16,18 @@ describe('buildSkillSearchUrl', () => {
|
|||
it('returns the base skills endpoint when no search params are provided', () => {
|
||||
expect(buildSkillSearchUrl({})).toBe('/api/web/skills')
|
||||
})
|
||||
|
||||
it('keeps an empty q parameter when the search query is an empty string', () => {
|
||||
expect(buildSkillSearchUrl({ q: '' })).toBe('/api/web/skills?q=')
|
||||
})
|
||||
|
||||
it('normalizes whitespace-only queries to an empty q parameter', () => {
|
||||
expect(buildSkillSearchUrl({
|
||||
q: ' ',
|
||||
sort: 'relevance',
|
||||
page: 0,
|
||||
})).toBe('/api/web/skills?q=&sort=relevance&page=0')
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldEnableNamespaceMemberCandidates', () => {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export function buildSkillSearchUrl(params: SearchParams) {
|
|||
const queryParams = new URLSearchParams()
|
||||
const normalizedQuery = normalizeSearchQuery(params.q ?? '')
|
||||
|
||||
if (normalizedQuery) {
|
||||
if (params.q !== undefined) {
|
||||
queryParams.append('q', normalizedQuery)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue