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.
[Workspace] Register a workspace dropdown menu at the top of left nav…
… bar (opensearch-project#6150) When workspace is enabled, the workspace plugin will register a workspace dropdown menu via `chrome.registerCollapsibleNavHeader` which displays a list of workspaces, links to create workspace page and workspace list page. --------- Signed-off-by: Yulong Ruan <[email protected]>
- Loading branch information
Showing
12 changed files
with
372 additions
and
26 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
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
120 changes: 120 additions & 0 deletions
120
src/plugins/workspace/public/components/workspace_menu/workspace_menu.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,120 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
|
||
import { WorkspaceMenu } from './workspace_menu'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { CoreStart } from '../../../../../core/public'; | ||
|
||
describe('<WorkspaceMenu />', () => { | ||
let coreStartMock: CoreStart; | ||
|
||
beforeEach(() => { | ||
coreStartMock = coreMock.createStart(); | ||
coreStartMock.workspaces.initialized$.next(true); | ||
jest.spyOn(coreStartMock.application, 'getUrlForApp').mockImplementation((appId: string) => { | ||
return `https://test.com/app/${appId}`; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should display a list of workspaces in the dropdown', () => { | ||
coreStartMock.workspaces.workspaceList$.next([ | ||
{ id: 'workspace-1', name: 'workspace 1' }, | ||
{ id: 'workspace-2', name: 'workspace 2' }, | ||
]); | ||
|
||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
fireEvent.click(screen.getByText(/select a workspace/i)); | ||
|
||
expect(screen.getByText(/workspace 1/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/workspace 2/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display current workspace name', () => { | ||
coreStartMock.workspaces.currentWorkspace$.next({ id: 'workspace-1', name: 'workspace 1' }); | ||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
expect(screen.getByText(/workspace 1/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the workspace dropdown list', async () => { | ||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
fireEvent.click(screen.getByText(/select a workspace/i)); | ||
|
||
expect(screen.getByLabelText(/close workspace dropdown/i)).toBeInTheDocument(); | ||
fireEvent.click(screen.getByLabelText(/close workspace dropdown/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByLabelText(/close workspace dropdown/i)).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should navigate to the workspace', () => { | ||
coreStartMock.workspaces.workspaceList$.next([ | ||
{ id: 'workspace-1', name: 'workspace 1' }, | ||
{ id: 'workspace-2', name: 'workspace 2' }, | ||
]); | ||
|
||
const originalLocation = window.location; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: jest.fn(), | ||
}, | ||
}); | ||
|
||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
fireEvent.click(screen.getByText(/select a workspace/i)); | ||
fireEvent.click(screen.getByText(/workspace 1/i)); | ||
|
||
expect(window.location.assign).toHaveBeenCalledWith( | ||
'https://test.com/w/workspace-1/app/workspace_overview' | ||
); | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
}); | ||
}); | ||
|
||
it('should navigate to create workspace page', () => { | ||
const originalLocation = window.location; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: jest.fn(), | ||
}, | ||
}); | ||
|
||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
fireEvent.click(screen.getByText(/select a workspace/i)); | ||
fireEvent.click(screen.getByText(/create workspace/i)); | ||
expect(window.location.assign).toHaveBeenCalledWith('https://test.com/app/workspace_create'); | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
}); | ||
}); | ||
|
||
it('should navigate to workspace list page', () => { | ||
const originalLocation = window.location; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: jest.fn(), | ||
}, | ||
}); | ||
|
||
render(<WorkspaceMenu coreStart={coreStartMock} />); | ||
fireEvent.click(screen.getByText(/select a workspace/i)); | ||
fireEvent.click(screen.getByText(/all workspace/i)); | ||
expect(window.location.assign).toHaveBeenCalledWith('https://test.com/app/workspace_list'); | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: originalLocation, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.