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.
[Discover - datasource selector] Add extension group title and modal (o…
…pensearch-project#5815) * add log explorer re-directon modal Signed-off-by: Eric <[email protected]> * adjustments to comments Signed-off-by: Eric <[email protected]> * add one missing i18n Signed-off-by: Eric <[email protected]> * add redirection text to group title Signed-off-by: Eric <[email protected]> * include changes in changelog Signed-off-by: Eric <[email protected]> * remove redundent title addition and unnecessary modal toggle functions Signed-off-by: Eric <[email protected]> * remove one comment Signed-off-by: Eric <[email protected]> * add i18n Signed-off-by: Eric <[email protected]> * add unit tests for modal Signed-off-by: Eric <[email protected]> * test id change Signed-off-by: Eric <[email protected]> * add devDependencies for tests Signed-off-by: Eric <[email protected]> * use open confirm api and move mock file to discover mock folder Signed-off-by: Eric <[email protected]> * remove unused type Signed-off-by: Eric <[email protected]> * remove modal for log explorer redirection Signed-off-by: Eric <[email protected]> * modify changelog Signed-off-by: Eric <[email protected]> * remove modal test Signed-off-by: Eric <[email protected]> * remove one modal related test Signed-off-by: Eric <[email protected]> --------- Signed-off-by: Eric <[email protected]>
- Loading branch information
1 parent
0f34d69
commit f97e554
Showing
7 changed files
with
192 additions
and
19 deletions.
There are no files selected for viewing
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
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
110 changes: 110 additions & 0 deletions
110
src/plugins/data_explorer/public/components/sidebar/index.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,110 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
import { Sidebar } from './index'; // Adjust the import path as necessary | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { MockS3DataSource } from '../../../../discover/public/__mock__/index.test.mock'; | ||
import { createMemoryHistory } from 'history'; | ||
import { Router } from 'react-router-dom'; | ||
|
||
const mockStore = configureMockStore(); | ||
const initialState = { | ||
metadata: { indexPattern: 'some-index-pattern-id' }, | ||
}; | ||
const store = mockStore(initialState); | ||
|
||
jest.mock('../../../../opensearch_dashboards_react/public', () => { | ||
return { | ||
toMountPoint: jest.fn().mockImplementation((component) => () => component), | ||
useOpenSearchDashboards: jest.fn().mockReturnValue({ | ||
services: { | ||
data: { | ||
indexPatterns: {}, | ||
dataSources: { | ||
dataSourceService: { | ||
dataSources$: { | ||
subscribe: jest.fn((callback) => { | ||
callback({ | ||
's3-prod-mock': new MockS3DataSource({ | ||
name: 's3-prod-mock', | ||
type: 's3glue', | ||
metadata: {}, | ||
}), | ||
}); | ||
return { unsubscribe: jest.fn() }; | ||
}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
notifications: { | ||
toasts: { | ||
addError: jest.fn(), | ||
}, | ||
}, | ||
application: { | ||
navigateToUrl: jest.fn(), | ||
}, | ||
overlays: { | ||
openConfirm: jest.fn(), | ||
}, | ||
}, | ||
}), | ||
withOpenSearchDashboards: () => (Component: React.ComponentClass) => (props: any) => ( | ||
<Component {...props} /> | ||
), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../../data_explorer/public', () => ({ | ||
useTypedSelector: jest.fn(), | ||
useTypedDispatch: jest.fn(), | ||
})); | ||
|
||
describe('Sidebar Component', () => { | ||
it('renders without crashing', () => { | ||
const { container, getByTestId } = render( | ||
<Provider store={store}> | ||
<Sidebar /> | ||
</Provider> | ||
); | ||
expect(container).toBeInTheDocument(); | ||
expect(getByTestId('dataExplorerDSSelect')).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows title extensions on the non-index pattern data source', () => { | ||
const { getByText, getByTestId } = render( | ||
<Provider store={store}> | ||
<Sidebar /> | ||
</Provider> | ||
); | ||
|
||
fireEvent.click(getByTestId('comboBoxToggleListButton')); | ||
waitFor(() => { | ||
expect(getByText('Open in Log Explorer')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('redirects to log explorer when clicking open-in-log-explorer button', () => { | ||
const history = createMemoryHistory(); | ||
const { getByText, getByTestId } = render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<Sidebar /> | ||
</Router> | ||
</Provider> | ||
); | ||
|
||
fireEvent.click(getByTestId('comboBoxToggleListButton')); | ||
waitFor(() => { | ||
expect(getByText('s3-prod-mock')).toBeInTheDocument(); | ||
fireEvent.click(getByText('s3-prod-mock')); | ||
expect(history.location.pathname).toContain('observability-logs#/explorer'); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export class MockS3DataSource { | ||
protected name: string; | ||
protected type: string; | ||
protected metadata: any; | ||
|
||
constructor({ name, type, metadata }: { name: string; type: string; metadata: any }) { | ||
this.name = name; | ||
this.type = type; | ||
this.metadata = metadata; | ||
} | ||
|
||
async getDataSet(dataSetParams?: any) { | ||
return [this.name]; | ||
} | ||
|
||
getName() { | ||
return this.name; | ||
} | ||
|
||
getType() { | ||
return this.type; | ||
} | ||
} |
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