Skip to content

Commit

Permalink
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
Browse files Browse the repository at this point in the history
…-ref HEAD~1..HEAD --fix'
  • Loading branch information
kibanamachine committed Dec 7, 2022
1 parent 6194538 commit ab014ac
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/
import { parseAlertsData } from './helpers';
import { parsedAlerts, mockAlertsData, mockAlertsEmptyData } from './mock_data';
import type { AlertsBySeverityResponse, AlertsBySeverityAgg} from './types';
import type { AlertsBySeverityResponse, AlertsBySeverityAgg } from './types';

describe('parseAlertsData', () => {
test('parse alerts with data', () => {
const res = parseAlertsData(mockAlertsData as AlertsBySeverityResponse<{}, AlertsBySeverityAgg>);
expect(res).toEqual(parsedAlerts);
});
test('parse alerts with data', () => {
const res = parseAlertsData(
mockAlertsData as AlertsBySeverityResponse<{}, AlertsBySeverityAgg>
);
expect(res).toEqual(parsedAlerts);
});

test('parse alerts without data', () => {
const res = parseAlertsData(mockAlertsEmptyData);
expect(res).toEqual(null);
});
});
test('parse alerts without data', () => {
const res = parseAlertsData(mockAlertsEmptyData);
expect(res).toEqual(null);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { severityLabels } from '../../../../overview/components/detection_respon
import { emptyDonutColor } from '../../../../common/components/charts/donutchart_empty';
import { SEVERITY_COLOR } from '../../../../overview/components/detection_response/utils';


export const parseAlertsData = (
response: AlertsBySeverityResponse<{}, AlertsBySeverityAgg>
): ParsedAlertsData => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jest.mock('react-router-dom', () => {
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) };
});


describe('AlertsChartsPanel', () => {
const defaultProps = {
signalIndexName: 'signalIndexName',
Expand All @@ -36,28 +35,28 @@ describe('AlertsChartsPanel', () => {
jest.restoreAllMocks();
});

test('renders correctly', async() => {
const { container } = render(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} />
</TestProviders>
);
await waitFor(() => {
expect(container.querySelector('[data-test-subj="alerts-charts-panel"]')).toBeInTheDocument();
});
test('renders correctly', async () => {
const { container } = render(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} />
</TestProviders>
);
await waitFor(() => {
expect(container.querySelector('[data-test-subj="alerts-charts-panel"]')).toBeInTheDocument();
});
});

test('it renders the header with the specified `alignHeader` alignment', async() => {
const { container } = render(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} alignHeader="flexEnd" />
</TestProviders>
);
await waitFor(() => {
expect(
container.querySelector('[data-test-subj="headerSectionInnerFlexGroup"]')?.classList[1]
).toContain('flexEnd');
});
test('it renders the header with the specified `alignHeader` alignment', async () => {
const { container } = render(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} alignHeader="flexEnd" />
</TestProviders>
);
await waitFor(() => {
expect(
container.querySelector('[data-test-subj="headerSectionInnerFlexGroup"]')?.classList[1]
).toContain('flexEnd');
});
});

describe('Query', () => {
Expand All @@ -84,11 +83,11 @@ describe('AlertsChartsPanel', () => {

describe('toggleQuery', () => {
test('toggles', async () => {
const wrapper = mount(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} />
</TestProviders>
);
const wrapper = mount(
<TestProviders>
<AlertsSummaryChartsPanel {...defaultProps} />
</TestProviders>
);
await act(async () => {
wrapper.find('[data-test-subj="query-toggle-header"]').first().simulate('click');
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,88 @@ export const from = '2022-04-05T12:00:00.000Z';
export const to = '2022-04-08T12:00:00.000Z';

export const mockAlertsData = {
took: 0,
timed_out: false,
_shards: {
total: 1,
successful: 1,
skipped: 0,
failed: 0
took: 0,
timed_out: false,
_shards: {
total: 1,
successful: 1,
skipped: 0,
failed: 0,
},
hits: {
total: {
value: 47,
relation: 'eq',
},
hits: {
total: {
value: 47,
relation: 'eq'
max_score: null,
hits: [],
},
aggregations: {
statusBySeverity: {
doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: [
{
key: 'high',
doc_count: 78,
},
{
key: 'low',
doc_count: 46,
},
{
key: 'medium',
doc_count: 32,
},
{
key: 'critical',
doc_count: 21,
},
max_score: null,
hits: []
],
},
aggregations: {
statusBySeverity: {
doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: [
{
key: 'high',
doc_count: 78
},
{
key: 'low',
doc_count: 46
},
{
key: 'medium',
doc_count: 32
},
{
key: 'critical',
doc_count: 21
}
]
}
}
},
};

export const parsedAlerts = [
{ key: 'high', value: 78, label: 'High' },
{ key: 'low', value: 46, label: 'Low' },
{ key: 'medium', value: 32, label: 'Medium' },
{ key: 'critical', value: 21, label: 'Critical' }
];

{ key: 'high', value: 78, label: 'High' },
{ key: 'low', value: 46, label: 'Low' },
{ key: 'medium', value: 32, label: 'Medium' },
{ key: 'critical', value: 21, label: 'Critical' },
];

export const mockAlertsEmptyData={
export const mockAlertsEmptyData = {
took: 0,
timed_out: false,
_shards: {
total: 1,
successful: 1,
skipped: 0,
failed: 0
failed: 0,
},
hits: {
total: {
value: 0,
relation: 'eq'
relation: 'eq',
},
max_score: null,
hits: []
hits: [],
},
aggregations: {
statusBySeverity: {
doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: []
}
}
}
buckets: [],
},
},
};

export const alertsBySeverityQuery = {
size: 0,
query: {
bool: {
filter: [
{ bool: { filter: [], must: [], must_not: [], should: []}},
{ range: { '@timestamp': { gte: from, lte: to } } }
{ bool: { filter: [], must: [], must_not: [], should: [] } },
{ range: { '@timestamp': { gte: from, lte: to } } },
],
},
},
Expand All @@ -102,5 +101,4 @@ export const alertsBySeverityQuery = {
},
},
runtime_mappings: undefined,

};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { render} from '@testing-library/react';
import { render } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../../../common/mock';
import { SeverityLevelChart } from './severity_level_chart';
Expand All @@ -16,7 +16,6 @@ jest.mock('react-router-dom', () => {
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) };
});


describe('Severity level chart', () => {
const defaultProps = {
data: [],
Expand All @@ -31,13 +30,13 @@ describe('Severity level chart', () => {

test('renders correctly', () => {
const { container } = render(
<TestProviders>
<SeverityLevelChart {...defaultProps} />
</TestProviders>
);
expect(container.querySelector('[data-test-subj="severty-chart"]')).toBeInTheDocument();
<TestProviders>
<SeverityLevelChart {...defaultProps} />
</TestProviders>
);
expect(container.querySelector('[data-test-subj="severty-chart"]')).toBeInTheDocument();
});

test('render HeaderSection', () => {
const { container } = render(
<TestProviders>
Expand All @@ -55,4 +54,4 @@ describe('Severity level chart', () => {
);
expect(container.querySelector('[data-test-subj="inspect-icon-button"]')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import { renderHook } from '@testing-library/react-hooks';
import { TestProviders } from '../../../../common/mock';
import { ALERTS_QUERY_NAMES } from '../../../../detections/containers/detection_engine/alerts/constants';
import { ALERTS_QUERY_NAMES } from '../../../containers/detection_engine/alerts/constants';
import { mockAlertsData, alertsBySeverityQuery, parsedAlerts, from, to } from './mock_data';
import type { UseAlertsBySeverity, UseSeverityChartProps } from './use_severity_chart_data';
import { useSeverityChartData } from './use_severity_chart_data';


const dateNow = new Date('2022-04-08T12:00:00.000Z').valueOf();
const mockDateNow = jest.fn().mockReturnValue(dateNow);
Date.now = jest.fn(() => mockDateNow()) as unknown as DateConstructor['now'];
Expand All @@ -26,7 +25,7 @@ const defaultUseQueryAlertsReturn = {
refetch: () => {},
};
const mockUseQueryAlerts = jest.fn().mockReturnValue(defaultUseQueryAlertsReturn);
jest.mock('../../../../detections/containers/detection_engine/alerts/use_query', () => {
jest.mock('../../../containers/detection_engine/alerts/use_query', () => {
return {
useQueryAlerts: (...props: unknown[]) => mockUseQueryAlerts(...props),
};
Expand All @@ -45,11 +44,11 @@ jest.mock('../../../../common/containers/use_global_time', () => {
const renderUseSeverityChartData = (props: Partial<UseSeverityChartProps> = {}) =>
renderHook<UseSeverityChartProps, ReturnType<UseAlertsBySeverity>>(
() =>
useSeverityChartData({
uniqueQueryId: 'test',
signalIndexName: 'signal-alerts',
...props,
}),
useSeverityChartData({
uniqueQueryId: 'test',
signalIndexName: 'signal-alerts',
...props,
}),
{
wrapper: TestProviders,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import type { AlertViewSelection } from './helpers';
import {
AlertViewSelection,
getButtonProperties,
getContextMenuPanels,
TABLE_ID,
Expand Down

0 comments on commit ab014ac

Please sign in to comment.