forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MD]Fix data source link to point to correct page, and use in page re…
…direct instead of reloading (opensearch-project#6604) Signed-off-by: Zhongnan Su <[email protected]>
- Loading branch information
1 parent
309193a
commit dcec7b5
Showing
3 changed files
with
97 additions
and
34 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...s/data_source_management/public/components/data_source_column/data_source_column.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { mount } from 'enzyme'; | ||
import { EuiBadge, EuiLink } from '@elastic/eui'; | ||
import { DataSourceColumn } from './data_source_column'; | ||
import { DataSourceTableItem } from '../../types'; | ||
import * as utils from '../utils'; | ||
import React from 'react'; | ||
import { DSM_APP_ID } from '../../plugin'; | ||
|
||
describe('DataSourceColumn', () => { | ||
let dataSourceColumn: DataSourceColumn; | ||
let savedObjectPromise: Promise<any>; | ||
|
||
beforeEach(() => { | ||
savedObjectPromise = Promise.resolve({ client: {} }); | ||
dataSourceColumn = new DataSourceColumn(savedObjectPromise); | ||
}); | ||
|
||
it('should render null when referenceId is not provided', () => { | ||
const euiColumn = dataSourceColumn.euiColumn.render(''); | ||
expect(euiColumn).toBeNull(); | ||
}); | ||
|
||
it('should render "Deleted" badge when data source is not found', () => { | ||
dataSourceColumn.data = new Map<string, DataSourceTableItem>(); | ||
const wrapper = mount(<>{dataSourceColumn.euiColumn.render('1')}</>); | ||
expect(wrapper.find(EuiBadge).text()).toBe('Deleted'); | ||
}); | ||
|
||
it('should render EuiLink with correct title and navigate to the correct path', () => { | ||
const dataSources = [ | ||
{ id: '1', title: 'DataSource 1' }, | ||
{ id: '2', title: 'DataSource 2' }, | ||
]; | ||
dataSourceColumn.data = new Map<string, DataSourceTableItem>( | ||
dataSources.map((dataSource) => [dataSource.id, dataSource]) | ||
); | ||
const navigateToAppMock = jest.fn(); | ||
spyOn(utils, 'getApplication').and.returnValue({ navigateToApp: navigateToAppMock }); | ||
const wrapper = mount(<>{dataSourceColumn.euiColumn.render('1')}</>); | ||
expect(wrapper.find(EuiLink).text()).toBe('DataSource 1'); | ||
wrapper.find(EuiLink).simulate('click'); | ||
|
||
expect(navigateToAppMock).toHaveBeenCalledWith('management', { | ||
path: `opensearch-dashboards/${DSM_APP_ID}/1`, | ||
}); | ||
}); | ||
|
||
it('should load data sources and set the data property', async () => { | ||
const dataSources = [ | ||
{ id: '1', title: 'DataSource 1' }, | ||
{ id: '2', title: 'DataSource 2' }, | ||
]; | ||
const getDataSourcesMock = jest.fn(() => Promise.resolve(dataSources)); | ||
|
||
jest.spyOn(utils, 'getDataSources').mockImplementation(getDataSourcesMock); | ||
|
||
await dataSourceColumn.loadData(); | ||
expect(dataSourceColumn.data).toEqual( | ||
new Map<string, DataSourceTableItem>( | ||
dataSources.map((dataSource) => [dataSource.id, dataSource]) | ||
) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters