Feat(settings): add renderer for settings configuration #142

Merged
jakob.scheid merged 88 commits from feature/settings-renderer into main 2026-07-28 20:14:50 +02:00
2 changed files with 40 additions and 29 deletions
Showing only changes of commit f7f4de8341 - Show all commits
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { useSettingsPage } from '../useSettingsPage'; import { normalizePagePath, useSettingsPage } from '../useSettingsPage.js';
import { describe, expect, test, vi } from 'vitest'; import { describe, expect, test, vi } from 'vitest';
const pushRoute = vi.fn(); const pushRoute = vi.fn();
@@ -25,35 +25,46 @@ vi.mock('vue-router', () => ({
})); }));
describe('useSettingsPage', () => { describe('useSettingsPage', () => {
describe('goToSettingsPage', () => { describe('normalizePagePath', () => {
test.for([ test.for([
{ settingsPath: 'a.b.c', expectedRoute: '/settings/a/b/c' }, { path: 'a.b.c', expected: ['a', 'b', 'c'] },
{ settingsPath: 'a', expectedRoute: '/settings/a' }, { path: 'a', expected: ['a'] },
{ settingsPath: 'a.b', expectedRoute: '/settings/a/b' }, { path: 'a.b', expected: ['a', 'b'] },
{ settingsPath: 'a..b', expectedRoute: '/settings/a/b' }, { path: 'a..b', expected: ['a', 'b'] },
{ settingsPath: '.a.b', expectedRoute: '/settings/a/b' }, { path: '.a.b', expected: ['a', 'b'] },
{ settingsPath: '..a.b', expectedRoute: '/settings/a/b' }, { path: '..a.b', expected: ['a', 'b'] },
{ settingsPath: '.a.b.', expectedRoute: '/settings/a/b' }, { path: '.a.b.', expected: ['a', 'b'] },
{ settingsPath: '..a.b..', expectedRoute: '/settings/a/b' }, { path: '..a.b..', expected: ['a', 'b'] },
{ settingsPath: 'a.b.', expectedRoute: '/settings/a/b' }, { path: 'a.b.', expected: ['a', 'b'] },
{ settingsPath: 'a.b..', expectedRoute: '/settings/a/b' }, { path: 'a.b..', expected: ['a', 'b'] },
{ settingsPath: '.a.b..', expectedRoute: '/settings/a/b' }, { path: '.a.b..', expected: ['a', 'b'] },
{ settingsPath: '..a.b.', expectedRoute: '/settings/a/b' }, { path: '..a.b.', expected: ['a', 'b'] },
{ settingsPath: '.a..b', expectedRoute: '/settings/a/b' }, { path: '.a..b', expected: ['a', 'b'] },
{ settingsPath: '..a..b', expectedRoute: '/settings/a/b' }, { path: '..a..b', expected: ['a', 'b'] },
{ settingsPath: '.a..b.', expectedRoute: '/settings/a/b' }, { path: '.a..b.', expected: ['a', 'b'] },
{ settingsPath: '..a..b..', expectedRoute: '/settings/a/b' }, { path: '..a..b..', expected: ['a', 'b'] },
{ settingsPath: 'a..b.', expectedRoute: '/settings/a/b' }, { path: 'a..b.', expected: ['a', 'b'] },
{ settingsPath: 'a..b..', expectedRoute: '/settings/a/b' }, { path: 'a..b..', expected: ['a', 'b'] },
{ settingsPath: '.a..b..', expectedRoute: '/settings/a/b' }, { path: '.a..b..', expected: ['a', 'b'] },
{ settingsPath: '..a..b.', expectedRoute: '/settings/a/b' }, { path: '..a..b.', expected: ['a', 'b'] },
{ settingsPath: '..a.....b.c..d....', expectedRoute: '/settings/a/b/c/d' } { path: '..a.....b.c..d....', expected: ['a', 'b', 'c', 'd'] }
])('goes to correct route', async ({ settingsPath, expectedRoute }) => { ])('normalizes path correctly', async ({ path, expected }) => {
const { goToSettingsPage } = useSettingsPage(); expect(normalizePagePath(path)).toStrictEqual(expected);
});
});
await goToSettingsPage(settingsPath); describe('useSettingsPage', () => {
expect(pushRoute).toHaveBeenCalledWith(expectedRoute); describe('goToSettingsPage', () => {
pushRoute.mockClear(); test('pushes correct route', async () => {
const { goToSettingsPage } = useSettingsPage();
await goToSettingsPage('..a.b...c.d..e......');
expect(pushRoute).toHaveBeenCalledWith({
name: 'settings',
params: {
rest: ['a', 'b', 'c', 'd', 'e']
}
});
});
}); });
}); });
}); });
@@ -16,7 +16,7 @@ limitations under the License.
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
const normalizePagePath = function normalizePagePath (path) { export const normalizePagePath = function normalizePagePath (path) {
return path return path
.replace(/\.+/g, '.') .replace(/\.+/g, '.')
.replace(/^\.+|\.+$/g, '') .replace(/^\.+|\.+$/g, '')