mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
Fix error when adding custom setting with no category (#2112)
Co-authored-by: huchenlei <huchenlei@proton.me>
This commit is contained in:
@@ -11,9 +11,8 @@ import { buildTree } from '@/utils/treeUtil'
|
|||||||
export const getSettingInfo = (setting: SettingParams) => {
|
export const getSettingInfo = (setting: SettingParams) => {
|
||||||
const parts = setting.category || setting.id.split('.')
|
const parts = setting.category || setting.id.split('.')
|
||||||
return {
|
return {
|
||||||
category: parts[0],
|
category: parts[0] ?? 'Other',
|
||||||
subCategory: parts[1],
|
subCategory: parts[1] ?? 'Other'
|
||||||
name: parts.slice(2).join('.')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createPinia, setActivePinia } from 'pinia'
|
import { createPinia, setActivePinia } from 'pinia'
|
||||||
|
|
||||||
import { api } from '@/scripts/api'
|
import { api } from '@/scripts/api'
|
||||||
import { useSettingStore } from '@/stores/settingStore'
|
import { getSettingInfo, useSettingStore } from '@/stores/settingStore'
|
||||||
import type { SettingParams } from '@/types/settingTypes'
|
import type { SettingParams } from '@/types/settingTypes'
|
||||||
|
|
||||||
// Mock the api
|
// Mock the api
|
||||||
@@ -140,3 +140,71 @@ describe('useSettingStore', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('getSettingInfo', () => {
|
||||||
|
const baseSetting: SettingParams = {
|
||||||
|
id: 'test.setting',
|
||||||
|
name: 'test.setting',
|
||||||
|
type: 'text',
|
||||||
|
defaultValue: 'default'
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should handle settings with explicit category array', () => {
|
||||||
|
const setting: SettingParams = {
|
||||||
|
...baseSetting,
|
||||||
|
id: 'test.setting',
|
||||||
|
category: ['Main', 'Sub', 'Detail']
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = getSettingInfo(setting)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
category: 'Main',
|
||||||
|
subCategory: 'Sub'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle settings with id-based categorization', () => {
|
||||||
|
const setting: SettingParams = {
|
||||||
|
...baseSetting,
|
||||||
|
id: 'main.sub.setting.name'
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = getSettingInfo(setting)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
category: 'main',
|
||||||
|
subCategory: 'sub'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should use "Other" as default subCategory when missing', () => {
|
||||||
|
const setting: SettingParams = {
|
||||||
|
...baseSetting,
|
||||||
|
id: 'single.setting',
|
||||||
|
category: ['single']
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = getSettingInfo(setting)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
category: 'single',
|
||||||
|
subCategory: 'Other'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should use "Other" as default category when missing', () => {
|
||||||
|
const setting: SettingParams = {
|
||||||
|
...baseSetting,
|
||||||
|
id: 'single.setting',
|
||||||
|
category: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = getSettingInfo(setting)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
category: 'Other',
|
||||||
|
subCategory: 'Other'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user