Skip to content

Commit

Permalink
last pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Aug 13, 2020
1 parent f9d18c1 commit 870ddbe
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

import React from 'react';
import { mount } from 'enzyme';
import { SOURCE_GROUPS } from '../../containers/sourcerer/constants';
import { SecurityPageName } from '../../containers/sourcerer/constants';
import { mockPatterns, mockSourceGroup } from '../../containers/sourcerer/mocks';
import { MaybeSourcerer } from './index';
import * as i18n from './translations';
import { ADD_INDEX_PATH } from '../../../../common/constants';

const updateSourceGroupIndicies = jest.fn();
const mockManageSource = {
activeSourceGroupId: SOURCE_GROUPS.default,
activeSourceGroupId: SecurityPageName.default,
availableIndexPatterns: mockPatterns,
availableSourceGroupIds: [SOURCE_GROUPS.default],
getManageSourceGroupById: jest.fn().mockReturnValue(mockSourceGroup(SOURCE_GROUPS.default)),
availableSourceGroupIds: [SecurityPageName.default],
getManageSourceGroupById: jest.fn().mockReturnValue(mockSourceGroup(SecurityPageName.default)),
initializeSourceGroup: jest.fn(),
isIndexPatternsLoading: false,
setActiveSourceGroupId: jest.fn(),
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('Sourcerer component', () => {
.prop('onChange');
// @ts-ignore
switcherOnChange([mockOptions[0], mockOptions[1]]);
expect(updateSourceGroupIndicies).toHaveBeenCalledWith(SOURCE_GROUPS.default, [
expect(updateSourceGroupIndicies).toHaveBeenCalledWith(SecurityPageName.default, [
mockOptions[0].value,
mockOptions[1].value,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const MaybeSourcerer = React.memo(() => {
);

const [isPopoverOpen, setPopoverIsOpen] = useState(false);
const setPopoverIsOpenCb = useCallback((isOpen) => setPopoverIsOpen(isOpen), []);
const trigger = useMemo(
() => (
<EuiButtonEmpty
Expand All @@ -55,14 +56,14 @@ export const MaybeSourcerer = React.memo(() => {
flush="left"
iconSide="right"
iconType="indexSettings"
onClick={() => setPopoverIsOpen(!isPopoverOpen)}
onClick={() => setPopoverIsOpenCb(!isPopoverOpen)}
size="l"
title={i18n.SOURCERER}
>
{i18n.SOURCERER}
</EuiButtonEmpty>
),
[isPopoverOpen]
[isPopoverOpen, setPopoverIsOpenCb]
);
const options: EuiSelectableOption[] = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

export const SOURCERER_FEATURE_FLAG_ON = false;

export enum SOURCE_GROUPS {
export enum SecurityPageName {
default = 'default',
host = 'host',
detections = 'detections',
timeline = 'timeline',
network = 'network',
}

export type SourceGroupsType = keyof typeof SOURCE_GROUPS;
export type SourceGroupsType = keyof typeof SecurityPageName;

export const sourceGroups = {
[SOURCE_GROUPS.default]: [
[SecurityPageName.default]: [
'apm-*-transaction*',
'auditbeat-*',
'endgame-*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
mockPatterns,
mockSource,
} from './mocks';
import { SOURCE_GROUPS } from './constants';
const mockSourceDefaults = mockSource(SOURCE_GROUPS.default);
import { SecurityPageName } from './constants';
const mockSourceDefaults = mockSource(SecurityPageName.default);
jest.mock('../../lib/kibana', () => ({
useKibana: jest.fn().mockReturnValue({
services: {
Expand All @@ -34,8 +34,8 @@ jest.mock('../../utils/apollo_context', () => ({
}));

describe('Sourcerer Hooks', () => {
const testId = SOURCE_GROUPS.default;
const uninitializedId = SOURCE_GROUPS.host;
const testId = SecurityPageName.default;
const uninitializedId = SecurityPageName.host;
beforeEach(() => {
jest.clearAllMocks();
jest.restoreAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { sourceQuery } from '../source/index.gql_query';
import { useApolloClient } from '../../utils/apollo_context';
import {
sourceGroups,
SOURCE_GROUPS,
SecurityPageName,
SourceGroupsType,
SOURCERER_FEATURE_FLAG_ON,
} from './constants';
Expand Down Expand Up @@ -111,7 +111,7 @@ export const getSourceDefaults = (id: SourceGroupsType, defaultIndex: string[])
});

const initManageSource: ManageSourcerer = {
activeSourceGroupId: SOURCE_GROUPS.default,
activeSourceGroupId: SecurityPageName.default,
availableIndexPatterns: [],
availableSourceGroupIds: [],
isIndexPatternsLoading: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SOURCE_GROUPS } from './constants';
import { SecurityPageName } from './constants';
import { getSourceDefaults } from './index';

export const mockPatterns = [
Expand All @@ -17,7 +17,7 @@ export const mockPatterns = [
];

export const mockSourceGroups = {
[SOURCE_GROUPS.default]: [
[SecurityPageName.default]: [
'apm-*-transaction*',
'auditbeat-*',
'blobbeat-*',
Expand All @@ -26,7 +26,7 @@ export const mockSourceGroups = {
'logs-*',
'winlogbeat-*',
],
[SOURCE_GROUPS.host]: [
[SecurityPageName.host]: [
'apm-*-transaction*',
'endgame-*',
'logs-*',
Expand All @@ -36,10 +36,10 @@ export const mockSourceGroups = {
};

export const mockSourceSelections = {
[SOURCE_GROUPS.default]: ['auditbeat-*', 'endgame-*', 'filebeat-*', 'logs-*', 'winlogbeat-*'],
[SOURCE_GROUPS.host]: ['endgame-*', 'logs-*', 'packetbeat-*', 'winlogbeat-*'],
[SecurityPageName.default]: ['auditbeat-*', 'endgame-*', 'filebeat-*', 'logs-*', 'winlogbeat-*'],
[SecurityPageName.host]: ['endgame-*', 'logs-*', 'packetbeat-*', 'winlogbeat-*'],
};
export const mockSource = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) => ({
export const mockSource = (testId: SecurityPageName.default | SecurityPageName.host) => ({
data: {
source: {
id: 'default',
Expand Down Expand Up @@ -69,7 +69,7 @@ export const mockSource = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) =
stale: false,
});

export const mockSourceGroup = (testId: SOURCE_GROUPS.default | SOURCE_GROUPS.host) => {
export const mockSourceGroup = (testId: SecurityPageName.default | SecurityPageName.host) => {
const indexes = mockSourceSelections[testId];
return {
...getSourceDefaults(testId, mockPatterns),
Expand Down

0 comments on commit 870ddbe

Please sign in to comment.