Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Fixed flaky Jest config: x-pack/plugins/security_solution/public/timelines #143824

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
57b7043
[Security Solution] Fixed flaky Jest config: x-pack/plugins/security_…
YulNaumenko Oct 22, 2022
f28b2b2
Improved Ids
YulNaumenko Oct 23, 2022
3cef80d
-
YulNaumenko Oct 23, 2022
330ed86
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 23, 2022
d003a51
Fixed test files and lazy suricata
YulNaumenko Oct 23, 2022
9935744
Merge remote-tracking branch 'origin/security-solution-fix-skipped-te…
YulNaumenko Oct 23, 2022
babe56f
Cleaned up act error for async stuff
YulNaumenko Oct 23, 2022
2b3a068
-
YulNaumenko Oct 23, 2022
e70260d
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 24, 2022
e90f0e0
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 24, 2022
c626f5b
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 24, 2022
3b2c01f
Cleaning up jest errors for timeline components
YulNaumenko Oct 24, 2022
d4d62d5
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 24, 2022
d1c816d
-
YulNaumenko Oct 25, 2022
69b917e
Merge remote-tracking branch 'origin/security-solution-fix-skipped-te…
YulNaumenko Oct 25, 2022
1486a17
Used mount enzyme
YulNaumenko Oct 25, 2022
d93122f
mocked react-beautiful-dnd
YulNaumenko Oct 25, 2022
b9a68bd
type check
YulNaumenko Oct 25, 2022
79e2d64
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 25, 2022
5930a58
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 25, 2022
e2519cb
Fixed snapshot
YulNaumenko Oct 25, 2022
cb392a8
mocked one more expensive lib
YulNaumenko Oct 25, 2022
667b121
Reduced the number of data rows to 1 to simplify rendering
YulNaumenko Oct 25, 2022
c6acd07
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 25, 2022
d269649
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 25, 2022
d11f5a6
Merge branch 'main' into security-solution-fix-skipped-test-143718
YulNaumenko Oct 25, 2022
115d5d5
Merge branch 'main' into security-solution-fix-skipped-test-143718
kibanamachine Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
} from './helpers';
import { SourcererScopeName } from '../../store/sourcerer/model';

/** the following `TimelineId`s are detection alert tables */
const detectionAlertsTimelines = [TableId.alertsOnAlertsPage, TableId.alertsOnRuleDetailsPage];
/** the following scopes are detection alert tables */
const detectionAlertsTables = [TableId.alertsOnAlertsPage, TableId.alertsOnRuleDetailsPage];

/** the following `TimelineId`s are NOT detection alert tables */
const otherTimelines = [
/** the following scopes are NOT detection alert tables */
const otherScopes = [
TableId.hostsPageEvents,
TableId.hostsPageSessions,
TableId.networkPageEvents,
Expand All @@ -36,7 +36,7 @@ const otherTimelines = [
TableId.kubernetesPageSessions,
];

const othersWithoutActive = otherTimelines.filter((x) => x !== TimelineId.active);
const othersWithoutActive = otherScopes.filter((x) => x !== TimelineId.active);

const hostNameFilter: Filter = {
meta: {
Expand Down Expand Up @@ -169,21 +169,21 @@ describe('getOptions', () => {
});

describe('isDetectionsAlertsTable', () => {
detectionAlertsTimelines.forEach((tableId) =>
detectionAlertsTables.forEach((tableId) =>
test(`it returns true for detections alerts table '${tableId}'`, () => {
expect(isDetectionsAlertsTable(tableId)).toEqual(true);
})
);

otherTimelines.forEach((tableId) =>
otherScopes.forEach((tableId) =>
test(`it returns false for (NON alert table) timeline '${tableId}'`, () => {
expect(isDetectionsAlertsTable(tableId)).toEqual(false);
})
);
});

describe('shouldIgnoreAlertFilters', () => {
detectionAlertsTimelines.forEach((tableId) => {
detectionAlertsTables.forEach((tableId) => {
test(`it returns true when the view is 'raw' for detections alerts table '${tableId}'`, () => {
const view = 'raw';
expect(shouldIgnoreAlertFilters({ tableId, view })).toEqual(true);
Expand All @@ -195,7 +195,7 @@ describe('shouldIgnoreAlertFilters', () => {
});
});

otherTimelines.forEach((tableId) => {
otherScopes.forEach((tableId) => {
test(`it returns false when the view is 'raw' for (NON alert table) timeline'${tableId}'`, () => {
const view = 'raw';
expect(shouldIgnoreAlertFilters({ tableId, view })).toEqual(false);
Expand All @@ -209,7 +209,7 @@ describe('shouldIgnoreAlertFilters', () => {
});

describe('removeIgnoredAlertFilters', () => {
detectionAlertsTimelines.forEach((tableId) => {
detectionAlertsTables.forEach((tableId) => {
test(`it removes the ignored alert filters when the view is 'raw' for detections alerts table '${tableId}'`, () => {
const view = 'raw';
expect(removeIgnoredAlertFilters({ filters: allFilters, tableId, view })).toEqual([
Expand All @@ -223,7 +223,7 @@ describe('removeIgnoredAlertFilters', () => {
});
});

otherTimelines.forEach((tableId) => {
otherScopes.forEach((tableId) => {
test(`it does NOT remove any filters when the view is 'raw' for (NON alert table) '${tableId}'`, () => {
const view = 'alert';
expect(removeIgnoredAlertFilters({ filters: allFilters, tableId, view })).toEqual(allFilters);
Expand All @@ -237,7 +237,7 @@ describe('removeIgnoredAlertFilters', () => {
});

describe('getSourcererScopeName', () => {
detectionAlertsTimelines.forEach((tableId) => {
detectionAlertsTables.forEach((tableId) => {
test(`it returns the 'default' SourcererScopeName when the view is 'raw' for detections alerts table '${tableId}'`, () => {
const view = 'raw';
expect(getSourcererScopeName({ scopeId: tableId, view })).toEqual(SourcererScopeName.default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,26 @@ export const mockGlobalState: State = {
start: '2020-07-07T08:20:18.966Z',
end: '2020-07-08T08:20:18.966Z',
},
sessionViewConfig: null,
show: false,
resolveTimelineConfig: undefined,
pinnedEventIds: {},
pinnedEventsSaveObject: {},
itemsPerPageOptions: [5, 10, 20],
sessionViewConfig: null,
show: false,
sort: [
{
columnId: '@timestamp',
columnType: 'date',
esTypes: ['date'],
sortDirection: Direction.desc,
sortDirection: 'desc',
},
],
isSaving: false,
status: TimelineStatus.draft,
version: null,
status: TimelineStatus.active,
isSelectAllChecked: false,
selectedEventIds: {},
isSelectAllChecked: false,
filters: [],
isSaving: false,
itemsPerPageOptions: [10, 25, 50, 100],
},
},
insertTimeline: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import React from 'react';

import { TestProviders } from '../../../../common/mock';
Expand All @@ -15,6 +15,15 @@ import { useGetUserCasesPermissions } from '../../../../common/lib/kibana';

jest.mock('../../../../common/lib/kibana');
const originalKibanaLib = jest.requireActual('../../../../common/lib/kibana');
jest.mock('@kbn/i18n-react', () => {
const originalModule = jest.requireActual('@kbn/i18n-react');
const FormattedRelative = jest.fn().mockImplementation(() => '20 hours ago');

return {
...originalModule,
FormattedRelative,
};
});

// Restore the useGetUserCasesPermissions so the calling functions can receive a valid permissions object
// The returned permissions object will indicate that the user does not have permissions by default
Expand All @@ -30,21 +39,25 @@ jest.mock('../../../../common/hooks/use_resolve_conflict', () => {
});

describe('Pane', () => {
test('renders with display block by default', () => {
test('renders with display block by default', async () => {
const EmptyComponent = render(
<TestProviders>
<Pane timelineId={TimelineId.test} />
</TestProviders>
);
expect(EmptyComponent.getByTestId('flyout-pane')).toHaveStyle('display: block');
await waitFor(() => {
expect(EmptyComponent.getByTestId('flyout-pane')).toHaveStyle('display: block');
});
});

test('renders with display none when visibility is set to false', () => {
test('renders with display none when visibility is set to false', async () => {
const EmptyComponent = render(
<TestProviders>
<Pane timelineId={TimelineId.test} visible={false} />
</TestProviders>
);
expect(EmptyComponent.getByTestId('flyout-pane')).toHaveStyle('display: none');
await waitFor(() => {
expect(EmptyComponent.getByTestId('flyout-pane')).toHaveStyle('display: none');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
ColumnHeaderOptions,
HeaderActionProps,
} from '../../../../../../common/types/timeline';
import { TimelineTabs } from '../../../../../../common/types/timeline';
import { TimelineId, TimelineTabs } from '../../../../../../common/types/timeline';
import { timelineActions } from '../../../../store/timeline';
import { getColumnHeader } from '../column_headers/helpers';

Expand All @@ -35,7 +35,7 @@ jest.mock('../../../../../common/hooks/use_selector', () => ({
}));

const columnId = 'test-field';
const timelineId = 'test-timeline';
const timelineId = TimelineId.test;

/* eslint-disable jsx-a11y/click-events-have-key-events */
mockTriggersActionsUi.getFieldBrowser.mockImplementation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { mount } from 'enzyme';
import React from 'react';
import { TableId } from '../../../../../../common/types/timeline';
import { TableId, TimelineId } from '../../../../../../common/types/timeline';
import { TestProviders, mockTimelineModel, mockTimelineData } from '../../../../../common/mock';
import { Actions, isAlert } from '.';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
Expand Down Expand Up @@ -97,7 +97,7 @@ const defaultProps = {
setEventsLoading: () => {},
showCheckboxes: true,
showNotes: false,
timelineId: 'test',
timelineId: TimelineId.test,
toggleShowNotes: () => {},
};

Expand Down Expand Up @@ -271,7 +271,7 @@ describe('Actions', () => {
<Actions
{...defaultProps}
ecsData={ecsData}
timelineId={TableId.kubernetesPageSessions}
timelineId={TableId.kubernetesPageSessions} // not a bug, this needs to be fixed by providing a generic interface for actions registry
/>
</TestProviders>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { HeaderComponent } from '.';
import { getNewSortDirectionOnClick, getNextSortDirection, getSortDirection } from './helpers';
import { Direction } from '../../../../../../../common/search_strategy';
import { useDeepEqualSelector } from '../../../../../../common/hooks/use_selector';
import { TimelineId } from '../../../../../../../common/types';

const mockDispatch = jest.fn();
jest.mock('react-redux', () => {
Expand Down Expand Up @@ -48,7 +49,7 @@ describe('Header', () => {
sortDirection: Direction.desc,
},
];
const timelineId = 'test';
const timelineId = TimelineId.test;

beforeEach(() => {
(useDeepEqualSelector as jest.Mock).mockReturnValue({ isLoading: false });
Expand Down
Loading