From a7a88b59178613b073344e1e8c010ca1af8f1475 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Fri, 8 Nov 2024 17:29:23 +0800 Subject: [PATCH 1/5] Add unit tests for inspect page url Signed-off-by: yubonluo --- .../index_header/index_header.test.tsx | 123 ++++++++++++++++++ .../saved_objects_table_page.tsx | 26 +--- .../public/utils.test.ts | 83 +++++++++++- .../saved_objects_management/public/utils.ts | 36 +++++ 4 files changed, 244 insertions(+), 24 deletions(-) create mode 100644 src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx new file mode 100644 index 000000000000..ade87e6e9fca --- /dev/null +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx @@ -0,0 +1,123 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { render } from '@testing-library/react'; +import { createOpenSearchDashboardsReactContext } from '../../../../../opensearch_dashboards_react/public'; +import { coreMock, workspacesServiceMock } from '../../../../../../core/public/mocks'; +import { BehaviorSubject } from 'rxjs'; +import { WorkspaceObject } from 'opensearch-dashboards/public'; +import { IntlProvider } from 'react-intl'; +import { IndexHeader } from './index_header'; + +describe('IndexHeader at new home page', () => { + const indexPattern = { id: 'default-index', title: 'Test Index Pattern', fields: [] }; + const mockCoreStart = coreMock.createStart(); + const workspaceObject = { + id: 'foo_id', + name: 'foo', + }; + const getIndexHeader = (props: any) => { + const mockHeaderControl = + (props?.header as Function) || + (() => { + return null; + }); + + const setDefault = jest.fn(); + const refreshFields = jest.fn(); + const deleteIndexPatternClick = jest.fn(); + const { Provider } = createOpenSearchDashboardsReactContext({ + ...mockCoreStart, + ...{ + application: { + ...mockCoreStart.application, + capabilities: { + ...mockCoreStart.application.capabilities, + workspaces: { enabled: true }, + }, + }, + uiSettings: { ...mockCoreStart.uiSettings, get: jest.fn().mockReturnValue(true) }, + workspaces: { + ...workspacesServiceMock.createStartContract(), + currentWorkspace$: new BehaviorSubject(props?.workspace), + }, + navigationUI: { + HeaderControl: mockHeaderControl, + }, + }, + }); + + return ( + + + + + + ); + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('renders the set default button when index is not default and user is in workspace', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { getByText } = render( + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'no-default-index', + workspace: workspaceObject, + }) + ); + + expect(getByText('Set as default index')).toBeInTheDocument(); + }); + + it('does not renders the set default button when index is default and user is in workspace', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { queryByText } = render( + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'default-index', + workspace: workspaceObject, + }) + ); + + expect(queryByText('Set as default index')).toBeNull(); + }); + + it('does not renders the set default button when index is not default and user is not in workspace', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { queryByText } = render( + getIndexHeader({ header: mockHeaderControl, defaultIndex: 'no-default-index' }) + ); + + expect(queryByText('Set as default index')).toBeNull(); + }); + + it('does not renders the set default button when index is default and user is not in workspace', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { queryByText } = render( + getIndexHeader({ header: mockHeaderControl, defaultIndex: 'default-index' }) + ); + + expect(queryByText('Set as default index')).toBeNull(); + }); +}); diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index 772d33199583..4d8f84a82f61 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -43,7 +43,7 @@ import { } from '../services'; import { SavedObjectsTable } from './objects_table'; import { NavigationPublicPluginStart } from '../../../navigation/public'; -import { formatUrlWithWorkspaceId } from '../../../../core/public/utils'; +import { formatInspectUrl } from '../utils'; const SavedObjectsTablePage = ({ coreStart, @@ -76,8 +76,6 @@ const SavedObjectsTablePage = ({ const itemsPerPage = coreStart.uiSettings.get('savedObjects:perPage', 50); const dateFormat = coreStart.uiSettings.get('dateFormat'); const currentWorkspace = useObservable(coreStart.workspaces.currentWorkspace$); - const basePath = coreStart.http.basePath; - const visibleWsIds = useObservable(coreStart.workspaces.workspaceList$)?.map((ws) => ws.id) || []; useEffect(() => { setBreadcrumbs([ @@ -119,26 +117,8 @@ const SavedObjectsTablePage = ({ workspaces={coreStart.workspaces} perPageConfig={itemsPerPage} goInspectObject={(savedObject) => { - const { editUrl } = savedObject.meta; - let finalEditUrl = editUrl; - if (useUpdatedUX && finalEditUrl) { - finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, '/app'); - } - if (finalEditUrl) { - let inAppUrl = basePath.prepend(finalEditUrl); - if (savedObject.workspaces?.length) { - if (currentWorkspace) { - inAppUrl = formatUrlWithWorkspaceId(finalEditUrl, currentWorkspace.id, basePath); - } else { - // find first workspace user have permission - const workspaceId = savedObject.workspaces.find((wsId) => - visibleWsIds.includes(wsId) - ); - if (workspaceId) { - inAppUrl = formatUrlWithWorkspaceId(finalEditUrl, workspaceId, basePath); - } - } - } + const inAppUrl = formatInspectUrl(savedObject, useUpdatedUX, currentWorkspace, coreStart); + if (inAppUrl) { return coreStart.application.navigateToUrl(inAppUrl); } }} diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index eebfdec8f61d..326b1023376a 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -3,7 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { formatWorkspaceIdParams } from './utils'; +import { coreMock } from '../../../core/public/mocks'; +import { formatInspectUrl, formatWorkspaceIdParams } from './utils'; describe('Utils', () => { it('formatWorkspaceIdParams with workspace null/undefined', async () => { @@ -41,4 +42,84 @@ describe('Utils', () => { }); expect(obj).toEqual({ foo: 'bar', availableWorkspaces: ['foo', 'bar'], workspaces: ['foo'] }); }); + + describe('navigateToInspectPage', () => { + const mockCoreStart = coreMock.createStart(); + const savedObject = { + type: 'dashboard', + id: 'dashboard', + attributes: {}, + references: [], + meta: { + editUrl: '/management/opensearch-dashboards/objects/savedDashboards/ID1', + }, + }; + + beforeEach(() => { + mockCoreStart.application.capabilities = { + ...mockCoreStart.application.capabilities, + workspaces: { + ...mockCoreStart.application.capabilities.workspaces, + enabled: true, + }, + }; + jest.clearAllMocks(); + }); + + it('formats URL correctly when useUpdatedUX is false and workspace is disabled', () => { + const currentWorkspace = { id: 'workspace1', name: 'workspace1' }; + mockCoreStart.application.capabilities = { + ...mockCoreStart.application.capabilities, + workspaces: { + ...mockCoreStart.application.capabilities.workspaces, + enabled: false, + }, + }; + const result = formatInspectUrl(savedObject, false, currentWorkspace, mockCoreStart); + expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); + }); + + it('formats URL correctly when useUpdatedUX is false, saved object does not belong to certain workspaces and not in current workspace', () => { + const result = formatInspectUrl(savedObject, false, null, mockCoreStart); + expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); + }); + + it('formats URL correctly when useUpdatedUX is true and in current workspace', () => { + const savedObjectWithWorkspaces = { + ...savedObject, + workspaces: ['workspace1'], + }; + const currentWorkspace = { id: 'workspace1', name: 'workspace1' }; + const result = formatInspectUrl( + savedObjectWithWorkspaces, + true, + currentWorkspace, + mockCoreStart + ); + + expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); + }); + + it('formats URL correctly when useUpdatedUX is true and saved object belongs to certain workspaces', () => { + const savedObjectWithWorkspaces = { + ...savedObject, + workspaces: ['workspace1'], + }; + mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace1', name: 'workspace1' }]); + const result = formatInspectUrl(savedObjectWithWorkspaces, true, null, mockCoreStart); + + expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); + }); + + it('formats URL correctly when useUpdatedUX is true and no workspace permission', () => { + const savedObjectWithWorkspaces = { + ...savedObject, + workspaces: ['workspace1'], + }; + mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace2', name: 'workspace2' }]); + const result = formatInspectUrl(savedObjectWithWorkspaces, true, null, mockCoreStart); + + expect(result).toBe('/app/objects/savedDashboards/ID1'); + }); + }); }); diff --git a/src/plugins/saved_objects_management/public/utils.ts b/src/plugins/saved_objects_management/public/utils.ts index 937e7767702d..a1ec261a1d9f 100644 --- a/src/plugins/saved_objects_management/public/utils.ts +++ b/src/plugins/saved_objects_management/public/utils.ts @@ -3,6 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { CoreStart, WorkspaceObject } from 'opensearch-dashboards/public'; +import { formatUrlWithWorkspaceId } from '../../../core/public/utils'; +import { SavedObjectWithMetadata } from './types'; + export function formatWorkspaceIdParams< T extends { workspaces?: string[] | null; availableWorkspaces?: string[] | null } >(obj: T): T | Omit { @@ -12,3 +16,35 @@ export function formatWorkspaceIdParams< } return others; } + +export function formatInspectUrl( + savedObject: SavedObjectWithMetadata, + useUpdatedUX: boolean, + currentWorkspace: WorkspaceObject | null | undefined, + coreStart: CoreStart +): string | undefined { + const { editUrl } = savedObject.meta; + let finalEditUrl = editUrl; + if (useUpdatedUX && finalEditUrl) { + finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, '/app'); + } + if (finalEditUrl) { + const basePath = coreStart.http.basePath; + let inAppUrl = basePath.prepend(finalEditUrl); + const workspaceEnabled = coreStart.application.capabilities.workspaces.enabled; + if (workspaceEnabled) { + if (currentWorkspace) { + inAppUrl = formatUrlWithWorkspaceId(finalEditUrl, currentWorkspace.id, basePath); + } else { + const visibleWsIds = coreStart.workspaces.workspaceList$.value?.map((ws) => ws.id) || []; + + // find first workspace user have permission + const workspaceId = savedObject?.workspaces?.find((wsId) => visibleWsIds.includes(wsId)); + if (workspaceId) { + inAppUrl = formatUrlWithWorkspaceId(finalEditUrl, workspaceId, basePath); + } + } + } + return inAppUrl; + } +} From 48ae92cea4f01591481abfad8a666ed1c385912a Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:32:15 +0000 Subject: [PATCH 2/5] Changeset file for PR #8834 created/updated --- changelogs/fragments/8834.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/8834.yml diff --git a/changelogs/fragments/8834.yml b/changelogs/fragments/8834.yml new file mode 100644 index 000000000000..78796507a6e4 --- /dev/null +++ b/changelogs/fragments/8834.yml @@ -0,0 +1,2 @@ +refactor: +- [Workspace] Add unit tests for inspect page url ([#8834](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8834)) \ No newline at end of file From 208cc1e8720d61f0c3790dd59db05b35a29e9f52 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Fri, 8 Nov 2024 17:36:15 +0800 Subject: [PATCH 3/5] optimize the code Signed-off-by: yubonluo --- src/plugins/saved_objects_management/public/utils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index 326b1023376a..d19fb49b9dbd 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -43,7 +43,7 @@ describe('Utils', () => { expect(obj).toEqual({ foo: 'bar', availableWorkspaces: ['foo', 'bar'], workspaces: ['foo'] }); }); - describe('navigateToInspectPage', () => { + describe('formatInspectUrl', () => { const mockCoreStart = coreMock.createStart(); const savedObject = { type: 'dashboard', From 6980151832f4172b2213fc26949849eccd49e0ab Mon Sep 17 00:00:00 2001 From: yubonluo Date: Fri, 8 Nov 2024 18:22:09 +0800 Subject: [PATCH 4/5] optimize the code Signed-off-by: yubonluo --- .../saved_objects_table_page.tsx | 2 +- .../public/utils.test.ts | 51 ++++++++++--------- .../saved_objects_management/public/utils.ts | 6 +-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index 4d8f84a82f61..0b32dfdfffce 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -117,7 +117,7 @@ const SavedObjectsTablePage = ({ workspaces={coreStart.workspaces} perPageConfig={itemsPerPage} goInspectObject={(savedObject) => { - const inAppUrl = formatInspectUrl(savedObject, useUpdatedUX, currentWorkspace, coreStart); + const inAppUrl = formatInspectUrl(savedObject, coreStart); if (inAppUrl) { return coreStart.application.navigateToUrl(inAppUrl); } diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index d19fb49b9dbd..5f4ac888c691 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -5,6 +5,7 @@ import { coreMock } from '../../../core/public/mocks'; import { formatInspectUrl, formatWorkspaceIdParams } from './utils'; +import { CoreStart } from 'opensearch-dashboards/public'; describe('Utils', () => { it('formatWorkspaceIdParams with workspace null/undefined', async () => { @@ -44,7 +45,7 @@ describe('Utils', () => { }); describe('formatInspectUrl', () => { - const mockCoreStart = coreMock.createStart(); + let mockCoreStart: CoreStart; const savedObject = { type: 'dashboard', id: 'dashboard', @@ -54,8 +55,14 @@ describe('Utils', () => { editUrl: '/management/opensearch-dashboards/objects/savedDashboards/ID1', }, }; + const savedObjectWithWorkspaces = { + ...savedObject, + workspaces: ['workspace1'], + }; beforeEach(() => { + jest.clearAllMocks(); + mockCoreStart = coreMock.createStart(); mockCoreStart.application.capabilities = { ...mockCoreStart.application.capabilities, workspaces: { @@ -63,11 +70,13 @@ describe('Utils', () => { enabled: true, }, }; - jest.clearAllMocks(); + mockCoreStart.uiSettings = { + ...mockCoreStart.uiSettings, + get: jest.fn().mockReturnValue(true), + }; }); it('formats URL correctly when useUpdatedUX is false and workspace is disabled', () => { - const currentWorkspace = { id: 'workspace1', name: 'workspace1' }; mockCoreStart.application.capabilities = { ...mockCoreStart.application.capabilities, workspaces: { @@ -75,49 +84,41 @@ describe('Utils', () => { enabled: false, }, }; - const result = formatInspectUrl(savedObject, false, currentWorkspace, mockCoreStart); + mockCoreStart.uiSettings = { + ...mockCoreStart.uiSettings, + get: jest.fn().mockReturnValue(false), + }; + const result = formatInspectUrl(savedObject, mockCoreStart); expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); }); it('formats URL correctly when useUpdatedUX is false, saved object does not belong to certain workspaces and not in current workspace', () => { - const result = formatInspectUrl(savedObject, false, null, mockCoreStart); + mockCoreStart.uiSettings = { + ...mockCoreStart.uiSettings, + get: jest.fn().mockReturnValue(false), + }; + const result = formatInspectUrl(savedObject, mockCoreStart); expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); }); it('formats URL correctly when useUpdatedUX is true and in current workspace', () => { - const savedObjectWithWorkspaces = { - ...savedObject, - workspaces: ['workspace1'], - }; const currentWorkspace = { id: 'workspace1', name: 'workspace1' }; - const result = formatInspectUrl( - savedObjectWithWorkspaces, - true, - currentWorkspace, - mockCoreStart - ); + mockCoreStart.workspaces.currentWorkspace$.next(currentWorkspace); + const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); }); it('formats URL correctly when useUpdatedUX is true and saved object belongs to certain workspaces', () => { - const savedObjectWithWorkspaces = { - ...savedObject, - workspaces: ['workspace1'], - }; mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace1', name: 'workspace1' }]); - const result = formatInspectUrl(savedObjectWithWorkspaces, true, null, mockCoreStart); + const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); }); it('formats URL correctly when useUpdatedUX is true and no workspace permission', () => { - const savedObjectWithWorkspaces = { - ...savedObject, - workspaces: ['workspace1'], - }; mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace2', name: 'workspace2' }]); - const result = formatInspectUrl(savedObjectWithWorkspaces, true, null, mockCoreStart); + const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); expect(result).toBe('/app/objects/savedDashboards/ID1'); }); diff --git a/src/plugins/saved_objects_management/public/utils.ts b/src/plugins/saved_objects_management/public/utils.ts index a1ec261a1d9f..9dada18e8711 100644 --- a/src/plugins/saved_objects_management/public/utils.ts +++ b/src/plugins/saved_objects_management/public/utils.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { CoreStart, WorkspaceObject } from 'opensearch-dashboards/public'; +import { CoreStart } from 'opensearch-dashboards/public'; import { formatUrlWithWorkspaceId } from '../../../core/public/utils'; import { SavedObjectWithMetadata } from './types'; @@ -19,11 +19,10 @@ export function formatWorkspaceIdParams< export function formatInspectUrl( savedObject: SavedObjectWithMetadata, - useUpdatedUX: boolean, - currentWorkspace: WorkspaceObject | null | undefined, coreStart: CoreStart ): string | undefined { const { editUrl } = savedObject.meta; + const useUpdatedUX = !!coreStart.uiSettings.get('home:useNewHomePage'); let finalEditUrl = editUrl; if (useUpdatedUX && finalEditUrl) { finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, '/app'); @@ -33,6 +32,7 @@ export function formatInspectUrl( let inAppUrl = basePath.prepend(finalEditUrl); const workspaceEnabled = coreStart.application.capabilities.workspaces.enabled; if (workspaceEnabled) { + const currentWorkspace = coreStart.workspaces.currentWorkspace$.value; if (currentWorkspace) { inAppUrl = formatUrlWithWorkspaceId(finalEditUrl, currentWorkspace.id, basePath); } else { From d70bae1346549a8884d1a0ebe8a7213a4222f521 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Mon, 11 Nov 2024 11:13:20 +0800 Subject: [PATCH 5/5] optimize the code Signed-off-by: yubonluo --- .../index_header/index_header.test.tsx | 52 ++++++++++++++++--- .../public/utils.test.ts | 2 +- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx index ade87e6e9fca..cc3b785344df 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/index_header/index_header.test.tsx @@ -36,7 +36,7 @@ describe('IndexHeader at new home page', () => { ...mockCoreStart.application, capabilities: { ...mockCoreStart.application.capabilities, - workspaces: { enabled: true }, + workspaces: { enabled: props.workspaceEnabled }, }, }, uiSettings: { ...mockCoreStart.uiSettings, get: jest.fn().mockReturnValue(true) }, @@ -69,6 +69,36 @@ describe('IndexHeader at new home page', () => { jest.clearAllMocks(); }); + it('renders the set default button when index is not default and workspace is disabled', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { getByText } = render( + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'no-default-index', + workspaceEnabled: false, + }) + ); + + expect(getByText('Set as default index')).toBeInTheDocument(); + }); + + it('does not render the set default button when index is default and workspace is disabled', () => { + const mockHeaderControl = ({ controls }) => { + return controls?.[1]?.label ?? null; + }; + const { queryByText } = render( + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'default-index', + workspaceEnabled: false, + }) + ); + + expect(queryByText('Set as default index')).toBeNull(); + }); + it('renders the set default button when index is not default and user is in workspace', () => { const mockHeaderControl = ({ controls }) => { return controls?.[1]?.label ?? null; @@ -78,13 +108,14 @@ describe('IndexHeader at new home page', () => { header: mockHeaderControl, defaultIndex: 'no-default-index', workspace: workspaceObject, + workspaceEnabled: true, }) ); expect(getByText('Set as default index')).toBeInTheDocument(); }); - it('does not renders the set default button when index is default and user is in workspace', () => { + it('does not render the set default button when index is default and user is in workspace', () => { const mockHeaderControl = ({ controls }) => { return controls?.[1]?.label ?? null; }; @@ -93,29 +124,38 @@ describe('IndexHeader at new home page', () => { header: mockHeaderControl, defaultIndex: 'default-index', workspace: workspaceObject, + workspaceEnabled: true, }) ); expect(queryByText('Set as default index')).toBeNull(); }); - it('does not renders the set default button when index is not default and user is not in workspace', () => { + it('does not render the set default button when index is not default and user is not in workspace', () => { const mockHeaderControl = ({ controls }) => { return controls?.[1]?.label ?? null; }; const { queryByText } = render( - getIndexHeader({ header: mockHeaderControl, defaultIndex: 'no-default-index' }) + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'no-default-index', + workspaceEnabled: true, + }) ); expect(queryByText('Set as default index')).toBeNull(); }); - it('does not renders the set default button when index is default and user is not in workspace', () => { + it('does not render the set default button when index is default and user is not in workspace', () => { const mockHeaderControl = ({ controls }) => { return controls?.[1]?.label ?? null; }; const { queryByText } = render( - getIndexHeader({ header: mockHeaderControl, defaultIndex: 'default-index' }) + getIndexHeader({ + header: mockHeaderControl, + defaultIndex: 'default-index', + workspaceEnabled: true, + }) ); expect(queryByText('Set as default index')).toBeNull(); diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index 5f4ac888c691..bcaed2bb9417 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -116,7 +116,7 @@ describe('Utils', () => { expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); }); - it('formats URL correctly when useUpdatedUX is true and no workspace permission', () => { + it('formats URL correctly when useUpdatedUX is true and the object does not belong to any workspace', () => { mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace2', name: 'workspace2' }]); const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart);