-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace] Register four get started cards in home page (#7333)
* support get start card in home page Signed-off-by: yubonluo <[email protected]> * Changeset file for PR #7333 created/updated * fix unit test errors Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> --------- Signed-off-by: yubonluo <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 08c2a00) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4963000
commit 7a0b709
Showing
17 changed files
with
522 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Workspace] Register four get started cards in home page ([#7333](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7333)) |
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
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
6 changes: 6 additions & 0 deletions
6
src/plugins/workspace/public/components/home_get_start_card/index.ts
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,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { UseCaseFooter } from './use_case_footer'; |
156 changes: 156 additions & 0 deletions
156
src/plugins/workspace/public/components/home_get_start_card/use_case_footer.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,156 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { UseCaseFooter as UseCaseFooterComponent, UseCaseFooterProps } from './use_case_footer'; | ||
import { coreMock, httpServiceMock } from '../../../../../core/public/mocks'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { WorkspaceUseCase } from '../../types'; | ||
import { CoreStart } from 'opensearch-dashboards/public'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { WORKSPACE_USE_CASES } from '../../../common/constants'; | ||
|
||
describe('UseCaseFooter', () => { | ||
// let coreStartMock: CoreStart; | ||
const navigateToApp = jest.fn(); | ||
const registeredUseCases$ = new BehaviorSubject([ | ||
WORKSPACE_USE_CASES.observability, | ||
WORKSPACE_USE_CASES['security-analytics'], | ||
WORKSPACE_USE_CASES.analytics, | ||
WORKSPACE_USE_CASES.search, | ||
]); | ||
|
||
const getMockCore = (isDashboardAdmin: boolean = true) => { | ||
const coreStartMock = coreMock.createStart(); | ||
coreStartMock.application.capabilities = { | ||
...coreStartMock.application.capabilities, | ||
dashboards: { isDashboardAdmin }, | ||
}; | ||
coreStartMock.application = { | ||
...coreStartMock.application, | ||
navigateToApp, | ||
}; | ||
jest.spyOn(coreStartMock.application, 'getUrlForApp').mockImplementation((appId: string) => { | ||
return `https://test.com/app/${appId}`; | ||
}); | ||
return coreStartMock; | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
const UseCaseFooter = (props: UseCaseFooterProps) => { | ||
return ( | ||
<IntlProvider locale="en"> | ||
<UseCaseFooterComponent {...props} /> | ||
</IntlProvider> | ||
); | ||
}; | ||
it('renders create workspace button for admin when no workspaces within use case exist', () => { | ||
const { getByTestId } = render( | ||
<UseCaseFooter | ||
useCaseId="analytics" | ||
useCaseTitle="Analytics" | ||
core={getMockCore()} | ||
registeredUseCases$={registeredUseCases$} | ||
/> | ||
); | ||
|
||
const button = getByTestId('useCase.footer.createWorkspace.button'); | ||
expect(button).toBeInTheDocument(); | ||
fireEvent.click(button); | ||
const createWorkspaceButtonInModal = getByTestId('useCase.footer.modal.create.button'); | ||
expect(createWorkspaceButtonInModal).toHaveAttribute( | ||
'href', | ||
'https://test.com/app/workspace_create' | ||
); | ||
}); | ||
|
||
it('renders create workspace button for non-admin when no workspaces within use case exist', () => { | ||
const { getByTestId } = render( | ||
<UseCaseFooter | ||
useCaseId="analytics" | ||
useCaseTitle="Analytics" | ||
core={getMockCore(false)} | ||
registeredUseCases$={registeredUseCases$} | ||
/> | ||
); | ||
|
||
const button = getByTestId('useCase.footer.createWorkspace.button'); | ||
expect(button).toBeInTheDocument(); | ||
fireEvent.click(button); | ||
expect(screen.getByText('Unable to create workspace')).toBeInTheDocument(); | ||
expect(screen.queryByTestId('useCase.footer.modal.create.button')).not.toBeInTheDocument(); | ||
fireEvent.click(getByTestId('useCase.footer.modal.close.button')); | ||
}); | ||
|
||
it('renders open workspace button when one workspace exists', () => { | ||
const core = getMockCore(); | ||
core.workspaces.workspaceList$.next([ | ||
{ id: 'workspace-1', name: 'workspace 1', features: ['use-case-observability'] }, | ||
]); | ||
const { getByTestId } = render( | ||
<UseCaseFooter | ||
useCaseId="observability" | ||
useCaseTitle="Observability" | ||
core={core} | ||
registeredUseCases$={registeredUseCases$} | ||
/> | ||
); | ||
|
||
const button = getByTestId('useCase.footer.openWorkspace.button'); | ||
expect(button).toBeInTheDocument(); | ||
expect(button).not.toBeDisabled(); | ||
expect(button).toHaveAttribute('href', 'https://test.com/w/workspace-1/app/discover'); | ||
}); | ||
|
||
it('renders select workspace popover when multiple workspaces exist', () => { | ||
const core = getMockCore(); | ||
core.workspaces.workspaceList$.next([ | ||
{ id: 'workspace-1', name: 'workspace 1', features: ['use-case-observability'] }, | ||
{ id: 'workspace-2', name: 'workspace 2', features: ['use-case-observability'] }, | ||
]); | ||
|
||
const originalLocation = window.location; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: jest.fn(), | ||
}, | ||
}); | ||
|
||
render( | ||
<UseCaseFooter | ||
useCaseId="observability" | ||
useCaseTitle="Observability" | ||
core={core} | ||
registeredUseCases$={registeredUseCases$} | ||
/> | ||
); | ||
|
||
const button = screen.getByText('Select workspace'); | ||
expect(button).toBeInTheDocument(); | ||
|
||
fireEvent.click(button); | ||
expect(screen.getByText('workspace 1')).toBeInTheDocument(); | ||
expect(screen.getByText('workspace 2')).toBeInTheDocument(); | ||
expect(screen.getByText('Observability Workspaces')).toBeInTheDocument(); | ||
|
||
const inputElement = screen.getByPlaceholderText('Search'); | ||
expect(inputElement).toBeInTheDocument(); | ||
fireEvent.change(inputElement, { target: { value: 'workspace 1' } }); | ||
expect(screen.queryByText('workspace 2')).toBeNull(); | ||
|
||
fireEvent.click(screen.getByText('workspace 1')); | ||
expect(window.location.assign).toHaveBeenCalledWith( | ||
'https://test.com/w/workspace-1/app/discover' | ||
); | ||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.