Skip to content

Commit ec04e41

Browse files
lgestckibanamachinePhilippeOberti
authored
[Security Solution][Data View Picker] Fix test suites (#227422)
## Summary This PR ~~enables the new [picker](elastic/security-team#11959) by default~~ fixes tests that w ill be affected by the new picker, deprecating some of them and updating default mocks in some of the suites to always include a mocked version of `useDataView`. individual tests may still override the mock. There will be a follow up with default enable experimental feature flag. ## Testing You tell me what is not working:). Its just fixing tests. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: PhilippeOberti <[email protected]>
1 parent 03fad3f commit ec04e41

File tree

129 files changed

+1488
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1488
-424
lines changed

x-pack/platform/plugins/shared/osquery/cypress/e2e/all/timelines.cy.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,8 @@ describe('ALL - Timelines', { tags: ['@ess'] }, () => {
2828
cy.getBySel('timeline-bottom-bar-title-button').click();
2929
});
3030
cy.getBySel('timelineQueryInput').type(
31-
'NOT host.name: "dev-fleet-server*" and component.type: "osquery"{enter}'
31+
'NOT host.name: "dev-fleet-server*" and component.type: "osquery" AND (_index: "logs-*" OR _index: "filebeat-*"){enter}'
3232
);
33-
// Filter out alerts
34-
cy.getBySel('timeline-sourcerer-trigger').click();
35-
cy.getBySel('sourcerer-advanced-options-toggle').click();
36-
cy.getBySel('sourcerer-combo-box').within(() => {
37-
cy.getBySel('comboBoxClearButton').click();
38-
cy.getBySel('comboBoxInput').type(
39-
'logs-*{downArrow}{enter}filebeat-*{downArrow}{enter}{esc}'
40-
);
41-
});
42-
cy.getBySel('sourcerer-save').click();
4333

4434
// Force true due to pointer-events: none on parent prevents user mouse interaction.
4535
cy.getBySel('docTableExpandToggleColumn').first().click({ force: true });

x-pack/solutions/security/plugins/security_solution/public/app/components/top_values_popover/top_values_popover.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jest.mock('react-router-dom', () => {
1818
useLocation: jest.fn().mockReturnValue({ pathname: '/test' }),
1919
};
2020
});
21+
jest.mock('../../../data_view_manager/hooks/use_data_view');
2122

2223
const element = document.createElement('button');
2324
document.body.appendChild(element);

x-pack/solutions/security/plugins/security_solution/public/app/home/global_header/index.test.tsx

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,21 @@ import {
1414
SECURITY_FEATURE_ID,
1515
THREAT_INTELLIGENCE_PATH,
1616
} from '../../../../common/constants';
17-
import {
18-
createMockStore,
19-
mockGlobalState,
20-
mockIndexPattern,
21-
TestProviders,
22-
} from '../../../common/mock';
17+
import { createMockStore, mockGlobalState, TestProviders } from '../../../common/mock';
2318
import { TimelineId } from '../../../../common/types/timeline';
2419
import { sourcererPaths } from '../../../sourcerer/containers/sourcerer_paths';
2520

26-
import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features';
2721
import { DATA_VIEW_PICKER_TEST_ID } from '../../../data_view_manager/components/data_view_picker/constants';
2822
import { useKibana as mockUseKibana } from '../../../common/lib/kibana/__mocks__';
2923
import { useKibana } from '../../../common/lib/kibana';
3024

31-
jest.mock('../../../common/hooks/use_experimental_features');
32-
3325
jest.mock('react-router-dom', () => {
3426
const actual = jest.requireActual('react-router-dom');
3527
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) };
3628
});
3729

3830
jest.mock('../../../common/lib/kibana');
3931

40-
jest.mock('../../../common/containers/source', () => ({
41-
useFetchIndex: () => [false, { indicesExist: true, indexPatterns: mockIndexPattern }],
42-
}));
43-
44-
jest.mock('../../../sourcerer/containers/use_signal_helpers', () => ({
45-
useSignalHelpers: () => ({ signalIndexNeedsInit: false }),
46-
}));
47-
4832
jest.mock('react-reverse-portal', () => ({
4933
InPortal: ({ children }: { children: React.ReactNode }) => <>{children}</>,
5034
OutPortal: ({ children }: { children: React.ReactNode }) => <>{children}</>,
@@ -133,29 +117,31 @@ describe('global header', () => {
133117
expect(link?.getAttribute('href')).toBe(ADD_THREAT_INTELLIGENCE_DATA_PATH);
134118
});
135119

136-
it.each(sourcererPaths)('shows sourcerer on %s page', (pathname) => {
137-
(useLocation as jest.Mock).mockReturnValue({ pathname });
138-
139-
const { getByTestId } = render(
140-
<TestProviders store={store}>
141-
<GlobalHeader />
142-
</TestProviders>
143-
);
144-
expect(getByTestId('sourcerer-trigger')).toBeInTheDocument();
145-
});
146-
147-
it('shows sourcerer on rule details page', () => {
120+
// TODO: Skipping until feature flag is enabled https://github.com/elastic/security-team/issues/11959 by default
121+
// it.each(sourcererPaths)('shows data view manager on %s page', (pathname) => {
122+
// (useLocation as jest.Mock).mockReturnValue({ pathname });
123+
//
124+
// const { getByTestId } = render(
125+
// <TestProviders store={store}>
126+
// <GlobalHeader />
127+
// </TestProviders>
128+
// );
129+
// expect(getByTestId(DATA_VIEW_PICKER_TEST_ID)).toBeInTheDocument();
130+
// });
131+
132+
// TODO: Skipping until feature flag is enabled https://github.com/elastic/security-team/issues/11959 by default
133+
it.skip('shows data view manager on rule details page', () => {
148134
(useLocation as jest.Mock).mockReturnValue({ pathname: sourcererPaths[2] });
149135

150136
const { getByTestId } = render(
151137
<TestProviders store={store}>
152138
<GlobalHeader />
153139
</TestProviders>
154140
);
155-
expect(getByTestId('sourcerer-trigger')).toBeInTheDocument();
141+
expect(getByTestId(DATA_VIEW_PICKER_TEST_ID)).toBeInTheDocument();
156142
});
157143

158-
it('shows no sourcerer if timeline is open', () => {
144+
it('shows no data view manager if timeline is open', () => {
159145
const mockstate = {
160146
...mockGlobalState,
161147
timeline: {
@@ -178,7 +164,7 @@ describe('global header', () => {
178164
</TestProviders>
179165
);
180166

181-
expect(queryByTestId('sourcerer-trigger')).not.toBeInTheDocument();
167+
expect(queryByTestId(DATA_VIEW_PICKER_TEST_ID)).not.toBeInTheDocument();
182168
});
183169

184170
it('shows AI Assistant header link', () => {
@@ -190,22 +176,4 @@ describe('global header', () => {
190176

191177
waitFor(() => expect(findByTestId('assistantNavLink')).toBeInTheDocument());
192178
});
193-
194-
describe('when new data view picker is enabled', () => {
195-
beforeEach(() => {
196-
// Mocking location to be alerts page
197-
(useLocation as jest.Mock).mockReturnValue({ pathname: sourcererPaths[0] });
198-
jest.mocked(useIsExperimentalFeatureEnabled).mockReturnValue(true);
199-
});
200-
201-
it('should render it instead of sourcerer', () => {
202-
const { queryByTestId } = render(
203-
<TestProviders store={store}>
204-
<GlobalHeader />
205-
</TestProviders>
206-
);
207-
expect(queryByTestId('sourcerer-trigger')).not.toBeInTheDocument();
208-
expect(queryByTestId(DATA_VIEW_PICKER_TEST_ID)).toBeInTheDocument();
209-
});
210-
});
211179
});

x-pack/solutions/security/plugins/security_solution/public/attack_discovery/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ module.exports = {
1515
collectCoverageFrom: [
1616
'<rootDir>/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/**/*.{ts,tsx}',
1717
],
18+
setupFilesAfterEnv: [
19+
'<rootDir>/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/test/setup.ts',
20+
],
1821
moduleNameMapper: require('../../server/__mocks__/module_name_map'),
1922
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
jest.mock('../../data_view_manager/hooks/use_data_view');

x-pack/solutions/security/plugins/security_solution/public/common/components/drag_and_drop/__snapshots__/drag_drop_context_wrapper.test.tsx.snap

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/solutions/security/plugins/security_solution/public/common/components/inspect/modal.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ModalInspectProps } from './modal';
1313
import { ModalInspectQuery, formatIndexPatternRequested } from './modal';
1414
import { InputsModelId } from '../../store/inputs/constants';
1515
import { fireEvent, render, screen } from '@testing-library/react';
16+
import { useDataView } from '../../../data_view_manager/hooks/use_data_view';
17+
import { withIndices } from '../../../data_view_manager/hooks/__mocks__/use_data_view';
1618

1719
jest.mock('react-router-dom', () => {
1820
const original = jest.requireActual('react-router-dom');
@@ -23,9 +25,9 @@ jest.mock('react-router-dom', () => {
2325
};
2426
});
2527

26-
const getRequest = (
27-
indices: string[] = ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*']
28-
) =>
28+
const defaultIndices = ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];
29+
30+
const getRequest = (indices: string[] = defaultIndices) =>
2931
`{"index": ${JSON.stringify(
3032
indices
3133
)},"allowNoIndices": true, "ignoreUnavailable": true, "body": { "aggregations": {"hosts": {"cardinality": {"field": "host.name" } }, "hosts_histogram": {"auto_date_histogram": {"field": "@timestamp","buckets": "6"},"aggs": { "count": {"cardinality": {"field": "host.name" }}}}}, "query": {"bool": {"filter": [{"range": { "@timestamp": {"gte": 1562290224506,"lte": 1562376624506 }}}]}}, "size": 0, "track_total_hits": false}}`;
@@ -244,6 +246,8 @@ describe('Modal Inspect', () => {
244246

245247
describe('index pattern messaging', () => {
246248
test('should show no messaging when all patterns match sourcerer selection', () => {
249+
jest.mocked(useDataView).mockReturnValue(withIndices(defaultIndices));
250+
247251
renderModal();
248252

249253
expect(screen.queryByTestId('not-sourcerer-msg')).toBeNull();

x-pack/solutions/security/plugins/security_solution/public/common/components/search_bar/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { useDataView } from '../../../data_view_manager/hooks/use_data_view';
4848
interface SiemSearchBarProps {
4949
id: InputsModelId.global | InputsModelId.timeline;
5050
pollForSignalIndex?: () => void;
51-
sourcererDataView: DataViewSpec | undefined;
51+
sourcererDataView: DataViewSpec | DataView | undefined; // TODO remove DataViewSpec type when we remove the newDataViewPickerEnabled feature flag
5252
timelineId?: string;
5353
dataTestSubj?: string;
5454
hideFilterBar?: boolean;
@@ -315,6 +315,10 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
315315
}
316316

317317
if (sourcererDataView != null) {
318+
if (sourcererDataView instanceof DataView) {
319+
return [sourcererDataView];
320+
}
321+
318322
return [new DataView({ spec: sourcererDataView, fieldFormats })];
319323
} else {
320324
return null;

x-pack/solutions/security/plugins/security_solution/public/common/components/tables/helpers.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ describe('Table Helpers', () => {
8484
test('it returns 2 items then overflows when displayCount is 2', () => {
8585
const rowItems = getRowItemsWithActions({
8686
values: items,
87-
fieldName: 'attrName',
87+
fieldName: 'user.name',
8888
idPrefix: 'idPrefix',
8989
displayCount: 2,
9090
});
9191
const { queryAllByTestId, queryByTestId } = render(<TestProviders>{rowItems}</TestProviders>);
92-
expect(queryAllByTestId('cellActions-renderContent-attrName').length).toBe(2);
92+
expect(queryAllByTestId('cellActions-renderContent-user.name').length).toBe(2);
9393
expect(queryByTestId('overflow-button')).toBeInTheDocument();
9494
});
9595
});

x-pack/solutions/security/plugins/security_solution/public/common/components/visualization_actions/lens_attributes/common/alerts/alerts_by_status_donut.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { mockExtraFilter, wrapper } from '../../../mocks';
1111
import { useLensAttributes } from '../../../use_lens_attributes';
1212

1313
import { getAlertsByStatusAttributes } from './alerts_by_status_donut';
14+
import { useDataView } from '../../../../../../data_view_manager/hooks/use_data_view';
15+
import { withIndices } from '../../../../../../data_view_manager/hooks/__mocks__/use_data_view';
1416

1517
jest.mock('uuid', () => ({
1618
v4: jest.fn().mockReturnValue('generated-uuid'),
@@ -34,6 +36,12 @@ jest.mock('../../../../../utils/route/use_route_spy', () => ({
3436
}));
3537

3638
describe('getAlertsByStatusAttributes', () => {
39+
beforeAll(() => {
40+
jest
41+
.mocked(useDataView)
42+
.mockReturnValue(withIndices(['signal-index'], 'security-solution-my-test'));
43+
});
44+
3745
it('should render without extra options', () => {
3846
const { result } = renderHook(
3947
() =>

0 commit comments

Comments
 (0)