mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
## Summary
Backport of #8090 to cloud/1.37 branch.
Cherry-picked from main commit 93e7a4f9f9.
## Conflict Resolutions
- `src/components/rightSidePanel/layout/PropertiesAccordionItem.vue`:
Took PR version but removed `TransitionCollapse` dependency (not present
in cloud/1.37). The transition animation is omitted; collapse/expand
works without animation.
## Original PR Description
Adds an editable Model Info Panel to show and modify asset details in
the asset browser.
### Changes
- Add `ModelInfoPanel` component with editable display name,
description, model type, base models, and tags
- Add `updateAssetMetadata` action in `assetsStore` with optimistic
cache updates
- Add shadcn-vue `Select` components with design system styling
- Add utility functions in `assetMetadataUtils` for extracting model
metadata
- Convert `BaseModalLayout` right panel state to `defineModel` pattern
- Add slide-in animation and collapse button for right panel
- Add `class` prop to `PropertiesAccordionItem` for custom styling
- Fix keyboard handling: Escape in TagsInput/TextArea doesn't close
parent modal
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8241-backport-cloud-1-37-feat-assets-add-ModelInfoPanel-for-asset-browser-right-panel-2f06d73d365081ffb57dca42a82349b6)
by [Unito](https://www.unito.io)
Co-authored-by: Amp <amp@ampcode.com>
166 lines
5.2 KiB
TypeScript
166 lines
5.2 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { createTestingPinia } from '@pinia/testing'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
|
|
|
|
import ModelInfoPanel from './ModelInfoPanel.vue'
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: { en: {} },
|
|
missingWarn: false,
|
|
fallbackWarn: false
|
|
})
|
|
|
|
describe('ModelInfoPanel', () => {
|
|
const createMockAsset = (
|
|
overrides: Partial<AssetDisplayItem> = {}
|
|
): AssetDisplayItem => ({
|
|
id: 'test-id',
|
|
name: 'test-model.safetensors',
|
|
asset_hash: 'hash123',
|
|
size: 1024,
|
|
mime_type: 'application/octet-stream',
|
|
tags: ['models', 'checkpoints'],
|
|
created_at: '2024-01-01T00:00:00Z',
|
|
updated_at: '2024-01-01T00:00:00Z',
|
|
last_access_time: '2024-01-01T00:00:00Z',
|
|
description: 'A test model description',
|
|
badges: [],
|
|
stats: {},
|
|
...overrides
|
|
})
|
|
|
|
const mountPanel = (asset: AssetDisplayItem) => {
|
|
return mount(ModelInfoPanel, {
|
|
props: { asset },
|
|
global: {
|
|
plugins: [createTestingPinia({ stubActions: false }), i18n]
|
|
}
|
|
})
|
|
}
|
|
|
|
describe('Basic Info Section', () => {
|
|
it('renders basic info section', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.basicInfo')
|
|
})
|
|
|
|
it('displays asset filename', () => {
|
|
const asset = createMockAsset({ name: 'my-model.safetensors' })
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).toContain('my-model.safetensors')
|
|
})
|
|
|
|
it('displays name from user_metadata when present', () => {
|
|
const asset = createMockAsset({
|
|
user_metadata: { name: 'My Custom Model' }
|
|
})
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).toContain('My Custom Model')
|
|
})
|
|
|
|
it('falls back to asset name when user_metadata.name not present', () => {
|
|
const asset = createMockAsset({ name: 'fallback-model.safetensors' })
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).toContain('fallback-model.safetensors')
|
|
})
|
|
|
|
it('renders source link when source_arn is present', () => {
|
|
const asset = createMockAsset({
|
|
user_metadata: { source_arn: 'civitai:model:123:version:456' }
|
|
})
|
|
const wrapper = mountPanel(asset)
|
|
const link = wrapper.find(
|
|
'a[href="https://civitai.com/models/123?modelVersionId=456"]'
|
|
)
|
|
expect(link.exists()).toBe(true)
|
|
expect(link.attributes('target')).toBe('_blank')
|
|
})
|
|
|
|
it('displays Civitai icon for Civitai source', () => {
|
|
const asset = createMockAsset({
|
|
user_metadata: { source_arn: 'civitai:model:123:version:456' }
|
|
})
|
|
const wrapper = mountPanel(asset)
|
|
expect(
|
|
wrapper.find('img[src="/assets/images/civitai.svg"]').exists()
|
|
).toBe(true)
|
|
})
|
|
|
|
it('does not render source field when source_arn is absent', () => {
|
|
const asset = createMockAsset()
|
|
const wrapper = mountPanel(asset)
|
|
const links = wrapper.findAll('a')
|
|
expect(links).toHaveLength(0)
|
|
})
|
|
})
|
|
|
|
describe('Model Tagging Section', () => {
|
|
it('renders model tagging section', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelTagging')
|
|
})
|
|
|
|
it('renders model type field', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelType')
|
|
})
|
|
|
|
it('renders base models field', () => {
|
|
const asset = createMockAsset({
|
|
user_metadata: { base_model: ['SDXL'] }
|
|
})
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).toContain(
|
|
'assetBrowser.modelInfo.compatibleBaseModels'
|
|
)
|
|
})
|
|
|
|
it('renders additional tags field', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.additionalTags')
|
|
})
|
|
})
|
|
|
|
describe('Model Description Section', () => {
|
|
it('renders trigger phrases when present', () => {
|
|
const asset = createMockAsset({
|
|
user_metadata: { trained_words: ['trigger1', 'trigger2'] }
|
|
})
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).toContain('trigger1')
|
|
expect(wrapper.text()).toContain('trigger2')
|
|
})
|
|
|
|
it('renders description section', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain(
|
|
'assetBrowser.modelInfo.modelDescription'
|
|
)
|
|
})
|
|
|
|
it('does not render trigger phrases field when empty', () => {
|
|
const asset = createMockAsset()
|
|
const wrapper = mountPanel(asset)
|
|
expect(wrapper.text()).not.toContain(
|
|
'assetBrowser.modelInfo.triggerPhrases'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('Accordion Structure', () => {
|
|
it('renders all three section labels', () => {
|
|
const wrapper = mountPanel(createMockAsset())
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.basicInfo')
|
|
expect(wrapper.text()).toContain('assetBrowser.modelInfo.modelTagging')
|
|
expect(wrapper.text()).toContain(
|
|
'assetBrowser.modelInfo.modelDescription'
|
|
)
|
|
})
|
|
})
|
|
})
|