Skip to content

Commit

Permalink
Added delete button tests for file_type.
Browse files Browse the repository at this point in the history
Added delete button tests for files_table.
  • Loading branch information
adcoelho committed Apr 5, 2023
1 parent 7fba826 commit 9009f41
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('FileDeleteButtonIcon', () => {

userEvent.click(deleteButton);

expect(await screen.findAllByTestId('property-actions-confirm-modal'));
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});

it('clicking delete button in the confirmation modal calls deleteFileAttachment with proper params', async () => {
Expand All @@ -61,7 +61,7 @@ describe('FileDeleteButtonIcon', () => {

userEvent.click(deleteButton);

expect(await screen.findAllByTestId('property-actions-confirm-modal'));
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

userEvent.click(await screen.findByTestId('confirmModalConfirmButton'));

Expand Down
25 changes: 25 additions & 0 deletions x-pack/plugins/cases/public/components/files/file_type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FILE_ATTACHMENT_TYPE } from '../../../common/api';
import { createAppMockRenderer } from '../../common/mock';
import { basicCase, basicFileMock } from '../../containers/mock';
import { getFileType } from './file_type';
import userEvent from '@testing-library/user-event';

describe('getFileType', () => {
const fileType = getFileType();
Expand Down Expand Up @@ -62,6 +63,30 @@ describe('getFileType', () => {
expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument();
});

it('actions renders a delete button', async () => {
appMockRender = createAppMockRenderer();

// @ts-ignore
appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).actions);

expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument();
});

it('clicking the delete button in actions opens deletion modal', async () => {
appMockRender = createAppMockRenderer();

// @ts-ignore
appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).actions);

const deleteButton = await screen.findByTestId('cases-files-delete-button');

expect(deleteButton).toBeInTheDocument();

userEvent.click(deleteButton);

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});

it('empty externalReferenceMetadata returns blank FileAttachmentViewObject', () => {
expect(
fileType.getAttachmentViewObject({ ...attachmentViewProps, externalReferenceMetadata: {} })
Expand Down
30 changes: 30 additions & 0 deletions x-pack/plugins/cases/public/components/files/files_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@ describe('FilesTable', () => {
expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument();
});

it('delete button renders correctly', async () => {
appMockRender.render(<FilesTable {...defaultProps} />);

expect(mockedFilesClient.getDownloadHref).toBeCalledTimes(1);
expect(mockedFilesClient.getDownloadHref).toHaveBeenCalledWith({
fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]),
id: basicFileMock.id,
});

expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument();
});

it('clicking delete button opens deletion modal', async () => {
appMockRender.render(<FilesTable {...defaultProps} />);

expect(mockedFilesClient.getDownloadHref).toBeCalledTimes(1);
expect(mockedFilesClient.getDownloadHref).toHaveBeenCalledWith({
fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]),
id: basicFileMock.id,
});

const deleteButton = await screen.findByTestId('cases-files-delete-button');

expect(deleteButton).toBeInTheDocument();

userEvent.click(deleteButton);

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});

it('go to next page calls onTableChange with correct values', async () => {
const mockPagination = { pageIndex: 0, pageSize: 1, totalItemCount: 2 };

Expand Down

0 comments on commit 9009f41

Please sign in to comment.