diff --git a/src/stores/settingStore.ts b/src/stores/settingStore.ts index d4b211e66..2a9afead8 100644 --- a/src/stores/settingStore.ts +++ b/src/stores/settingStore.ts @@ -11,9 +11,8 @@ import { buildTree } from '@/utils/treeUtil' export const getSettingInfo = (setting: SettingParams) => { const parts = setting.category || setting.id.split('.') return { - category: parts[0], - subCategory: parts[1], - name: parts.slice(2).join('.') + category: parts[0] ?? 'Other', + subCategory: parts[1] ?? 'Other' } } diff --git a/tests-ui/tests/store/settingStore.test.ts b/tests-ui/tests/store/settingStore.test.ts index 9308e5f47..3cfc1143c 100644 --- a/tests-ui/tests/store/settingStore.test.ts +++ b/tests-ui/tests/store/settingStore.test.ts @@ -1,7 +1,7 @@ import { createPinia, setActivePinia } from 'pinia' import { api } from '@/scripts/api' -import { useSettingStore } from '@/stores/settingStore' +import { getSettingInfo, useSettingStore } from '@/stores/settingStore' import type { SettingParams } from '@/types/settingTypes' // 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' + }) + }) +})