Skip to content

Commit

Permalink
Fix linting/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Dec 7, 2021
1 parent c2bc60c commit 7fbba7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jest.mock('react-router-dom', () => {
...originalModule,
createHref: jest.fn(),
useHistory: jest.fn(),
useLocation: jest.fn().mockReturnValue({ pathname: '' }),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { useInspectButton, UseInspectButtonParams, useStackByFields } from './hooks';
import { mockBrowserFields } from '../../../../common/containers/source/mock';
import {
TestProviders,
} from '../../../../common/mock';

import { TestProviders } from '../../../../common/mock';

jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
Expand Down Expand Up @@ -60,12 +57,16 @@ describe('hooks', () => {
useSourcererDataView: jest.fn().mockReturnValue({ browserFields: mockBrowserFields }),
}));
it('returns only aggregateable fields', () => {
const wrapper = ({ children }: { children: JSX.Element }) => <TestProviders>{children}</TestProviders>
const wrapper = ({ children }: { children: JSX.Element }) => (
<TestProviders>{children}</TestProviders>
);
const { result, unmount } = renderHook(() => useStackByFields(), { wrapper });
const aggregateableFields = result.current;
unmount();
expect(aggregateableFields?.find(field => field.label === 'agent.id')).toBeTruthy();
expect(aggregateableFields?.find(field => field.label === 'nestedField.firstAttributes')).toBe(undefined);
expect(aggregateableFields?.find((field) => field.label === 'agent.id')).toBeTruthy();
expect(
aggregateableFields?.find((field) => field.label === 'nestedField.firstAttributes')
).toBe(undefined);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useSourcererDataView } from '../../../common/containers/sourcerer';
import { createStore, State } from '../../../common/store';
import { mockHistory, Router } from '../../../common/mock/router';
import { mockTimelines } from '../../../common/mock/mock_timelines_plugin';
import { mockBrowserFields } from '../../../common/containers/source/mock';

// Test will fail because we will to need to mock some core services to make the test work
// For now let's forget about SiemSearchBar and QueryBar
Expand Down Expand Up @@ -71,6 +72,9 @@ jest.mock('../../../common/lib/kibana', () => {
siem: { crud_alerts: true, read_alerts: true },
},
},
uiSettings: {
get: jest.fn(),
},
timelines: { ...mockTimelines },
data: {
query: {
Expand Down Expand Up @@ -113,6 +117,7 @@ describe('DetectionEnginePageComponent', () => {
(useSourcererDataView as jest.Mock).mockReturnValue({
indicesExist: true,
indexPattern: {},
browserFields: mockBrowserFields,
});
});

Expand Down

0 comments on commit 7fbba7c

Please sign in to comment.