mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 05:00:03 +00:00
[fix] cleanup
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { d, t } from '@/i18n'
|
||||
import type { UUID } from '@/lib/litegraph/src/utils/uuid'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import { assetService } from '@/platform/assets/services/assetService'
|
||||
import {
|
||||
@@ -203,10 +202,7 @@ export function useAssetBrowser(assets: AssetItem[] = []) {
|
||||
// Execute callback with validated filename
|
||||
onSelect(filename)
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to fetch asset details for ${assetId}:`,
|
||||
error
|
||||
)
|
||||
console.error(`Failed to fetch asset details for ${assetId}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ export const useAssetBrowserDialog = () => {
|
||||
|
||||
async function show(props: AssetBrowserDialogProps) {
|
||||
const handleAssetSelected = (assetPath: string) => {
|
||||
hide() // Auto-close on selection before async operations
|
||||
props.onAssetSelected?.(assetPath)
|
||||
hide() // Auto-close on selection
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
@@ -39,7 +39,7 @@ export const useAssetBrowserDialog = () => {
|
||||
const dialogComponentProps = {
|
||||
headless: true,
|
||||
modal: true,
|
||||
closable: false,
|
||||
closable: true,
|
||||
pt: {
|
||||
root: {
|
||||
class: 'rounded-2xl overflow-hidden'
|
||||
@@ -58,7 +58,11 @@ export const useAssetBrowserDialog = () => {
|
||||
try {
|
||||
assets = await assetService.getAssetsForNodeType(props.nodeType)
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch assets for node type:', props.nodeType, error)
|
||||
console.error(
|
||||
'Failed to fetch assets for node type:',
|
||||
props.nodeType,
|
||||
error
|
||||
)
|
||||
}
|
||||
|
||||
dialogStore.showDialog({
|
||||
|
||||
@@ -144,8 +144,10 @@ function createAssetService() {
|
||||
const modelToNodeStore = useModelToNodeStore()
|
||||
const modelToNodeMap = modelToNodeStore.modelToNodeMap
|
||||
|
||||
const category = Object.keys(modelToNodeMap).find(categoryKey =>
|
||||
modelToNodeMap[categoryKey].some(provider => provider.nodeDef.name === nodeType)
|
||||
const category = Object.keys(modelToNodeMap).find((categoryKey) =>
|
||||
modelToNodeMap[categoryKey].some(
|
||||
(provider) => provider.nodeDef.name === nodeType
|
||||
)
|
||||
)
|
||||
|
||||
if (!category) {
|
||||
@@ -159,9 +161,12 @@ function createAssetService() {
|
||||
)
|
||||
|
||||
// Return full AssetItem[] objects (don't strip like getAssetModels does)
|
||||
return data?.assets?.filter(asset =>
|
||||
!asset.tags.includes(MISSING_TAG) && asset.tags.includes(category)
|
||||
) ?? []
|
||||
return (
|
||||
data?.assets?.filter(
|
||||
(asset) =>
|
||||
!asset.tags.includes(MISSING_TAG) && asset.tags.includes(category)
|
||||
) ?? []
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +191,9 @@ function createAssetService() {
|
||||
return result.data.assets[0]
|
||||
}
|
||||
|
||||
const error = fromZodError(result.error)
|
||||
const error = result.error
|
||||
? fromZodError(result.error)
|
||||
: 'Unknown validation error'
|
||||
throw new Error(`Invalid asset response against zod schema:\n${error}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import { nextTick } from 'vue'
|
||||
import AssetBrowserModal from '@/platform/assets/components/AssetBrowserModal.vue'
|
||||
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
|
||||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
||||
import { assetService } from '@/platform/assets/services/assetService'
|
||||
|
||||
// Mock assetService
|
||||
vi.mock('@/platform/assets/services/assetService', () => ({
|
||||
@@ -106,12 +105,9 @@ vi.mock('vue-i18n', () => ({
|
||||
|
||||
vi.mock('@/i18n', () => ({
|
||||
t: (key: string) => key,
|
||||
d: (date: Date, options?: any) => date.toLocaleDateString()
|
||||
d: (date: Date) => date.toLocaleDateString()
|
||||
}))
|
||||
|
||||
// Mock console.error for error handling tests
|
||||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
|
||||
describe('AssetBrowserModal', () => {
|
||||
const createTestAsset = (
|
||||
id: string,
|
||||
@@ -271,10 +267,8 @@ describe('AssetBrowserModal', () => {
|
||||
const emittedAsset = emitted![0][0] as AssetDisplayItem
|
||||
expect(emittedAsset.id).toBe('asset1')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
describe('Left Panel Conditional Logic', () => {
|
||||
it('hides left panel by default when showLeftPanel prop is undefined', () => {
|
||||
const singleCategoryAssets = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import { useAssetBrowser } from '@/platform/assets/composables/useAssetBrowser'
|
||||
@@ -20,7 +20,7 @@ vi.mock('@/i18n', () => ({
|
||||
}
|
||||
return translations[key] || key
|
||||
},
|
||||
d: (date: Date, options?: any) => date.toLocaleDateString()
|
||||
d: (date: Date) => date.toLocaleDateString()
|
||||
}))
|
||||
|
||||
describe('useAssetBrowser', () => {
|
||||
@@ -258,7 +258,6 @@ describe('useAssetBrowser', () => {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('Async Asset Selection with Detail Fetching', () => {
|
||||
it('should fetch asset details and call onSelect with filename when provided', async () => {
|
||||
const onSelectSpy = vi.fn()
|
||||
@@ -279,11 +278,15 @@ describe('useAssetBrowser', () => {
|
||||
await selectAssetWithCallback(asset.id, onSelectSpy)
|
||||
|
||||
expect(assetService.getAssetDetails).toHaveBeenCalledWith('asset-123')
|
||||
expect(onSelectSpy).toHaveBeenCalledWith('checkpoints/test-model.safetensors')
|
||||
expect(onSelectSpy).toHaveBeenCalledWith(
|
||||
'checkpoints/test-model.safetensors'
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle missing user_metadata.filename as error', async () => {
|
||||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
const consoleErrorSpy = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {})
|
||||
const onSelectSpy = vi.fn()
|
||||
const asset = createApiAsset({ id: 'asset-456' })
|
||||
|
||||
@@ -310,7 +313,9 @@ describe('useAssetBrowser', () => {
|
||||
})
|
||||
|
||||
it('should handle API errors gracefully', async () => {
|
||||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
const consoleErrorSpy = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {})
|
||||
const onSelectSpy = vi.fn()
|
||||
const asset = createApiAsset({ id: 'asset-789' })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user