Skip to content

Commit

Permalink
fix test for delete workspace modal (#299)
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Mar 18, 2024
1 parent 5133bd8 commit 4b12d65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { DeleteWorkspaceModal, DeleteWorkspaceModalProps } from './delete_workspace_modal';
import { coreMock } from '../../../../../core/public/mocks';
import { render, fireEvent, waitFor } from '@testing-library/react';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import { workspaceClientMock } from '../../../public/workspace_client.mock';
import { OpenSearchDashboardsContextProvider } from '../../../../../plugins/opensearch_dashboards_react/public';

Expand Down Expand Up @@ -34,11 +34,11 @@ describe('DeleteWorkspaceModal', () => {
jest.clearAllMocks();
});

it('should render normally', () => {
it('should render normally', async () => {
const { getByText, baseElement, getByTestId } = render(
getWrapWorkspaceDeleteModalInContext(defaultProps)
);

await screen.findByTestId('delete-workspace-modal-header');
expect(getByText('Delete workspace')).toBeInTheDocument();
expect(getByTestId('delete-workspace-modal-header')).toBeInTheDocument();
expect(getByTestId('delete-workspace-modal-body')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import { OpenSearchDashboardsContextProvider } from '../../../../../plugins/open

jest.mock('../utils/workspace');

jest.mock('../delete_workspace_modal', () => ({
DeleteWorkspaceModal: ({ onClose }: { onClose: () => void }) => (
<div aria-label="mock delete workspace modal">
<button onClick={onClose} aria-label="mock delete workspace modal button" />
</div>
),
}));

function getWrapWorkspaceListInContext(
workspaceList = [
{ id: 'id1', name: 'name1' },
Expand Down Expand Up @@ -92,11 +100,10 @@ describe('WorkspaceList', () => {
const { getAllByTestId } = render(getWrapWorkspaceListInContext());
const deleteIcon = getAllByTestId('workspace-list-delete-icon')[0];
fireEvent.click(deleteIcon);
await screen.findByTestId('delete-workspace-modal-header');
expect(screen.getByTestId('delete-workspace-modal-header')).toBeInTheDocument();
const cancelButton = screen.getByTestId('delete-workspace-modal-cancel-button');
fireEvent.click(cancelButton);
expect(screen.queryByTestId('delete-workspace-modal-header')).not.toBeInTheDocument();
expect(screen.queryByLabelText('mock delete workspace modal')).toBeInTheDocument();
const modalCancelButton = screen.getByLabelText('mock delete workspace modal button');
fireEvent.click(modalCancelButton);
expect(screen.queryByLabelText('mock delete workspace modal')).not.toBeInTheDocument();
});

it('should be able to pagination when clicking pagination button', async () => {
Expand Down

0 comments on commit 4b12d65

Please sign in to comment.