diff --git a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/helpers/http_requests.ts b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/helpers/http_requests.ts index a9f1dac15ed1f..cd64b428eb1e5 100644 --- a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/helpers/http_requests.ts +++ b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/helpers/http_requests.ts @@ -90,17 +90,8 @@ const registerHttpRequestMockHelpers = ( const setDeleteDataStreamResponse = (response?: HttpResponse, error?: ResponseError) => mockResponse('POST', `${API_BASE_PATH}/delete_data_streams`, response, error); - const setEditDataRetentionResponse = ( - dataStreamId: string, - response?: HttpResponse, - error?: ResponseError - ) => - mockResponse( - 'PUT', - `${API_BASE_PATH}/data_streams/${encodeURIComponent(dataStreamId)}/data_retention`, - response, - error - ); + const setEditDataRetentionResponse = (response?: HttpResponse, error?: ResponseError) => + mockResponse('PUT', `${API_BASE_PATH}/data_streams/data_retention`, response, error); const setDeleteTemplateResponse = (response?: HttpResponse, error?: ResponseError) => mockResponse('POST', `${API_BASE_PATH}/delete_index_templates`, response, error); diff --git a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts index b75d1c507cc7a..ae95b62a55515 100644 --- a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts +++ b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts @@ -38,6 +38,7 @@ export interface DataStreamsTabTestBed extends TestBed { clickEditDataRetentionButton: () => void; clickDetailPanelIndexTemplateLink: () => void; clickManageDataStreamsButton: () => void; + clickBulkDeleteDataStreamsButton: () => void; clickBulkEditDataRetentionButton: () => void; }; findDeleteActionAt: (index: number) => ReactWrapper; @@ -181,14 +182,10 @@ export const setup = async ( }; const clickConfirmDelete = async () => { - const modal = document.body.querySelector('[data-test-subj="deleteDataStreamsConfirmation"]'); - const confirmButton: HTMLButtonElement | null = modal!.querySelector( - '[data-test-subj="confirmModalConfirmButton"]' - ); - await act(async () => { - confirmButton!.click(); + testBed.find('confirmModalConfirmButton').simulate('click'); }); + testBed.component.update(); }; const clickDeleteDataStreamButton = () => { @@ -216,7 +213,13 @@ export const setup = async ( testBed.find('dataStreamActionsPopoverButton').simulate('click'); }; + const clickBulkDeleteDataStreamsButton = () => { + testBed.find('dataStreamActionsPopoverButton').simulate('click'); + testBed.find('deleteDataStreamsButton').simulate('click'); + }; + const clickBulkEditDataRetentionButton = () => { + testBed.find('dataStreamActionsPopoverButton').simulate('click'); testBed.find('bulkEditDataRetentionButton').simulate('click'); }; @@ -269,6 +272,7 @@ export const setup = async ( clickEditDataRetentionButton, clickDetailPanelIndexTemplateLink, clickManageDataStreamsButton, + clickBulkDeleteDataStreamsButton, clickBulkEditDataRetentionButton, }, findDeleteActionAt, diff --git a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.test.ts b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.test.ts index d3368371de336..eea1abf305e28 100644 --- a/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.test.ts +++ b/x-pack/platform/plugins/shared/index_management/__jest__/client_integration/home/data_streams_tab.test.ts @@ -449,9 +449,64 @@ describe('Data Streams tab', () => { }); }); + describe('bulk delete of data streams', () => { + beforeAll(async () => { + const { setLoadDataStreamsResponse } = httpRequestsMockHelpers; + + const ds1 = createDataStreamPayload({ + name: 'dataStream1', + privileges: { delete_index: true, manage_data_stream_lifecycle: true }, + }); + const ds2 = createDataStreamPayload({ + name: 'dataStream2', + privileges: { delete_index: true, manage_data_stream_lifecycle: true }, + }); + + setLoadDataStreamsResponse([ds1, ds2]); + + testBed = await setup(httpSetup, { + history: createMemoryHistory(), + url: urlServiceMock, + }); + await act(async () => { + testBed.actions.goToDataStreamsList(); + }); + testBed.component.update(); + }); + + test('can delete multiple data streams at once', async () => { + const { + actions: { selectDataStream, clickBulkDeleteDataStreamsButton, clickConfirmDelete }, + } = testBed; + + selectDataStream('dataStream1', true); + selectDataStream('dataStream2', true); + + clickBulkDeleteDataStreamsButton(); + + httpRequestsMockHelpers.setDeleteDataStreamResponse({ + results: { + dataStreamsDeleted: ['dataStream1', 'dataStream2'], + errors: [], + }, + }); + + await clickConfirmDelete(); + + testBed.component.update(); + + expect(httpSetup.post).toHaveBeenLastCalledWith( + `${API_BASE_PATH}/delete_data_streams`, + expect.objectContaining({ + body: JSON.stringify({ dataStreams: ['dataStream1', 'dataStream2'] }), + }) + ); + }); + }); + describe('bulk update data retention', () => { beforeAll(async () => { - const { setLoadDataStreamsResponse, setLoadDataStreamResponse } = httpRequestsMockHelpers; + const { setLoadDataStreamsResponse } = httpRequestsMockHelpers; const ds1 = createDataStreamPayload({ name: 'dataStream1', @@ -467,7 +522,6 @@ describe('Data Streams tab', () => { }); setLoadDataStreamsResponse([ds1, ds2]); - setLoadDataStreamResponse(ds1.name, ds1); testBed = await setup(httpSetup, { history: createMemoryHistory(), @@ -481,24 +535,15 @@ describe('Data Streams tab', () => { test('can set data retention period for mutliple data streams', async () => { const { - actions: { - selectDataStream, - clickManageDataStreamsButton, - clickBulkEditDataRetentionButton, - }, + actions: { selectDataStream, clickBulkEditDataRetentionButton }, } = testBed; selectDataStream('dataStream1', true); selectDataStream('dataStream2', true); - clickManageDataStreamsButton(); clickBulkEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { - success: true, - }); - - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream2', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, }); @@ -526,24 +571,15 @@ describe('Data Streams tab', () => { test('can disable lifecycle', async () => { const { - actions: { - selectDataStream, - clickManageDataStreamsButton, - clickBulkEditDataRetentionButton, - }, + actions: { selectDataStream, clickBulkEditDataRetentionButton }, } = testBed; selectDataStream('dataStream1', true); selectDataStream('dataStream2', true); - clickManageDataStreamsButton(); clickBulkEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { - success: true, - }); - - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream2', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, }); @@ -564,24 +600,15 @@ describe('Data Streams tab', () => { test('allows to set infinite retention period', async () => { const { - actions: { - selectDataStream, - clickManageDataStreamsButton, - clickBulkEditDataRetentionButton, - }, + actions: { selectDataStream, clickBulkEditDataRetentionButton }, } = testBed; selectDataStream('dataStream1', true); selectDataStream('dataStream2', true); - clickManageDataStreamsButton(); clickBulkEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { - success: true, - }); - - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream2', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, }); @@ -693,7 +720,7 @@ describe('Data Streams tab', () => { clickEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, }); @@ -725,7 +752,7 @@ describe('Data Streams tab', () => { clickEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, }); @@ -753,7 +780,7 @@ describe('Data Streams tab', () => { clickEditDataRetentionButton(); - httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', { + httpRequestsMockHelpers.setEditDataRetentionResponse({ success: true, });