mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 15:24:09 +00:00
refactor: remove any types from algoliaSearchProvider.test.ts
- Define RegistryNodePack type from comfyRegistryTypes - Create GlobalWithAlgolia interface for global properties - Replace (global as any) with properly typed (globalThis as unknown as GlobalWithAlgolia) - Type testPack and incompletePack as Partial<RegistryNodePack> - Replace as any casts with as RegistryNodePack
This commit is contained in:
@@ -2,12 +2,21 @@ import type { Mock } from 'vitest'
|
||||
import { liteClient as algoliasearch } from 'algoliasearch/dist/lite/builds/browser'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { components } from '@/types/comfyRegistryTypes'
|
||||
import { useAlgoliaSearchProvider } from '@/services/providers/algoliaSearchProvider'
|
||||
import { SortableAlgoliaField } from '@/workbench/extensions/manager/types/comfyManagerTypes'
|
||||
|
||||
type RegistryNodePack = components['schemas']['Node']
|
||||
|
||||
interface GlobalWithAlgolia {
|
||||
__ALGOLIA_APP_ID__: string
|
||||
__ALGOLIA_API_KEY__: string
|
||||
}
|
||||
|
||||
// Mock global Algolia constants
|
||||
;(global as any).__ALGOLIA_APP_ID__ = 'test-app-id'
|
||||
;(global as any).__ALGOLIA_API_KEY__ = 'test-api-key'
|
||||
;(globalThis as unknown as GlobalWithAlgolia).__ALGOLIA_APP_ID__ = 'test-app-id'
|
||||
;(globalThis as unknown as GlobalWithAlgolia).__ALGOLIA_API_KEY__ =
|
||||
'test-api-key'
|
||||
|
||||
// Mock algoliasearch
|
||||
vi.mock('algoliasearch/dist/lite/builds/browser', () => ({
|
||||
@@ -259,7 +268,7 @@ describe('useAlgoliaSearchProvider', () => {
|
||||
})
|
||||
|
||||
describe('getSortValue', () => {
|
||||
const testPack = {
|
||||
const testPack: Partial<RegistryNodePack> = {
|
||||
id: '1',
|
||||
name: 'Test Pack',
|
||||
downloads: 100,
|
||||
@@ -286,7 +295,10 @@ describe('useAlgoliaSearchProvider', () => {
|
||||
|
||||
const createdTimestamp = new Date('2024-01-01T10:00:00Z').getTime()
|
||||
expect(
|
||||
provider.getSortValue(testPack as any, SortableAlgoliaField.Created)
|
||||
provider.getSortValue(
|
||||
testPack as RegistryNodePack,
|
||||
SortableAlgoliaField.Created
|
||||
)
|
||||
).toBe(createdTimestamp)
|
||||
|
||||
const updatedTimestamp = new Date('2024-01-15T10:00:00Z').getTime()
|
||||
@@ -296,23 +308,35 @@ describe('useAlgoliaSearchProvider', () => {
|
||||
})
|
||||
|
||||
it('should handle missing values', () => {
|
||||
const incompletePack = { id: '1', name: 'Incomplete' }
|
||||
const incompletePack: Partial<RegistryNodePack> = {
|
||||
id: '1',
|
||||
name: 'Incomplete'
|
||||
}
|
||||
const provider = useAlgoliaSearchProvider()
|
||||
|
||||
expect(
|
||||
provider.getSortValue(incompletePack, SortableAlgoliaField.Downloads)
|
||||
provider.getSortValue(
|
||||
incompletePack as RegistryNodePack,
|
||||
SortableAlgoliaField.Downloads
|
||||
)
|
||||
).toBe(0)
|
||||
expect(
|
||||
provider.getSortValue(incompletePack, SortableAlgoliaField.Publisher)
|
||||
provider.getSortValue(
|
||||
incompletePack as RegistryNodePack,
|
||||
SortableAlgoliaField.Publisher
|
||||
)
|
||||
).toBe('')
|
||||
expect(
|
||||
provider.getSortValue(
|
||||
incompletePack as any,
|
||||
incompletePack as RegistryNodePack,
|
||||
SortableAlgoliaField.Created
|
||||
)
|
||||
).toBe(0)
|
||||
expect(
|
||||
provider.getSortValue(incompletePack, SortableAlgoliaField.Updated)
|
||||
provider.getSortValue(
|
||||
incompletePack as RegistryNodePack,
|
||||
SortableAlgoliaField.Updated
|
||||
)
|
||||
).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user