mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 06:19:58 +00:00
* basic/empty model library sidebar tab in-progress * make it actually list out models * extremely primitive search impl * list out available folders (incomplete list atm) * load list dynamically * nice lil loading icon * that's not doing anything * run autoformatter * fix up some absolute vue shenanigans * swap to pi-box * is_fake_object * i think apply the tailwind thingo * trim '.safetensors' from end of display title * oop * after load, retain title if no new title is given * is_load_requested to prevent duplication * dirty initial model metadata load & preview based on node preview code * update model store tests * initial image icon for model lib * i hate this * better empty spacer * add api handler for '/models' * load model folders list instead of hardcoding * add a 'no content' placeholder for empty folders * autoformat * autoload model metadata * error handling on metadata loading * larger model icons * click a model to spawn a node for it * draggable model nodes * add a setting for whether to autoload or not * autoformat will be the death of me * cleanup promise code * make the model preview actually half-decent * revert bad unchecked change * put registration back
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useModelStore } from '@/stores/modelStore'
|
|
import { api } from '@/scripts/api'
|
|
|
|
// Mock the api
|
|
jest.mock('@/scripts/api', () => ({
|
|
api: {
|
|
getModels: jest.fn(),
|
|
viewMetadata: jest.fn()
|
|
}
|
|
}))
|
|
|
|
function enableMocks() {
|
|
;(api.getModels as jest.Mock).mockResolvedValue([
|
|
'sdxl.safetensors',
|
|
'sdv15.safetensors',
|
|
'noinfo.safetensors'
|
|
])
|
|
;(api.viewMetadata as jest.Mock).mockImplementation((_, model) => {
|
|
if (model === 'noinfo.safetensors') {
|
|
return Promise.resolve({})
|
|
}
|
|
return Promise.resolve({
|
|
'modelspec.title': `Title of ${model}`,
|
|
display_name: 'Should not show',
|
|
'modelspec.architecture': 'stable-diffusion-xl-base-v1',
|
|
'modelspec.author': `Author of ${model}`,
|
|
'modelspec.description': `Description of ${model}`,
|
|
'modelspec.resolution': '1024x1024',
|
|
trigger_phrase: `Trigger phrase of ${model}`,
|
|
usage_hint: `Usage hint of ${model}`,
|
|
tags: `tags,for,${model}`
|
|
})
|
|
})
|
|
}
|
|
|
|
describe('useModelStore', () => {
|
|
let store: ReturnType<typeof useModelStore>
|
|
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
store = useModelStore()
|
|
})
|
|
|
|
it('should load models', async () => {
|
|
enableMocks()
|
|
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
|
expect(folderStore).not.toBeNull()
|
|
expect(Object.keys(folderStore.models)).toHaveLength(3)
|
|
})
|
|
|
|
it('should load model metadata', async () => {
|
|
enableMocks()
|
|
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
|
const model = folderStore.models['sdxl.safetensors']
|
|
await model.load()
|
|
expect(model.title).toBe('Title of sdxl.safetensors')
|
|
expect(model.architecture_id).toBe('stable-diffusion-xl-base-v1')
|
|
expect(model.author).toBe('Author of sdxl.safetensors')
|
|
expect(model.description).toBe('Description of sdxl.safetensors')
|
|
expect(model.resolution).toBe('1024x1024')
|
|
expect(model.trigger_phrase).toBe('Trigger phrase of sdxl.safetensors')
|
|
expect(model.usage_hint).toBe('Usage hint of sdxl.safetensors')
|
|
expect(model.tags).toHaveLength(3)
|
|
})
|
|
|
|
it('should handle no metadata', async () => {
|
|
enableMocks()
|
|
const folderStore = await store.getModelsInFolderCached('checkpoints')
|
|
const model = folderStore.models['noinfo.safetensors']
|
|
await model.load()
|
|
expect(model.name).toBe('noinfo.safetensors')
|
|
expect(model.title).toBe('noinfo')
|
|
expect(model.architecture_id).toBe('')
|
|
expect(model.author).toBe('')
|
|
expect(model.description).toBe('')
|
|
expect(model.resolution).toBe('')
|
|
})
|
|
|
|
it('should cache model information', async () => {
|
|
enableMocks()
|
|
const folderStore1 = await store.getModelsInFolderCached('checkpoints')
|
|
const folderStore2 = await store.getModelsInFolderCached('checkpoints')
|
|
expect(api.getModels).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|