From e0e2033fdf3f79eefc856824033fdf298d580a0e Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Tue, 28 Jul 2026 13:03:47 +0200 Subject: [PATCH] refactor(settings)!: pass path to getSettingsRecursively using an array instead of a string Tests and all files the utility is used in are also updated. Warning: This change is breaking! --- .../utils/__tests__/getSetting.test.js | 32 +++++++++---------- src/features/settings/utils/getSetting.js | 2 +- src/features/settings/views/SettingsView.vue | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/features/settings/utils/__tests__/getSetting.test.js b/src/features/settings/utils/__tests__/getSetting.test.js index 53e0f07..d28eb62 100644 --- a/src/features/settings/utils/__tests__/getSetting.test.js +++ b/src/features/settings/utils/__tests__/getSetting.test.js @@ -116,14 +116,14 @@ const veryNestedSettingsList = [ ]; test.for([ - ({ settings: [], path: 'a', expected: undefined }), + ({ settings: [], path: ['a'], expected: undefined }), ({ settings: [ { type: 'bool', name: '1a', i18n: '1a' } - ], path: '1a', expected: { + ], path: ['1a'], expected: { type: 'bool', name: '1a', i18n: '1a' @@ -146,7 +146,7 @@ test.for([ } ] } - ], path: '1a', expected: { + ], path: ['1a'], expected: { type: 'bool', name: '1a', i18n: '1a' @@ -169,7 +169,7 @@ test.for([ } ] } - ], path: '1b.2a', expected: { + ], path: ['1b', '2a'], expected: { type: 'bool', name: '2a', i18n: '2a' @@ -198,7 +198,7 @@ test.for([ } ] } - ], path: '1b.2b', expected: { + ], path: ['1b', '2b'], expected: { type: 'number', name: '2b', i18n: '2b', @@ -234,7 +234,7 @@ test.for([ } ] } - ], path: '1b.2b.3a', expected: { + ], path: ['1b', '2b', '3a'], expected: { type: 'string', name: '3a', i18n: '3a' @@ -269,7 +269,7 @@ test.for([ } ] } - ], path: '1b', expected: { + ], path: ['1b'], expected: { type: 'section', name: '1b', i18n: '1b', @@ -323,7 +323,7 @@ test.for([ } ] } - ], path: '1b.2b', expected: { + ], path: ['1b', '2b'], expected: { type: 'section', name: '2b', i18n: '2b', @@ -366,7 +366,7 @@ test.for([ } ] } - ], path: '1b.2b.3b', expected: undefined }), + ], path: ['1b', '2b', '3b'], expected: undefined }), ({ settings: [ { type: 'bool', @@ -397,7 +397,7 @@ test.for([ } ] } - ], path: '1b.2a.3a', expected: undefined }), + ], path: ['1b', '2a', '3a'], expected: undefined }), ({ settings: [ { type: 'bool', @@ -428,7 +428,7 @@ test.for([ } ] } - ], path: '1b.2c.3a', expected: undefined }), + ], path: ['1b', '2c', '3a'], expected: undefined }), ({ settings: [ { type: 'bool', @@ -459,7 +459,7 @@ test.for([ } ] } - ], path: '1a.2b.3a', expected: undefined }), + ], path: ['1a', '2b', '3a'], expected: undefined }), ({ settings: [ { type: 'bool', @@ -490,13 +490,13 @@ test.for([ } ] } - ], path: '1c.2b.3a', expected: undefined }), - ({ settings: veryNestedSettingsList, path: '1b.2b.3b.4b.5b.6b.7a', expected: { + ], path: ['1c', '2b', '3a'], expected: undefined }), + ({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b', '6b', '7a'], expected: { type: 'bool', name: '7a', i18n: '7a' } }), - ({ settings: veryNestedSettingsList, path: '1b.2b.3b.4b.5b', expected: { + ({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b'], expected: { type: 'section', name: '5b', i18n: '5b', @@ -520,7 +520,7 @@ test.for([ } ] } }), - ({ settings: veryNestedSettingsList, path: '1b.2b.3b.4ba.5b.6b.7a', expected: undefined }) + ({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4ba', '5b', '6b', '7a'], expected: undefined }) ])('returns $expected', ({ settings, path, expected }) => { expect(getSettingRecursively(path, settings)).toStrictEqual(expected); }); \ No newline at end of file diff --git a/src/features/settings/utils/getSetting.js b/src/features/settings/utils/getSetting.js index c42744b..e65fcd5 100644 --- a/src/features/settings/utils/getSetting.js +++ b/src/features/settings/utils/getSetting.js @@ -38,5 +38,5 @@ export const getSettingRecursively = function getSettingRecursively (sectionPath return; }; }; - return oneSettingsLevel(sectionPath.split('.'), { content: settings }); + return oneSettingsLevel(sectionPath, { content: settings }); }; \ No newline at end of file diff --git a/src/features/settings/views/SettingsView.vue b/src/features/settings/views/SettingsView.vue index f1a9590..67903d6 100644 --- a/src/features/settings/views/SettingsView.vue +++ b/src/features/settings/views/SettingsView.vue @@ -43,7 +43,7 @@ watchEffect(() => { const updateSettings = function updateSettings () { if (activeSection.value) { - const setting = getSettingRecursively(activeSection.value, settings.value); + const setting = getSettingRecursively(activeSection.value.split('.'), settings.value); if (!setting) { router.push('/settings'); } else {