From 6e68a539a3d9cddc9e489e52ff651abc42b74d8a Mon Sep 17 00:00:00 2001 From: tygao Date: Fri, 15 Mar 2024 14:49:58 +0800 Subject: [PATCH] fix test for delete workspace modal (#299) Signed-off-by: tygao --- .../delete_workspace_modal.test.tsx | 6 +++--- .../components/workspace_list/index.test.tsx | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.test.tsx b/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.test.tsx index 15078b87bade..d2ba2e7876ef 100644 --- a/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.test.tsx +++ b/src/plugins/workspace/public/components/delete_workspace_modal/delete_workspace_modal.test.tsx @@ -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'; @@ -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(); diff --git a/src/plugins/workspace/public/components/workspace_list/index.test.tsx b/src/plugins/workspace/public/components/workspace_list/index.test.tsx index f9e5a388368e..1719bfe7a109 100644 --- a/src/plugins/workspace/public/components/workspace_list/index.test.tsx +++ b/src/plugins/workspace/public/components/workspace_list/index.test.tsx @@ -16,6 +16,14 @@ import { OpenSearchDashboardsContextProvider } from '../../../../../plugins/open jest.mock('../utils/workspace'); +jest.mock('../delete_workspace_modal', () => ({ + DeleteWorkspaceModal: ({ onClose }: { onClose: () => void }) => ( +
+
+ ), +})); + function getWrapWorkspaceListInContext( workspaceList = [ { id: 'id1', name: 'name1' }, @@ -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 () => {