dify/web/app/components/base/search-input/__tests__/search-state.spec.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

52 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { hasSearchText, isSearchResultEmpty } from '../search-state'
describe('search-state', () => {
it('detects trimmed search text', () => {
expect(hasSearchText(' query ')).toBe(true)
expect(hasSearchText(' ')).toBe(false)
expect(hasSearchText()).toBe(false)
})
it('treats search empty as filtering existing source data to no results', () => {
expect(
isSearchResultEmpty({
isLoading: false,
resultCount: 0,
searchText: 'missing',
sourceCount: 2,
}),
).toBe(true)
})
it('does not treat loading or true source empty as search empty', () => {
expect(
isSearchResultEmpty({
isLoading: true,
resultCount: 0,
searchText: 'missing',
sourceCount: 2,
}),
).toBe(false)
expect(
isSearchResultEmpty({
isLoading: false,
resultCount: 0,
searchText: 'missing',
sourceCount: 0,
}),
).toBe(false)
})
it('supports non-text filters', () => {
expect(
isSearchResultEmpty({
hasActiveFilter: true,
isLoading: false,
resultCount: 0,
sourceCount: 2,
}),
).toBe(true)
})
})