Skip to content
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

fix failed modal cross component tests in ci env #298

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading