mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-10 15:40:24 +00:00
Road to No explicit any: Group 8 (part 7) test files (#8459)
## Summary
This PR removes unsafe type assertions ("as unknown as Type") from test
files and improves type safety across the codebase.
### Key Changes
#### Type Safety Improvements
- Removed improper `as unknown as Type` patterns from 17 test files in
Group 8 part 7
- Replaced with proper TypeScript patterns using factory functions and
Mock types
- Fixed createTestingPinia usage in test files (was incorrectly using
createPinia)
- Fixed vi.hoisted pattern for mockSetDirty in viewport tests
- Fixed vi.doMock lint issues with vi.mock and vi.hoisted pattern
- Retained necessary `as unknown as` casts only for complex mock objects
where direct type assertions would fail
### Files Changed
Test files (Group 8 part 7 - services, stores, utils):
- src/services/nodeOrganizationService.test.ts
- src/services/providers/algoliaSearchProvider.test.ts
- src/services/providers/registrySearchProvider.test.ts
- src/stores/comfyRegistryStore.test.ts
- src/stores/domWidgetStore.test.ts
- src/stores/executionStore.test.ts
- src/stores/firebaseAuthStore.test.ts
- src/stores/modelToNodeStore.test.ts
- src/stores/queueStore.test.ts
- src/stores/subgraphNavigationStore.test.ts
- src/stores/subgraphNavigationStore.viewport.test.ts
- src/stores/subgraphStore.test.ts
- src/stores/systemStatsStore.test.ts
- src/stores/workspace/nodeHelpStore.test.ts
- src/utils/colorUtil.test.ts
- src/utils/executableGroupNodeChildDTO.test.ts
Source files:
- src/stores/modelStore.ts - Improved type handling
### Testing
- All TypeScript type checking passes (`pnpm typecheck`)
- All affected test files pass (`pnpm test:unit`)
- Linting passes without errors (`pnpm lint`)
- Code formatting applied (`pnpm format`)
Part of the "Road to No Explicit Any" initiative, cleaning up type
casting issues from branch `fix/remove-any-types-part8`.
### Previous PRs in this series:
- Part 2: #7401
- Part 3: #7935
- Part 4: #7970
- Part 5: #8064
- Part 6: #8083
- Part 7: #8092
- Part 8 Group 1: #8253
- Part 8 Group 2: #8258
- Part 8 Group 3: #8304
- Part 8 Group 4: #8314
- Part 8 Group 5: #8329
- Part 8 Group 6: #8344
- Part 8 Group 7: #8459 (this PR)
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8459-Road-to-No-explicit-any-Group-8-part-7-test-files-2f86d73d36508114ad28d82e72a3a5e9)
by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
067d80c4ed
commit
13311a46ea
@@ -5,7 +5,7 @@ import { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
import { NodeSourceType } from '@/types/nodeSource'
|
||||
|
||||
describe('nodeOrganizationService', () => {
|
||||
const createMockNodeDef = (overrides: any = {}) => {
|
||||
const createMockNodeDef = (overrides: Partial<ComfyNodeDefImpl> = {}) => {
|
||||
const mockNodeDef = {
|
||||
name: 'TestNode',
|
||||
display_name: 'Test Node',
|
||||
@@ -273,7 +273,7 @@ describe('nodeOrganizationService', () => {
|
||||
it('should handle unknown source type', () => {
|
||||
const nodeDef = createMockNodeDef({
|
||||
nodeSource: {
|
||||
type: 'unknown' as any,
|
||||
type: 'unknown' as NodeSourceType,
|
||||
className: 'unknown',
|
||||
displayText: 'Unknown',
|
||||
badgeText: '?'
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
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']
|
||||
|
||||
type GlobalWithAlgolia = typeof globalThis & {
|
||||
__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'
|
||||
const globalWithAlgolia = globalThis as GlobalWithAlgolia
|
||||
globalWithAlgolia.__ALGOLIA_APP_ID__ = 'test-app-id'
|
||||
globalWithAlgolia.__ALGOLIA_API_KEY__ = 'test-api-key'
|
||||
|
||||
// Mock algoliasearch
|
||||
vi.mock('algoliasearch/dist/lite/builds/browser', () => ({
|
||||
liteClient: vi.fn()
|
||||
}))
|
||||
|
||||
interface MockSearchClient {
|
||||
search: Mock
|
||||
}
|
||||
|
||||
describe('useAlgoliaSearchProvider', () => {
|
||||
let mockSearchClient: any
|
||||
let mockSearchClient: MockSearchClient
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -24,7 +38,11 @@ describe('useAlgoliaSearchProvider', () => {
|
||||
search: vi.fn()
|
||||
}
|
||||
|
||||
vi.mocked(algoliasearch).mockReturnValue(mockSearchClient)
|
||||
vi.mocked(algoliasearch).mockReturnValue(
|
||||
mockSearchClient as Partial<
|
||||
ReturnType<typeof algoliasearch>
|
||||
> as ReturnType<typeof algoliasearch>
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -252,7 +270,7 @@ describe('useAlgoliaSearchProvider', () => {
|
||||
})
|
||||
|
||||
describe('getSortValue', () => {
|
||||
const testPack = {
|
||||
const testPack: Partial<RegistryNodePack> = {
|
||||
id: '1',
|
||||
name: 'Test Pack',
|
||||
downloads: 100,
|
||||
@@ -279,7 +297,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()
|
||||
@@ -289,23 +310,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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,20 +14,31 @@ describe('useComfyRegistrySearchProvider', () => {
|
||||
const mockListAllPacksCall = vi.fn()
|
||||
const mockListAllPacksClear = vi.fn()
|
||||
|
||||
const createMockStore = (
|
||||
params: Partial<ReturnType<typeof useComfyRegistryStore>> = {}
|
||||
) => {
|
||||
return {
|
||||
search: {
|
||||
call: mockSearchCall,
|
||||
clear: mockSearchClear,
|
||||
cancel: vi.fn()
|
||||
},
|
||||
listAllPacks: {
|
||||
call: mockListAllPacksCall,
|
||||
clear: mockListAllPacksClear,
|
||||
cancel: vi.fn()
|
||||
},
|
||||
...params
|
||||
} as Partial<ReturnType<typeof useComfyRegistryStore>> as ReturnType<
|
||||
typeof useComfyRegistryStore
|
||||
>
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
// Setup store mock
|
||||
vi.mocked(useComfyRegistryStore).mockReturnValue({
|
||||
search: {
|
||||
call: mockSearchCall,
|
||||
clear: mockSearchClear
|
||||
},
|
||||
listAllPacks: {
|
||||
call: mockListAllPacksCall,
|
||||
clear: mockListAllPacksClear
|
||||
}
|
||||
} as any)
|
||||
vi.mocked(useComfyRegistryStore).mockReturnValue(createMockStore())
|
||||
})
|
||||
|
||||
describe('searchPacks', () => {
|
||||
|
||||
Reference in New Issue
Block a user