-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workspace] Register a workspace dropdown menu at the top of left nav bar #6150
Merged
ruanyl
merged 5 commits into
opensearch-project:main
from
ruanyl:workspace-dropdown-selector-in-left-nav
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So nice to have this in core mock, have encountered type error in some test cases