Skip to content

Commit

Permalink
feat: improve test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 21, 2024
1 parent 8eb4e7d commit 493e67c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(<Relationships {...props} />);

await findByText('Type of the saved object');

expect(getByTestId('relationshipsTitle')).toHaveAttribute('href', '/app/indexPatterns#/edit/1');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(<Table {...customizedProps} />);
expect(
getByTestId('savedObjectsTableRowTitle').querySelector(
'[href="/app/indexPatterns/patterns/1"]'
)
).toBeInTheDocument();
});
});

0 comments on commit 493e67c

Please sign in to comment.