Skip to content

Commit

Permalink
[Security Solution]Error coming up on clicking create timeline templa…
Browse files Browse the repository at this point in the history
…te (#111856) (#112005)

* do not call addErrorHash if it is timeline template

* unit test

* fix types

* trim kqlQueryExpression

* revert change

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Angela Chuang <[email protected]>
  • Loading branch information
kibanamachine and angorayc authored Sep 13, 2021
1 parent e77e072 commit 4e6c280
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useTimelineEventsDetails } from '../../../containers/details/index';
import { useSourcererScope } from '../../../../common/containers/sourcerer';
import { mockSourcererScope } from '../../../../common/containers/sourcerer/mocks';
import { Direction } from '../../../../../common/search_strategy';
import * as helpers from '../helpers';

jest.mock('../../../containers/index', () => ({
useTimelineEvents: jest.fn(),
Expand Down Expand Up @@ -116,7 +117,7 @@ describe('Timeline', () => {
itemsPerPage: 5,
itemsPerPageOptions: [5, 10, 20],
kqlMode: 'search' as QueryTabContentComponentProps['kqlMode'],
kqlQueryExpression: '',
kqlQueryExpression: ' ',
onEventClosed: jest.fn(),
renderCellValue: DefaultCellRenderer,
rowRenderers: defaultRowRenderers,
Expand All @@ -133,6 +134,27 @@ describe('Timeline', () => {
});

describe('rendering', () => {
let spyCombineQueries: jest.SpyInstance;

beforeEach(() => {
spyCombineQueries = jest.spyOn(helpers, 'combineQueries');
});
afterEach(() => {
spyCombineQueries.mockClear();
});

test('should trim kqlQueryExpression', () => {
mount(
<TestProviders>
<QueryTabContentComponent {...props} />
</TestProviders>
);

expect(spyCombineQueries.mock.calls[0][0].kqlQuery.query).toEqual(
props.kqlQueryExpression.trim()
);
});

test('renders correctly against snapshot', () => {
const wrapper = shallow(
<TestProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export const QueryTabContentComponent: React.FC<Props> = ({
const kqlQuery: {
query: string;
language: KueryFilterQueryKind;
} = useMemo(() => ({ query: kqlQueryExpression, language: 'kuery' }), [kqlQueryExpression]);
} = useMemo(() => ({ query: kqlQueryExpression.trim(), language: 'kuery' }), [
kqlQueryExpression,
]);

const combinedQueries = combineQueries({
config: esQueryConfig,
Expand Down

0 comments on commit 4e6c280

Please sign in to comment.