Skip to content

Commit

Permalink
[8.x] [Security Solution] Fix flaky unified component test elastic#18…
Browse files Browse the repository at this point in the history
…9791 (elastic#195093) (elastic#195238)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Fix flaky unified component test elastic#189791
(elastic#195093)](elastic#195093)

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

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

<!--BACKPORT [{"author":{"name":"Jatin
Kathuria","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-07T12:15:31Z","message":"[Security
Solution] Fix flaky unified component test elastic#189791 (elastic#195093)\n\n##
Summary\r\n\r\nFixes elastic#189791\r\n\r\nPagination test suite was timing out
because huge number of records in\r\ndata grid was rendering in JSDOM
which were creating performance issues.\r\nThis PR fixes that so that
test does not times
out.","sha":"67f2b7cad2df49dbfec4a9603f01fbd6e76f8cb9","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Threat
Hunting:Investigations","backport:prev-minor"],"title":"[Security
Solution] Fix flaky unified component test
elastic#189791","number":195093,"url":"https://github.com/elastic/kibana/pull/195093","mergeCommit":{"message":"[Security
Solution] Fix flaky unified component test elastic#189791 (elastic#195093)\n\n##
Summary\r\n\r\nFixes elastic#189791\r\n\r\nPagination test suite was timing out
because huge number of records in\r\ndata grid was rendering in JSDOM
which were creating performance issues.\r\nThis PR fixes that so that
test does not times
out.","sha":"67f2b7cad2df49dbfec4a9603f01fbd6e76f8cb9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195093","number":195093,"mergeCommit":{"message":"[Security
Solution] Fix flaky unified component test elastic#189791 (elastic#195093)\n\n##
Summary\r\n\r\nFixes elastic#189791\r\n\r\nPagination test suite was timing out
because huge number of records in\r\ndata grid was rendering in JSDOM
which were creating performance issues.\r\nThis PR fixes that so that
test does not times
out.","sha":"67f2b7cad2df49dbfec4a9603f01fbd6e76f8cb9"}}]}] BACKPORT-->

Co-authored-by: Jatin Kathuria <[email protected]>
  • Loading branch information
kibanamachine and logeekal authored Oct 7, 2024
1 parent c5fe95f commit 07a0d97
Showing 1 changed file with 84 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,27 @@ describe('query tab with unified timeline', () => {
);
});

// FLAKY: https://github.com/elastic/kibana/issues/189791
describe.skip('pagination', () => {
describe('pagination', () => {
beforeEach(() => {
// should return all the records instead just 3
// as the case in the default mock
// pagination tests need more than 1 record so here
// we return 5 records instead of just 1.
useTimelineEventsMock = jest.fn(() => [
false,
{
events: structuredClone(mockTimelineData),
events: structuredClone(mockTimelineData.slice(0, 5)),
pageInfo: {
activePage: 0,
totalPages: 10,
totalPages: 5,
},
refreshedAt: Date.now(),
totalCount: 70,
/*
* `totalCount` could be any number w.r.t this test
* and actually means total hits on elastic search
* and not the fecthed number of records.
*
* This helps in testing `sampleSize` and `loadMore`
*/
totalCount: 50,
loadPage: loadPageMock,
},
]);
Expand All @@ -326,21 +332,48 @@ describe('query tab with unified timeline', () => {
it(
'should paginate correctly',
async () => {
renderTestComponents();
const mockStateWithNoteInTimeline = {
...mockGlobalState,
timeline: {
...mockGlobalState.timeline,
timelineById: {
[TimelineId.test]: {
...mockGlobalState.timeline.timelineById[TimelineId.test],
/* 1 record for each page */
itemsPerPage: 1,
itemsPerPageOptions: [1, 2, 3, 4, 5],
savedObjectId: 'timeline-1', // match timelineId in mocked notes data
pinnedEventIds: { '1': true },
},
},
},
};

await waitFor(() => {
expect(screen.getByTestId('tablePaginationPopoverButton')).toHaveTextContent(
'Rows per page: 5'
);
});
render(
<TestProviders
store={createMockStore({
...structuredClone(mockStateWithNoteInTimeline),
})}
>
<TestComponent />
</TestProviders>
);

expect(await screen.findByTestId('discoverDocTable')).toBeVisible();
expect(screen.getByTestId('pagination-button-previous')).toBeVisible();

expect(screen.getByTestId('tablePaginationPopoverButton')).toHaveTextContent(
'Rows per page: 1'
);

expect(screen.getByTestId('pagination-button-0')).toHaveAttribute('aria-current', 'true');
expect(screen.getByTestId('pagination-button-6')).toBeVisible();
expect(screen.getByTestId('pagination-button-4')).toBeVisible();
expect(screen.queryByTestId('pagination-button-5')).toBeNull();

fireEvent.click(screen.getByTestId('pagination-button-6'));
fireEvent.click(screen.getByTestId('pagination-button-4'));

await waitFor(() => {
expect(screen.getByTestId('pagination-button-6')).toHaveAttribute('aria-current', 'true');
expect(screen.getByTestId('pagination-button-4')).toHaveAttribute('aria-current', 'true');
});
},
SPECIAL_TEST_TIMEOUT
Expand All @@ -349,13 +382,45 @@ describe('query tab with unified timeline', () => {
it(
'should load more records according to sample size correctly',
async () => {
renderTestComponents();
const mockStateWithNoteInTimeline = {
...mockGlobalState,
timeline: {
...mockGlobalState.timeline,
timelineById: {
[TimelineId.test]: {
...mockGlobalState.timeline.timelineById[TimelineId.test],
itemsPerPage: 1,
/*
* `sampleSize` is the max number of records that are fetched from elasticsearch
* in one request. If hits > sampleSize, you can fetch more records ( <= sampleSize)
*/
sampleSize: 5,
itemsPerPageOptions: [1, 2, 3, 4, 5],
savedObjectId: 'timeline-1', // match timelineId in mocked notes data
pinnedEventIds: { '1': true },
},
},
},
};

render(
<TestProviders
store={createMockStore({
...structuredClone(mockStateWithNoteInTimeline),
})}
>
<TestComponent />
</TestProviders>
);

expect(await screen.findByTestId('discoverDocTable')).toBeVisible();

await waitFor(() => {
expect(screen.getByTestId('pagination-button-0')).toHaveAttribute('aria-current', 'true');
expect(screen.getByTestId('pagination-button-6')).toBeVisible();
expect(screen.getByTestId('pagination-button-4')).toBeVisible();
});
// Go to last page
fireEvent.click(screen.getByTestId('pagination-button-6'));
fireEvent.click(screen.getByTestId('pagination-button-4'));
await waitFor(() => {
expect(screen.getByTestId('dscGridSampleSizeFetchMoreLink')).toBeVisible();
});
Expand Down

0 comments on commit 07a0d97

Please sign in to comment.