-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into filter-left-menu-based-on-current-workspace
Signed-off-by: SuZhou-Joe <[email protected]>
- Loading branch information
Showing
38 changed files
with
967 additions
and
137 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
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,19 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { httpServerMock } from '../mocks'; | ||
import { getWorkspaceState, updateWorkspaceState } from './workspace'; | ||
|
||
describe('updateWorkspaceState', () => { | ||
it('update with payload', () => { | ||
const requestMock = httpServerMock.createOpenSearchDashboardsRequest(); | ||
updateWorkspaceState(requestMock, { | ||
requestWorkspaceId: 'foo', | ||
}); | ||
expect(getWorkspaceState(requestMock)).toEqual({ | ||
requestWorkspaceId: 'foo', | ||
}); | ||
}); | ||
}); |
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,36 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { OpenSearchDashboardsRequest, ensureRawRequest } from '../http/router'; | ||
|
||
export interface WorkspaceState { | ||
requestWorkspaceId?: string; | ||
} | ||
|
||
/** | ||
* This function will be used as a proxy | ||
* because `ensureRequest` is only importable from core module. | ||
* | ||
* @param workspaceId string | ||
* @returns void | ||
*/ | ||
export const updateWorkspaceState = ( | ||
request: OpenSearchDashboardsRequest, | ||
payload: Partial<WorkspaceState> | ||
) => { | ||
const rawRequest = ensureRawRequest(request); | ||
|
||
rawRequest.app = { | ||
...rawRequest.app, | ||
...payload, | ||
}; | ||
}; | ||
|
||
export const getWorkspaceState = (request: OpenSearchDashboardsRequest): WorkspaceState => { | ||
const { requestWorkspaceId } = ensureRawRequest(request).app as WorkspaceState; | ||
return { | ||
requestWorkspaceId, | ||
}; | ||
}; |
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
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
Oops, something went wrong.