Skip to content

Commit

Permalink
[Security Solution] Resolver, revert to default data view (elastic#12…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored and kibanamachine committed Dec 21, 2021
1 parent 3653d70 commit 32e4b5d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ import {
useGlobalFullScreen,
useTimelineFullScreen,
} from '../../../common/containers/use_full_screen';
import { TestProviders } from '../../../common/mock';
import {
createSecuritySolutionStorageMock,
kibanaObservable,
mockGlobalState,
mockIndexNames,
SUB_PLUGINS_REDUCER,
TestProviders,
} from '../../../common/mock';
import { TimelineId } from '../../../../common/types/timeline';
import { GraphOverlay } from '.';
import { createStore } from '../../../common/store';
import { useStateSyncingActions } from '../../../resolver/view/use_state_syncing_actions';
import { SourcererScopeName } from '../../../common/store/sourcerer/model';

jest.mock('../../../common/containers/use_full_screen', () => ({
useGlobalFullScreen: jest.fn(),
Expand All @@ -24,10 +34,15 @@ jest.mock('../../../common/containers/use_full_screen', () => ({

jest.mock('../../../resolver/view/use_resolver_query_params_cleaner');
jest.mock('../../../resolver/view/use_state_syncing_actions');
const useStateSyncingActionsMock = useStateSyncingActions as jest.Mock;

jest.mock('../../../resolver/view/use_sync_selected_node');

describe('GraphOverlay', () => {
const { storage } = createSecuritySolutionStorageMock();

beforeEach(() => {
jest.clearAllMocks();
(useGlobalFullScreen as jest.Mock).mockReturnValue({
globalFullScreen: false,
setGlobalFullScreen: jest.fn(),
Expand Down Expand Up @@ -73,6 +88,36 @@ describe('GraphOverlay', () => {
expect(overlayContainer).toHaveStyleRule('position', 'fixed');
});
});

test('it gets index pattern from default data view', () => {
mount(
<TestProviders
store={createStore(
{
...mockGlobalState,
timeline: {
...mockGlobalState.timeline,
timelineById: {
test: {
...mockGlobalState.timeline.timelineById.test,
graphEventId: 'definitely-not-null',
},
},
},
},
SUB_PLUGINS_REDUCER,
kibanaObservable,
storage
)}
>
<GraphOverlay timelineId={TimelineId.test} />
</TestProviders>
);

expect(useStateSyncingActionsMock.mock.calls[0][0].indices).toEqual(
mockGlobalState.sourcerer.defaultDataView.patternList
);
});
});

describe('when used in the active timeline', () => {
Expand Down Expand Up @@ -112,5 +157,43 @@ describe('GraphOverlay', () => {
expect(overlayContainer).toHaveStyleRule('width', '100%');
});
});

test('it gets index pattern from Timeline data view', () => {
mount(
<TestProviders
store={createStore(
{
...mockGlobalState,
timeline: {
...mockGlobalState.timeline,
timelineById: {
[timelineId]: {
...mockGlobalState.timeline.timelineById[timelineId],
graphEventId: 'definitely-not-null',
},
},
},
sourcerer: {
...mockGlobalState.sourcerer,
sourcererScopes: {
...mockGlobalState.sourcerer.sourcererScopes,
[SourcererScopeName.timeline]: {
...mockGlobalState.sourcerer.sourcererScopes[SourcererScopeName.timeline],
selectedPatterns: mockIndexNames,
},
},
},
},
SUB_PLUGINS_REDUCER,
kibanaObservable,
storage
)}
>
<GraphOverlay timelineId={timelineId} />
</TestProviders>
);

expect(useStateSyncingActionsMock.mock.calls[0][0].indices).toEqual(mockIndexNames);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import * as i18n from './translations';
import { SourcererScopeName } from '../../../common/store/sourcerer/model';
import { useSourcererDataView } from '../../../common/containers/sourcerer';
import { sourcererSelectors } from '../../../common/store';

const OverlayContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -181,7 +182,18 @@ const GraphOverlayComponent: React.FC<OwnProps> = ({ timelineId }) => {
globalFullScreen,
]);

const { selectedPatterns } = useSourcererDataView(SourcererScopeName.timeline);
const getDefaultDataViewSelector = useMemo(
() => sourcererSelectors.defaultDataViewSelector(),
[]
);
const defaultDataView = useDeepEqualSelector(getDefaultDataViewSelector);

const { selectedPatterns: timelinePatterns } = useSourcererDataView(SourcererScopeName.timeline);

const selectedPatterns = useMemo(
() => (isInTimeline ? timelinePatterns : defaultDataView.patternList),
[defaultDataView.patternList, isInTimeline, timelinePatterns]
);

if (fullScreen && !isInTimeline) {
return (
Expand Down

0 comments on commit 32e4b5d

Please sign in to comment.