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.
Signed-off-by: tygao <tygao@amazon.com>
- Loading branch information
Showing
3 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
src/plugins/workspace/public/components/workspace_list/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/plugins/workspace/public/components/workspace_list/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,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { WorkspaceList } from './index'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
|
||
import { of } from 'rxjs'; | ||
|
||
jest.doMock('../../../../opensearch_dashboards_react/public', () => ({ | ||
useOpenSearchDashboards: jest.fn().mockReturnValue({ | ||
services: coreMock.createStart(), | ||
}), | ||
})); | ||
|
||
test('render normally', () => { | ||
const component = shallow(<WorkspaceList />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
describe('WorkspaceList', function () { | ||
it('should render title and table regularly', () => { | ||
const { getByText, getByRole } = render(<WorkspaceList />); | ||
expect(getByText('Workspaces')).toBeInTheDocument(); | ||
expect(getByRole('table')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render data in table based on workspace list', async () => { | ||
jest.doMock('../../../../opensearch_dashboards_react/public', () => ({ | ||
useOpenSearchDashboards: jest.fn().mockReturnValue({ | ||
services: { | ||
...coreMock.createStart(), | ||
workspaces: { | ||
workspaceList$: of([ | ||
{ id: 'id1', name: 'name1' }, | ||
{ id: 'id2', name: 'name2' }, | ||
]), | ||
}, | ||
}, | ||
}), | ||
})); | ||
const { getByText } = render(<WorkspaceList />); | ||
await waitFor(() => { | ||
expect(getByText('name1')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
src/plugins/workspace/public/components/workspace_list/workspace_actions_menu.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,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { EuiButton, EuiContextMenuPanel, EuiContextMenuItem, EuiPopover } from '@elastic/eui'; | ||
|
||
export const WorkspaceActionsMenu = () => { | ||
const [isPopoverOpen, setPopover] = useState(false); | ||
|
||
const onButtonClick = () => { | ||
setPopover(!isPopoverOpen); | ||
}; | ||
|
||
const closePopover = () => { | ||
setPopover(false); | ||
}; | ||
|
||
const items = [ | ||
<EuiContextMenuItem key="delete" icon="trash" onClick={closePopover}> | ||
Delete | ||
</EuiContextMenuItem>, | ||
]; | ||
|
||
const button = ( | ||
<EuiButton iconType="arrowDown" iconSide="right" onClick={onButtonClick}> | ||
Actions | ||
</EuiButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
id="smallContextMenuExample" | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenuPanel size="s" items={items} /> | ||
</EuiPopover> | ||
); | ||
}; |