diff --git a/packages/editor-ui/src/router.test.ts b/packages/editor-ui/src/router.test.ts index f67399d6345b4..8af15d9da5dca 100644 --- a/packages/editor-ui/src/router.test.ts +++ b/packages/editor-ui/src/router.test.ts @@ -14,6 +14,8 @@ const App = { }; const renderComponent = createComponentRenderer(App); +let settingsStore: ReturnType; + describe('router', () => { let server: ReturnType; const initializeAuthenticatedFeaturesSpy = vi.spyOn(init, 'initializeAuthenticatedFeatures'); @@ -28,6 +30,7 @@ describe('router', () => { }); beforeEach(() => { + settingsStore = useSettingsStore(); initializeAuthenticatedFeaturesSpy.mockImplementation(async () => await Promise.resolve()); }); @@ -114,7 +117,6 @@ describe('router', () => { ])( 'should resolve %s to %s with %s user permissions', async (path, name, scopes) => { - const settingsStore = useSettingsStore(); const rbacStore = useRBACStore(); settingsStore.settings.communityNodesEnabled = true; @@ -126,4 +128,13 @@ describe('router', () => { }, 10000, ); + + test.each([ + [VIEWS.PERSONAL_SETTINGS, true], + [VIEWS.USAGE, false], + ])('should redirect Settings to %s', async (name, hideUsagePage) => { + settingsStore.settings.hideUsagePage = hideUsagePage; + await router.push('/settings'); + expect(router.currentRoute.value.name).toBe(name); + }); }); diff --git a/packages/editor-ui/src/router.ts b/packages/editor-ui/src/router.ts index cdf162717e8f6..af0a960a401f6 100644 --- a/packages/editor-ui/src/router.ts +++ b/packages/editor-ui/src/router.ts @@ -483,7 +483,13 @@ export const routes: RouteRecordRaw[] = [ name: VIEWS.SETTINGS, component: SettingsView, props: true, - redirect: { name: VIEWS.USAGE }, + redirect: () => { + const settingsStore = useSettingsStore(); + if (settingsStore.settings.hideUsagePage) { + return { name: VIEWS.PERSONAL_SETTINGS }; + } + return { name: VIEWS.USAGE }; + }, children: [ { path: 'usage', diff --git a/packages/editor-ui/src/views/SettingsView.test.ts b/packages/editor-ui/src/views/SettingsView.test.ts index 87875147f86a0..00178caffb2e0 100644 --- a/packages/editor-ui/src/views/SettingsView.test.ts +++ b/packages/editor-ui/src/views/SettingsView.test.ts @@ -50,7 +50,7 @@ const router = createRouter({ name: VIEWS.SETTINGS, component: SettingsView, props: true, - redirect: { name: VIEWS.USAGE }, + redirect: { name: VIEWS.PERSONAL_SETTINGS }, children: settingsRouteChildren, }, ],