From 493e67c15d88d9853b20dc1a7ccf46601aea349a Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 21 Aug 2024 18:40:55 +0800 Subject: [PATCH] feat: improve test coverage Signed-off-by: SuZhou-Joe --- .../components/relationships.test.tsx | 48 +++++++++++++++++++ .../objects_table/components/table.test.tsx | 33 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx index 1f21e5990c74..8389941c56bf 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx @@ -32,6 +32,7 @@ import React from 'react'; import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { httpServiceMock } from '../../../../../../core/public/mocks'; import { Relationships, RelationshipsProps } from './relationships'; +import { render } from '@testing-library/react'; jest.mock('../../../lib/fetch_export_by_type_and_search', () => ({ fetchExportByTypeAndSearch: jest.fn(), @@ -702,4 +703,51 @@ describe('Relationships from legacy app', () => { expect(props.getRelationships).toHaveBeenCalled(); expect(component).toMatchSnapshot(); }); + + it('should replace the url to standard application when new nav group is enabled', async () => { + const props: RelationshipsProps = { + goInspectObject: () => {}, + canGoInApp: () => true, + basePath: httpServiceMock.createSetupContract().basePath, + getRelationships: jest.fn().mockImplementation(() => [ + { + type: 'index-patterns', + id: '1', + relationship: 'child', + meta: { + editUrl: '/management/kibana/objects/savedVisualizations/1', + icon: 'visualizeApp', + inAppUrl: { + path: '/app/management/opensearch-dashboards/indexPatterns#/edit/1', + uiCapabilitiesPath: 'visualize.show', + }, + title: 'My Visualization Title 1', + }, + }, + ]), + savedObject: { + id: '1', + type: 'dashboard', + attributes: {}, + references: [], + meta: { + title: 'MyDashboard', + icon: 'dashboardApp', + editUrl: '/management/kibana/objects/savedDashboards/1', + inAppUrl: { + path: '/dashboard/1', + uiCapabilitiesPath: 'dashboard.show', + }, + }, + }, + close: jest.fn(), + useUpdatedUX: true, + }; + + const { getByTestId, findByText } = render(); + + await findByText('Type of the saved object'); + + expect(getByTestId('relationshipsTitle')).toHaveAttribute('href', '/app/indexPatterns#/edit/1'); + }); }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx index ddf50e68c25a..cc0da7ea775d 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx @@ -38,6 +38,7 @@ import { columnServiceMock } from '../../../services/column_service.mock'; import { SavedObjectsManagementAction } from '../../..'; import { Table, TableProps } from './table'; import { WorkspaceAttribute } from 'opensearch-dashboards/public'; +import { render } from '@testing-library/react'; const defaultProps: TableProps = { basePath: httpServiceMock.createSetupContract().basePath, @@ -257,4 +258,36 @@ describe('Table', () => { duplicateAction.onClick(); expect(onDuplicateSingle).toHaveBeenCalled(); }); + + it('should replace legacy path to standard application path when useUpdatedUX is true', () => { + const showDuplicate = true; + const customizedProps = { + ...defaultProps, + showDuplicate, + useUpdatedUX: true, + items: [ + { + id: '1', + type: 'index-pattern', + attributes: {}, + references: [], + meta: { + title: `MyIndexPattern*`, + icon: 'indexPatternApp', + editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1', + inAppUrl: { + path: '/app/management/opensearch-dashboards/indexPatterns/patterns/1', + uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns', + }, + }, + }, + ], + }; + const { getByTestId } = render(); + expect( + getByTestId('savedObjectsTableRowTitle').querySelector( + '[href="/app/indexPatterns/patterns/1"]' + ) + ).toBeInTheDocument(); + }); });