Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Jul 8, 2022
1 parent 273b10b commit 4d3160e
Showing 1 changed file with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import {
} from '../../../../common/types/timeline';
import { FlowTargetSourceDest } from '../../../../common/search_strategy/security_solution/network';
import { EventDetailsPanel } from './event_details';
import { useKibana } from '../../../common/lib/kibana';
import { mockCasesContext } from '@kbn/cases-plugin/public/mocks/mock_cases_context';
import { useSearchStrategy } from '../../../common/containers/use_search_strategy';

jest.mock('../../../common/lib/kibana');
jest.mock('../../../common/containers/use_search_strategy', () => ({
useSearchStrategy: jest.fn(),
}));

describe('Details Panel Component', () => {
const state: State = {
Expand Down Expand Up @@ -101,34 +102,11 @@ describe('Details Panel Component', () => {
timelineId: 'test',
};

const mockSearchStrategy = jest.fn();
const mockUseSearchStrategy = useSearchStrategy as jest.Mock;

describe('DetailsPanel: rendering', () => {
beforeEach(() => {
store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage);
(useKibana as jest.Mock).mockReturnValue({
services: {
data: {
search: {
searchStrategyClient: jest.fn(),
search: mockSearchStrategy.mockReturnValue({
unsubscribe: jest.fn(),
subscribe: jest.fn(),
}),
},
query: jest.fn(),
},
uiSettings: {
get: jest.fn().mockReturnValue([]),
},
application: {
navigateToApp: jest.fn(),
},
cases: {
ui: { getCasesContext: () => mockCasesContext },
},
},
});
});

test('it should not render the DetailsPanel if no expanded detail has been set in the reducer', () => {
Expand Down Expand Up @@ -270,12 +248,25 @@ describe('Details Panel Component', () => {

describe('DetailsPanel:NetworkDetails: rendering', () => {
beforeEach(() => {
mockUseSearchStrategy.mockReturnValue({
loading: true,
result: {
networkDetails: {},
},
search: jest.fn(),
refetch: jest.fn(),
inspect: {},
});
const mockState = { ...state };
mockState.timeline.timelineById[TimelineId.active].expandedDetail = networkExpandedDetail;
mockState.timeline.timelineById.test.expandedDetail = networkExpandedDetail;
store = createStore(mockState, SUB_PLUGINS_REDUCER, kibanaObservable, storage);
});

afterEach(() => {
mockUseSearchStrategy.mockReset();
});

test('it should render the Network Details view in the Details Panel when the panelView is networkDetail and the ip is set', () => {
const wrapper = mount(
<TestProviders store={store}>
Expand Down

0 comments on commit 4d3160e

Please sign in to comment.