Skip to content

Commit

Permalink
[Data Streams] Improve jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva committed Dec 19, 2024
1 parent f72b63f commit 568a893
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 21 deletions.
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 @@ -216,7 +217,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 +276,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,16 +535,11 @@ 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();

Expand Down Expand Up @@ -526,16 +575,11 @@ 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();

Expand Down Expand Up @@ -564,16 +608,11 @@ 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();

Expand Down Expand Up @@ -1250,4 +1289,4 @@ describe('Data Streams tab', () => {
});
});
});
});
});

0 comments on commit 568a893

Please sign in to comment.