Skip to content

Commit

Permalink
[Data Streams] Improve jest tests for bulk actions (elastic#204938)
Browse files Browse the repository at this point in the history
Follow-up to elastic#203083

## Summary

This PR improves the jest tests for bulk actions in data streams.
  • Loading branch information
ElenaStoeva authored Jan 9, 2025
1 parent 74da51f commit 542da4a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
clickEditDataRetentionButton: () => void;
clickDetailPanelIndexTemplateLink: () => void;
clickManageDataStreamsButton: () => void;
clickBulkDeleteDataStreamsButton: () => void;
clickBulkEditDataRetentionButton: () => void;
};
findDeleteActionAt: (index: number) => ReactWrapper;
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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');
};

Expand Down Expand Up @@ -269,6 +272,7 @@ export const setup = async (
clickEditDataRetentionButton,
clickDetailPanelIndexTemplateLink,
clickManageDataStreamsButton,
clickBulkDeleteDataStreamsButton,
clickBulkEditDataRetentionButton,
},
findDeleteActionAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -467,7 +522,6 @@ describe('Data Streams tab', () => {
});

setLoadDataStreamsResponse([ds1, ds2]);
setLoadDataStreamResponse(ds1.name, ds1);

testBed = await setup(httpSetup, {
history: createMemoryHistory(),
Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -693,7 +720,7 @@ describe('Data Streams tab', () => {

clickEditDataRetentionButton();

httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', {
httpRequestsMockHelpers.setEditDataRetentionResponse({
success: true,
});

Expand Down Expand Up @@ -725,7 +752,7 @@ describe('Data Streams tab', () => {

clickEditDataRetentionButton();

httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', {
httpRequestsMockHelpers.setEditDataRetentionResponse({
success: true,
});

Expand Down Expand Up @@ -753,7 +780,7 @@ describe('Data Streams tab', () => {

clickEditDataRetentionButton();

httpRequestsMockHelpers.setEditDataRetentionResponse('dataStream1', {
httpRequestsMockHelpers.setEditDataRetentionResponse({
success: true,
});

Expand Down

0 comments on commit 542da4a

Please sign in to comment.