From 55b9c01539f9aeb634b1574d6c5ba27f63dfccc4 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Fri, 3 Nov 2023 18:45:18 +0200 Subject: [PATCH] [Cases] Fix FilesTable flaky test (#170504) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../components/files/files_table.test.tsx | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/cases/public/components/files/files_table.test.tsx b/x-pack/plugins/cases/public/components/files/files_table.test.tsx index 651f86e76b462..fdab9615ea11d 100644 --- a/x-pack/plugins/cases/public/components/files/files_table.test.tsx +++ b/x-pack/plugins/cases/public/components/files/files_table.test.tsx @@ -90,7 +90,7 @@ describe('FilesTable', () => { ) ); - expect(await screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); + expect(screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); }); it('image rows open file preview', async () => { @@ -132,10 +132,15 @@ describe('FilesTable', () => { it('download button renders correctly', async () => { appMockRender.render(); - expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - id: basicFileMock.id, + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); + }); + + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + id: basicFileMock.id, + }); }); expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument(); @@ -144,10 +149,15 @@ describe('FilesTable', () => { it('delete button renders correctly', async () => { appMockRender.render(); - expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - id: basicFileMock.id, + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); + }); + + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + id: basicFileMock.id, + }); }); expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); @@ -156,10 +166,15 @@ describe('FilesTable', () => { it('clicking delete button opens deletion modal', async () => { appMockRender.render(); - expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - id: basicFileMock.id, + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toBeCalledTimes(1); + }); + + await waitFor(() => { + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + id: basicFileMock.id, + }); }); const deleteButton = await screen.findByTestId('cases-files-delete-button'); @@ -216,9 +231,9 @@ describe('FilesTable', () => { ); - userEvent.click(screen.getByTestId('tablePaginationPopoverButton')); + userEvent.click(await screen.findByTestId('tablePaginationPopoverButton')); - const pageSizeOption = screen.getByTestId('tablePagination-50-rows'); + const pageSizeOption = await screen.findByTestId('tablePagination-50-rows'); pageSizeOption.style.pointerEvents = 'all';