Skip to content

Commit

Permalink
[Security Solution] Clearing up all jest errors and warnings (#91740) (
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored Feb 19, 2021
1 parent b24efee commit 24a1ef0
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
*/

import {
EuiMarkdownEditorUiPlugin,
getDefaultEuiMarkdownParsingPlugins,
getDefaultEuiMarkdownProcessingPlugins,
getDefaultEuiMarkdownUiPlugins,
} from '@elastic/eui';

import * as timelineMarkdownPlugin from './timeline';

export const uiPlugins = [timelineMarkdownPlugin.plugin];
const uiPlugins: EuiMarkdownEditorUiPlugin[] = getDefaultEuiMarkdownUiPlugins();
uiPlugins.push(timelineMarkdownPlugin.plugin);
export { uiPlugins };
export const parsingPlugins = getDefaultEuiMarkdownParsingPlugins();
export const processingPlugins = getDefaultEuiMarkdownProcessingPlugins();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ describe('QueryBar ', () => {
await waitFor(() => getByTestId('queryInput')); // check for presence of query input
return mount(Component);
};
let abortSpy: jest.SpyInstance;
beforeAll(() => {
const mockAbort = new AbortController();
mockAbort.abort();
abortSpy = jest.spyOn(window, 'AbortController').mockImplementation(() => mockAbort);
});

afterAll(() => {
abortSpy.mockRestore();
});
beforeEach(() => {
mockOnChangeQuery.mockClear();
mockOnSubmitQuery.mockClear();
Expand Down Expand Up @@ -264,7 +273,6 @@ describe('QueryBar ', () => {
const onChangedQueryRef = searchBarProps.onQueryChange;
const onSubmitQueryRef = searchBarProps.onQuerySubmit;
const onSavedQueryRef = searchBarProps.onSavedQueryUpdated;

wrapper.setProps({ onSavedQuery: jest.fn() });
wrapper.update();

Expand Down Expand Up @@ -294,22 +302,21 @@ describe('QueryBar ', () => {
onSavedQuery={mockOnSavedQuery}
/>
);
await waitFor(() => {
const isSavedQueryPopoverOpen = () =>
wrapper.find('EuiPopover[id="savedQueryPopover"]').prop('isOpen');
const isSavedQueryPopoverOpen = () =>
wrapper.find('EuiPopover[id="savedQueryPopover"]').prop('isOpen');

expect(isSavedQueryPopoverOpen()).toBeFalsy();
expect(isSavedQueryPopoverOpen()).toBeFalsy();

wrapper
.find('button[data-test-subj="saved-query-management-popover-button"]')
.simulate('click');
wrapper
.find('button[data-test-subj="saved-query-management-popover-button"]')
.simulate('click');

await waitFor(() => {
expect(isSavedQueryPopoverOpen()).toBeTruthy();
});
wrapper.find('button[data-test-subj="saved-query-management-save-button"]').simulate('click');

wrapper
.find('button[data-test-subj="saved-query-management-save-button"]')
.simulate('click');

await waitFor(() => {
expect(isSavedQueryPopoverOpen()).toBeFalsy();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ import { useAllExceptionLists } from './use_all_exception_lists';
jest.mock('../../../../../../common/lib/kibana');
jest.mock('./use_all_exception_lists');
jest.mock('../../../../../../shared_imports');
jest.mock('@kbn/i18n/react', () => {
const originalModule = jest.requireActual('@kbn/i18n/react');
const FormattedRelative = jest.fn().mockImplementation(() => '20 hours ago');

return {
...originalModule,
FormattedRelative,
};
});
describe('ExceptionListsTable', () => {
const exceptionList1 = getExceptionListSchemaMock();
const exceptionList2 = { ...getExceptionListSchemaMock(), list_id: 'not_endpoint_list', id: '2' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('when on the list page', () => {
let store: AppContextTestRender['store'];
let coreStart: AppContextTestRender['coreStart'];
let middlewareSpy: AppContextTestRender['middlewareSpy'];
let abortSpy: jest.SpyInstance;
beforeAll(() => {
const mockAbort = new AbortController();
mockAbort.abort();
abortSpy = jest.spyOn(window, 'AbortController').mockImplementation(() => mockAbort);
});

afterAll(() => {
abortSpy.mockRestore();
});
beforeEach(() => {
const mockedContext = createAppRootMockRenderer();
({ history, store, coreStart, middlewareSpy } = mockedContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
*/

import React, { memo } from 'react';
import { EuiCard, EuiIcon, EuiTextColor, EuiLink, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import {
EuiCard,
EuiIcon,
EuiTextColor,
EuiLink,
EuiFlexGroup,
EuiFlexItem,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -42,8 +50,10 @@ export const LockedPolicyCard = memo(() => {
</strong>
</h3>
}
description={
<EuiFlexGroup className="lockedCardDescription" direction="column" gutterSize="none">
description={false}
>
<EuiFlexGroup className="lockedCardDescription" direction="column" gutterSize="none">
<EuiText>
<EuiFlexItem>
<h4>
<EuiTextColor color="subdued">
Expand All @@ -59,7 +69,7 @@ export const LockedPolicyCard = memo(() => {
<FormattedMessage
id="xpack.securitySolution.endpoint.policy.details.lockedCard"
defaultMessage="To turn on Ransomware protection, you must upgrade your license to Platinum, start a
free 30-day trial, or spin up a {cloudDeploymentLink} on AWS, GCP, or Azure."
free 30-day trial, or spin up a {cloudDeploymentLink} on AWS, GCP, or Azure."
values={{
cloudDeploymentLink: (
<EuiLink href="https://www.elastic.co/cloud/" target="_blank">
Expand All @@ -73,9 +83,9 @@ export const LockedPolicyCard = memo(() => {
/>
</p>
</EuiFlexItem>
</EuiFlexGroup>
}
/>
</EuiText>
</EuiFlexGroup>
</EuiCard>
</LockedPolicyDiv>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ jest.mock('../../../containers/kpis', () => ({
}));
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
jest.mock('../../../../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,
};
});
const mockUseTimelineKpiResponse = {
processCount: 1,
userCount: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { cloneDeep, getOr, omit } from 'lodash/fp';
import { Dispatch } from 'redux';
import ApolloClient from 'apollo-client';

import {
mockTimelineResults,
mockTimelineResult,
mockTimelineModel,
} from '../../../common/mock/timeline_results';
import { mockTimelineResults, mockTimelineResult, mockTimelineModel } from '../../../common/mock';
import { timelineDefaults } from '../../store/timeline/defaults';
import { setTimelineRangeDatePicker as dispatchSetTimelineRangeDatePicker } from '../../../common/store/inputs/actions';
import {
Expand All @@ -37,7 +33,7 @@ import {
formatTimelineResultToModel,
} from './helpers';
import { OpenTimelineResult, DispatchUpdateTimeline } from './types';
import { KueryFilterQueryKind } from '../../../common/store/model';
import { KueryFilterQueryKind } from '../../../common/store';
import { Note } from '../../../common/lib/note';
import moment from 'moment';
import sinon from 'sinon';
Expand Down Expand Up @@ -1275,7 +1271,7 @@ describe('helpers', () => {

describe('update a timeline', () => {
const updateIsLoading = jest.fn();
const updateTimeline = jest.fn();
const updateTimeline = jest.fn().mockImplementation(() => jest.fn());
const selectedTimeline = { ...mockSelectedTimeline };
const apolloClient = {
query: (jest.fn().mockResolvedValue(selectedTimeline) as unknown) as ApolloClient<{}>,
Expand Down Expand Up @@ -1316,6 +1312,7 @@ describe('helpers', () => {
args.duplicate,
args.timelineType
);

expect(updateTimeline).toBeCalledWith({
timeline: {
...timeline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import { createStore, State } from '../../../common/store';
import { DetailsPanel } from './index';
import { TimelineExpandedDetail, TimelineTabs } from '../../../../common/types/timeline';
import { FlowTarget } from '../../../../common/search_strategy/security_solution/network';
jest.mock('react-apollo', () => {
const original = jest.requireActual('react-apollo');
return {
...original,
// eslint-disable-next-line react/display-name
Query: () => <></>,
};
});

describe('Details Panel Component', () => {
const state: State = { ...mockGlobalState };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ jest.mock('../../containers/index', () => ({

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

return {
...originalModule,
FormattedRelative,
};
});
const mockUseResizeObserver: jest.Mock = useResizeObserver as jest.Mock;
jest.mock('use-resize-observer/polyfilled');
mockUseResizeObserver.mockImplementation(() => ({}));
Expand Down

0 comments on commit 24a1ef0

Please sign in to comment.