Skip to content

Commit

Permalink
[8.x] [Data Streams] Improve jest tests for bulk actions (#204938) (#…
Browse files Browse the repository at this point in the history
…206008)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Data Streams] Improve jest tests for bulk actions
(#204938)](#204938)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-09T10:03:14Z","message":"[Data
Streams] Improve jest tests for bulk actions (#204938)\n\nFollow-up to
https://github.com/elastic/kibana/pull/203083\r\n\r\n##
Summary\r\n\r\nThis PR improves the jest tests for bulk actions in data
streams.","sha":"542da4a773eb638bf87946898cf00c32c916cad3","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Index
Management","Team:Kibana
Management","release_note:skip","v9.0.0","backport:prev-minor","v8.18.0"],"title":"[Data
Streams] Improve jest tests for bulk
actions","number":204938,"url":"https://github.com/elastic/kibana/pull/204938","mergeCommit":{"message":"[Data
Streams] Improve jest tests for bulk actions (#204938)\n\nFollow-up to
https://github.com/elastic/kibana/pull/203083\r\n\r\n##
Summary\r\n\r\nThis PR improves the jest tests for bulk actions in data
streams.","sha":"542da4a773eb638bf87946898cf00c32c916cad3"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204938","number":204938,"mergeCommit":{"message":"[Data
Streams] Improve jest tests for bulk actions (#204938)\n\nFollow-up to
https://github.com/elastic/kibana/pull/203083\r\n\r\n##
Summary\r\n\r\nThis PR improves the jest tests for bulk actions in data
streams.","sha":"542da4a773eb638bf87946898cf00c32c916cad3"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
  • Loading branch information
kibanamachine and ElenaStoeva authored Jan 9, 2025
1 parent 6c9f9c3 commit 62a443b
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 62a443b

Please sign in to comment.