mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-07 06:00:03 +00:00
## Summary Extract duplicated asset-browser eligibility guard into `shouldUseAssetBrowser()`, fix a missing parameter bug, and sanitize a log statement. ## Changes - **What**: - DRY: Extract the repeated 3-condition guard (`isCloud && isUsingAssetAPI && isAssetBrowserEligible`) into `assetService.shouldUseAssetBrowser()`, used by `widgetInputs.ts` and `useComboWidget.ts` - Bug fix: `createAssetBrowserWidget()` in `useComboWidget.ts` was missing the `inputNameForBrowser` parameter, which could show wrong assets for nodes with multiple model inputs - Security: `createAssetWidget.ts` no longer logs the full raw asset object on validation failure - `WidgetSelect.vue` keeps an inline guard because it has a special `widget.type === "asset"` fallback that must stay gated behind `isUsingAssetAPI` ## Review Focus - `shouldUseAssetBrowser()` correctly combines the three conditions that were previously duplicated - `WidgetSelect.vue` preserves exact behavioral equivalence (a widget can have `type === "asset"` when the setting is off if a user toggles the setting after creating asset widgets) Fixes #8744 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8867-refactor-extract-shouldUseAssetBrowser-fix-missing-inputNameForBrowser-sanitize-logs-3076d73d3650818cabdcd76a351dac31) by [Unito](https://www.unito.io)
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { createTestingPinia } from '@pinia/testing'
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
import PrimeVue from 'primevue/config'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import type { SimplifiedWidget } from '@/types/simplifiedWidget'
|
|
|
|
import WidgetSelect from '@/renderer/extensions/vueNodes/widgets/components/WidgetSelect.vue'
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: { en: {} }
|
|
})
|
|
|
|
// Mock modules
|
|
vi.mock('@/platform/assets/services/assetService', () => ({
|
|
assetService: {
|
|
shouldUseAssetBrowser: vi.fn(() => true),
|
|
isAssetAPIEnabled: vi.fn(() => true)
|
|
}
|
|
}))
|
|
|
|
// Import after mocks are defined
|
|
import { assetService } from '@/platform/assets/services/assetService'
|
|
const mockShouldUseAssetBrowser = vi.mocked(assetService.shouldUseAssetBrowser)
|
|
|
|
describe('WidgetSelect asset mode', () => {
|
|
const createWidget = (): SimplifiedWidget<string | undefined> => ({
|
|
name: 'ckpt_name',
|
|
type: 'combo',
|
|
value: undefined,
|
|
options: {
|
|
values: []
|
|
}
|
|
})
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockShouldUseAssetBrowser.mockReturnValue(true)
|
|
})
|
|
|
|
// Helper to mount with common setup
|
|
const mountWidget = () => {
|
|
return mount(WidgetSelect, {
|
|
props: {
|
|
widget: createWidget(),
|
|
modelValue: undefined,
|
|
nodeType: 'CheckpointLoaderSimple'
|
|
},
|
|
global: {
|
|
plugins: [PrimeVue, createTestingPinia(), i18n]
|
|
}
|
|
})
|
|
}
|
|
|
|
it('uses dropdown when isCloud && UseAssetAPI && isEligible', async () => {
|
|
const wrapper = mountWidget()
|
|
await flushPromises()
|
|
|
|
expect(
|
|
wrapper.findComponent({ name: 'WidgetSelectDropdown' }).exists()
|
|
).toBe(true)
|
|
})
|
|
|
|
it('uses default widget when shouldUseAssetBrowser returns false', () => {
|
|
mockShouldUseAssetBrowser.mockReturnValue(false)
|
|
const wrapper = mountWidget()
|
|
|
|
expect(
|
|
wrapper.findComponent({ name: 'WidgetSelectDefault' }).exists()
|
|
).toBe(true)
|
|
})
|
|
})
|